Thread: Post your games here...

  1. #106
    Registered User
    Join Date
    Dec 2006
    Location
    Scranton, Pa
    Posts
    252
    Finish it up. At the very least, it's good practice. Believe it or not, slider puzzles are still somewhat popular. I have my own versions (9 and 15 puzzles) and they're downloaded at least a few dozen times a month.

  2. #107
    Registered User guesst's Avatar
    Join Date
    Feb 2008
    Location
    Lehi, UT
    Posts
    179
    Ya know, this is a good thread, but a little to slow moving. I mean, 3 years, still sticked, and only 8 pages? I'm gonna throw one out here:
    Code:
    Operating system: Any
    Compiler: MinGW, but it should work for any
    Graphics Library: stdio.h
    Other Libraries:
    Description: Reflex
    See how good you can count Mississippis.
    Type-ins are back! Visit Cymon's Games at http://www.cymonsgames.com for a new game every week!

  3. #108
    Registered User
    Join Date
    Sep 2009
    Posts
    2

    Knights tour

    C Source code for knights tour

    Code:
    /****Knight's Tour*******/
    
    #include<stdio.h>
    #include<stdlib.h>
    #include<graphics.h>
    #include<conio.h>
    
    
    
    typedef struct
    {
    	int x,y,s2;
    }chessboard;
    typedef struct
    {
    	int u,v,s1;
    }hamiltonian;
    int b,p,q,w=5;
    int j=0;
    chessboard chess[8][8];
    hamiltonian path[64];
    void search();
    void push();
    void pop();
    void pawn(int,int,int);
    void knight(int,int,int);
    void main()
    {
    	int i,j,l,m;
    	/* request auto detection */
    	int gdriver = DETECT, gmode, errorcode;
    	FILE *fp;
    	clrscr();
    	/* initialize graphics, local variables*/
    	initgraph(&gdriver, &gmode, "f:\\tc\\bgi");
    	/* read result of initialization */
    	errorcode = graphresult();
    	if (errorcode != grOk)
    	/* an error occurred */
    	{
    		printf("Graphics error: %s\n", grapherrormsg(errorcode));
    		printf("Press any key to halt:");
    		getch();
    		exit(1);
    		/* terminate with an error code */
    	}
    	printf("\n\n\n\n\n\n\n\n\n\n\n\tPROGRAM TO CHECK WHETHER A KNIGHT CAN REACH A PAWN IN A CHESSBOARD");
    
    	printf("\n\n\n\t\t     THE CO-ORDINATES MUST BE GIVEN FROM 1-8");
    	printf("\n\n\nEnter the position of the Pawn: ");
    	scanf("%d,%d",&a,&b);
    	printf("\n\nEnter the position of the Knight: ");
    	scanf("%d,%d",&p,&q);
    	cleardevice();
    	//chessboard
    	setcolor(3);
    	for(i=80;i<=560;i+=60)
    	{
    		line(i,0,i,480);
    		line(i+1,0,i+1,480);
    	}
    
    	for(i=0;i<480;i+=60)
    	{
    		line(80,i,560,i);
    		line(80,i+1,560,i+1);
    	}
    	line(80,478,560,478);
    	line(80,479,560,479);
    	setfillstyle(1,15);
    	for(i=0;i<=7;i++)
    		for(j=0;j<=7;j++)
    			chess[i][j].s2=0;
    	for(i=0;i<=63;i++)
    		path[i].s1=-1;
    	for(i=20;i<=440;i+=120)
    		for(j=100;j<=520;j+=120)
    			floodfill(j,i,3);
    	for(i=80;i<=440;i+=120)
    		for(j=160;j<=520;j+=120)
    			floodfill(j,i,3);
    	for(i=0,l=30;i<=7,l<=450;i++,l+=60)
    		for(j=0,m=110;j<=7,m<=530;j++,m+=60)
    		{
    			chess[i][j].x=m;
    			chess[i][j].y=l;
    		}
    
    	pawn(chess[b][a].x,chess[b][a].y,RED);
    	setcolor(1);
    	setfillstyle(1,1);
    
    	/*settextstyle(10,1,2);
    	setcolor(MAGENTA);
    	outtextxy(10,20,"Magenta = Start = Knight");
    	settextstyle(10,1,2);
    	setcolor(RED);
    	outtextxy(575,5,"Red = Destination = Pawn ");
    	fclose(fp);*/
    	path[0].u=chess[q][p].x;
    	path[0].v=chess[q][p].y;
    	chess[q][p].s2=1;
    	path[j].s1=1;
    	knight(chess[q][p].x,chess[q][p].y,MAGENTA);
    	getch();
    	search();
    	getch();
    	cleardevice();
    	printf("\t\t\tThe Knight reached the pawn");
    	getch();
    	closegraph();
    
    }
    void search()
    {
    	int r,s,c=0,flag;
    	char ch;
    	if(path[j].u==chess[b][a].x&&path[j].v==chess[b][a].y)
    	{
    	       knight(path[j].u,path[j].v+10,MAGENTA);
    	       return;
    	}
    	while(1)
    	{
    
    		r=random(8);
    		s=random(8);
    	if(path[j].u+120==chess[r][s].x&&path[j].v+60==chess[r][s].y)
    	{
    		if(path[j].s1==chess[r][s].s2)
    		{
    			c++;
    			continue;
    		}
    		flag=1;
    		knight(path[j].u+120,path[j].v+70,GREEN);
    		break;
    	}
    	else
    		if(path[j].u+120==chess[r][s].x&&path[j].v-60==chess[r][s].y)
    		{
    			if(path[j].s1==chess[r][s].s2)
    			{
    				c++;
    				if(c==8)
    					break;
    				continue;
    			}
    			flag=1;
    			knight(path[j].u+120,path[j].v-50,GREEN);
    			break;
    		}
    		else
    			if(path[j].u-120==chess[r][s].x&&path[j].v+60==chess[r][s].y)
    			{
    				if(path[j].s1==chess[r][s].s2)
    				{
    					c++;
    					if(c==8)
    						break;
    					continue;
    				}
    				flag=1;
    				knight(path[j].u-120,path[j].v+70,GREEN);
    				break;
    			}
    			else
    				if(path[j].u-120==chess[r][s].x&&path[j].v-60==chess[r][s].y)
    				{
    					if(path[j].s1==chess[r][s].s2)
    					{
    						c++;
    						if(c==8)
    							break;
    						continue;
    					}
    					flag=1;
    					knight(path[j].u-120,path[j].v-50,GREEN);
    					break;
    				}
    				else
    					if(path[j].u+60==chess[r][s].x&&path[j].v+120==chess[r][s].y)
    					{
    						if(path[j].s1==chess[r][s].s2)
    						{
    							c++;
    							if(c==8)
    								break;
    							continue;
    						}
    						flag=1;
    						knight(path[j].u+60,path[j].v+130,GREEN);
    						break;
    					}
    					else
    						if(path[j].u+60==chess[r][s].x&&path[j].v-120==chess[r][s].y)
    						{
    							if(path[j].s1==chess[r][s].s2)
    							{
    								c++;
    								if(c==8)
    									break;
    								continue;
    							}
    							flag=1;
    							knight(path[j].u+60,path[j].v-110,GREEN);
    							break;
    						}
    						else
    							if(path[j].u-60==chess[r][s].x&&path[j].v-120==chess[r][s].y)
    							{
    								if(path[j].s1==chess[r][s].s2)
    								{
    									c++;
    									if(c==8)
    										break;
    									continue;
    								}
    								flag=1;
    								knight(path[j].u-60,path[j].v-110,GREEN);
    								break;
    							}
    							else
    									continue;
    
    	}
    
    	/*ch=getch();
    	if(ch==' ')
    	{
    		j--;
    		search();
    	}*/
    	if(flag==1)
    	{
    		push();
    		path[j].u=chess[r][s].x;
    		path[j].v=chess[r][s].y;
    		chess[r][s].s2=1;
    		path[j].s1=1;
    		getch();
    		search();
    
    	}
    
    
    }
    void pawn(int r, int s,int c)
    {
    	s=s+4;
    	setcolor(c);
    	setfillstyle(6,c);
    	circle(r,s-10,5);
    	floodfill(r,s-7,c);
    	line(r,s-10,r-11,s+15);
    	line(r,s-10,r+11,s+15);
    	rectangle(r-13,s+15,r+13,s+18);
    	floodfill(r,s+10,c);
    	floodfill(r,s+17,c);
    }
    void knight(int r,int s,int c)
    {
    	setcolor(c);
    	setfillstyle(6,c);
    	arc(r,s-10,0,180,14);
    	line(r-14,s-10,r,s-10);
    	line(r-3,s-10,r-14,s+10);
    	line(r+14,s-10,r+14,s+10);
    	rectangle(r-17,s+10,r+17,s+13);
    	floodfill(r,s-8,c);
    	floodfill(r,s+12,c);
    }
    void push()
    {
    	j++;
    }
    void pop()
    {
    	j--;
    }

  4. #109
    Registered User
    Join Date
    Sep 2009
    Posts
    2
    Anothe code for knights tour
    Code:
    #include <stdio.h>
    #include <conio.h>
    #include<graphics.h>
    #include<dos.h>
    #include<stdlib.h>
    typedef struct
    {
    	int n,color;
    }sq;
    struct link
    {
    	int x,y;
    	struct link *next;
    };
    typedef struct link l;
    l *h=NULL,*e=NULL,*p=NULL;
    void inilink();
    void graph();
    void chessboard(sq [8][8]);
    void iniboard(sq [8][8]);
    void drawpawn(int,int);
    void drawknight(int,int);
    void rec(l*,int,int);
    char name[][2]={"A","B","C","D","E","F","G","H","0","1","2","3","4","5","6","7"};
    int flag=0;
    void main()
    {
    	int i,j,i1,i2,j1,j2;
    	sq c[8][8];
    	clrscr();
    	printf("Enter the coordinates of pawn");
    	scanf("%d,%d",&i1,&j1);
    	printf("Enter the coordinates of the knight");
    	scanf("%d,%d",&i2,&j2);
    	if(i1==i2&&j1==j2)
    	exit(1);
    	for(i=0;i<8;i++)
    		for(j=0;j<8;j++)
    			c[8][8].n=0;
    	c[i1][j1].n=2;
    	c[i2][j2].n=1;
    	inilink();
    	e->next=h;
    	graph();
    	iniboard(c);
    	chessboard(c);
    	setcolor(BLUE);
    	setfillstyle(1,BLUE);
    	drawpawn(i1,j1);
    	setfillstyle(1,RED);
    	drawknight(i2,j2);
    	setfillstyle(1,GREEN);
    	for(p=h;p->next!=h;p=p->next)
    		if(p->x==i2&&p->y==j2)
    			break;
    		getch();
    	rec(p,i1,j1);
    	drawknight(i1,j1);
    	getch();
    	closegraph();
    }
    void rec(l *p,int i2,int j2)
    {
    	if((p->x==i2&&p->y==j2)||(flag==1))
    		return;
    	drawknight(p->next->x,p->next->y);
    	delay(1000);
    	rec(p->next,i2,j2);
    }
    void inilink()
    {
    	FILE *fp;
    	l *n;
    	fp=fopen("N:\\K.txt","r");
    	while(!feof(fp))
    	{
    		n=(l*)malloc(sizeof(l));
    		fscanf(fp,"%d %d",&n->x,&n->y);
    		n->next=NULL;
    		if(h==NULL)
    			h=e=n;
    		else
    		{
    			n->next=h;
    			h=n;
    		}
    	}
    	fclose(fp);
    }
    void iniboard(sq c[8][8])
    {
    	int i,j,k;
    	for(i=0;i<8;i++)
    		for(j=0;j<8;j++)
    			if(i%2==1)
    			{
    				c[i][j++].color=BROWN;
    				c[i][j].color=LIGHTRED;
    			}
    			else
    			{
    				c[i][j++].color=LIGHTRED;
    				c[i][j].color=BROWN;
    			}
    }
    void chessboard(sq c[8][8])
    {
    	int i,j,k,l;
    	cleardevice();
    	setbkcolor(GREEN);
    	//to make the board
    	setlinestyle(SOLID_LINE,1,2);
    	setcolor(BLUE);
    	for(i=60;i<=540;i+=60)
    		line(i,20,i,460);
    	for(i=20;i<=460;i+=55)
    		line(60,i,540,i);
    	for(i=60,k=0;i<540;i+=60,k++)
    		for(j=20,l=0;j<468;j+=56,l++)
    		{
    			setfillstyle(1,c[k][l].color);
    			floodfill(i+2,j+2,BLUE);
    		}
    
    	//to draw the border
    
    	line(40,1,40,479);
    	line(560,1,560,479);
    	line(40,1,560,1);
    	line(40,479,560,479);
    
    	line(40,1,60,20);
    	line(560,479,540,460);
    	line(40,479,60,460);
    	line(560,1,540,20);
    
    	setfillstyle(1,YELLOW);
    	floodfill(45,2,BLUE);
    	floodfill(45,25,BLUE);
    	floodfill(45,478,BLUE);
    	floodfill(545,455,BLUE);
    
    	//to label the board
    
    	settextstyle(2,0,4);
    	setcolor(RED);
    	for(i=50;i<=545;i+=495)
    		for(j=43,k=0;j<468;j+=56,k++)
    			outtextxy(i,j,name[k]);
    	for(j=5;j<=468;j+=460)
    		for(i=90,k=8;i<=550;i+=60,k++)
    			outtextxy(i,j,name[k]);
    }
    void graph(void)
    {
    	// request auto detection
    	int gdriver = DETECT, gmode, errorcode;
    	/* initialize graphics and local variables */
    	initgraph(&gdriver, &gmode, "e:\\tc\\bgi");
    	/* read result of initialization */
    	errorcode = graphresult();
    	if (errorcode != grOk)  /* an error occurRED */
    	{
    		printf("Graphics error: %s\n", grapherrormsg(errorcode));
    		printf("Press any key to halt:");
    		getch();
    		exit(1);
    		/* terminate with an error code */
    	}
    }
    void drawpawn(int i,int j)
    {
    	int pawn[]={25,20,25,22,28,22,28,35,20,35,20,40,15,40,15,45,45,45,45,40,40,40,40,35,32,35,32,22,35,22,35,20,25,20};
    	int k,fac1=(j+1)*60,fac2=i*55+25;
    	for(k=0;k<34;k+=2)
    	{
    		pawn[k]+=fac1;
    		pawn[k+1]+=fac2;
    	}
    	circle(30+fac1,15+fac2,5);
    	floodfill(31+fac1,16+fac2,BLUE);
    	fillpoly(17,pawn);
    }
    void drawknight(int i,int j)
    {
    	int knight[]={20,55,20,60,15,60,15,65,45,65,45,60,40,60,40,55};
    	int k,fac1=(j+1)*60,fac2=i*55+5;
    	for(k=0;k<16;k+=2)
    	{
    		knight[k]+=fac1;
    		knight[k+1]+=fac2;
    	}
    	drawpoly(8,knight);
    	if(j<4)
    	{
    		arc(33+fac1,40+fac2,105,230,20);
    		line(30+fac1,17+fac2,33+fac1,22+fac2);
    		line(30+fac1,17+fac2,27+fac1,22+fac2);
    		line(33+fac1,22+fac2,48+fac1,30+fac2);
    		line(48+fac1,30+fac2,48+fac1,35+fac2);
    		line(48+fac1,35+fac2,42+fac1,35+fac2);
    		arc(7+fac1,45+fac2,343,17,35);
    		circle(35+fac1,30+fac2,1);
    		floodfill(45+fac1,34+fac2,BLUE);
    		circle(35+fac1,30+fac2,3);
    	}
    	else
    	{
    		arc(25+fac1,42+fac2,320,70,20);
    		line(30+fac1,18+fac2,33+fac1,23+fac2);
    		line(30+fac1,18+fac2,27+fac1,23+fac2);
    		line(27+fac1,23+fac2,12+fac1,31+fac2);
    		line(12+fac1,31+fac2,12+fac1,36+fac2);
    		line(12+fac1,36+fac2,18+fac1,36+fac2);
    		arc(52+fac1,45+fac2,165,199,35);
    		circle(25+fac1,31+fac2,1);
    		floodfill(13+fac1,31+fac2,BLUE);
    		circle(25+fac1,31+fac2,3);
    	}
    }

  5. #110
    Registered User
    Join Date
    Feb 2009
    Posts
    26
    Game Title: Dwarf Caretaker
    Version: 0.5
    Operating System: XP
    Compiler: Code::Blocks w/ Mingw
    Graphics Library: Console
    Description: A sort of sim game (very) loosely based on the world sim game, Dwarf Fortress. This is my first real project that isn't out of a book or tutorial, so despite how simple (and boring...) it currently is, I'm rather proud of it. The code is probably horribly written, and once I've gotten a few other things cleaned up I may rewrite it completely to make use of some of the things I've learned along the way.
    Download: v0.6 - Includes source files, README Guide and compiled EXE

    Comments, critisism, advice, bug reports, etc. should be sent to [email protected], thank you!

    I'm apparently not allowed to attach .zip files to my posts, so the source code is attached as separate files, and the pre-compiled version with the guide is avaliable via the zip file above. I know I'm not supposed to use outside links, but since I can't upload exe, zip or rtf files I don't see any other way to make them available. There is a discussion topic for my game here.

    [EDIT]: I almost forgot, there are quite a few Dwarf Fortress reference in the game that may not make any sense to someone who hasn't played it. My appologies, but it was originally intended for the DF community, and besides, if you haven't played Dwarf Fortress at least once you should go play it now anyways.


    v0.4 Update:
    • Bug Fix - Ale was free
    • Bug Fix - "Opponent" was spelled wrong
    • NEW - Waiting now makes you hungry/thirsty and passes the time.
    • NEW - You can now choose how difficult you want a fight to be. At the moment, easy is the same as moderate unless you have at least 3 toughness.


    v0.5 Changes:
    • NEW - Complete re-write to clean up code and make future developement easier.
    • NEW - Winning a sparring match now increases toughness by 0.5 and happiness by 15, losing causes a loss of 15 happiness, and win or lose you get hungry and thirsty.
    • NEW - When quiting you can choose to save and exit, exit without saving, or not exit at all.
    • NEW - Heavy and Light work have been combined into "Work", and are options given to you after choosing to work.


    v0.6 Update:
    • BUG FIX - Player can die of starvation and dehydration again.
    • NEW - The maximum damage to any wound is increased by 1 for every 3 levels of toughness..
    • NEW - Death screen asking if you want to quit or restart.
    • NEW - ASCII art title screen!
    • NEW - Renamed and added choices to eat, drink and work to better represent DF.
    • NEW - Leaving happiness at 1 can now result in your dwarf commiting suicide.
    Last edited by timmeh; 09-07-2009 at 08:29 PM.

  6. #111
    Registered User
    Join Date
    Feb 2009
    Posts
    26

    Dwarf Caretaker v1.3

    Game Title: Dwarf Caretaker
    Version: 1.3
    Operating System: Built for Windows XP, although it may work on others with minimal changes.
    Compiler: Code::Blocks w/ Mingw
    Graphics Library: PDCurses
    Description: I recently finished version 1.3 of my "Dwarf Caretaker" game. I know I'm supposed to edit my old post, but for whatever reason vBulletin won't let me...

    As it is, unless something changes to make updating the post here easier, I think I'll just stick to updating it's topic on the DF forums, the google code page, and the blog. As a side effect, while the external links I'll post in addition to the source code I'll upload directly will always be current, the source code here may or may not be, depending on my ability to change it later without having to make a new post....


    If any of the mods get's a chance, I'd really appreciate it if they could either merge this post with my old one, or delete the old one.

    [EDIT]: Now that I think about it, the source code here is actually slightly different from the v1.3 code, as it's part way through the next update... all I've done is a quick bug-fix (gotta stop dividing by zero...) though, so it should be fine.
    Last edited by timmeh; 09-22-2009 at 03:45 PM. Reason: Forgot something...
    My Dev Blog - The most up-to-date info on my current projects.

  7. #112
    Registered User
    Join Date
    Apr 2010
    Posts
    1

    Tetris Game

    Hi everybody.I'm a new member in this forum.I'm a student from VietNam.
    +++++++++++++++++Info Game+++++++++++++++++++++


    Language:C (dont use graphics.h)
    Complier:Turbo C/C++ or BorLand C/C++
    OS:all version
    Written by: Le Tuan Anh ( by me)
    Email: [email protected]
    Age:20 - student of Univer Information Technology. VietNam
    Country:VietNam.

    +++++++++++++++++++++++++++++++++++++++++++++
    And this is my game:Tetris
    Programming language: C (dont use graphics.h)
    -Something about my game:
    +You can use mouse to click.
    +To configure game seting press [SPACE] and you have 7 option: SAVE,LOAD,CONTROL,HELP,ABOUT,RESUME,EXIT
    +Default,to moving you use :UP,DOWN,LEFT,RIGHT.if you want you can change them by click on [CONTROL]
    +[SAVE]:to save game into C:\
    +[LOAD]: to load game from C:\

    -->Download: HERE

  8. #113
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472

    Game Of Life project

    you can download the zip file here > Rogster GameOfLife
    a release version .exe is included in the zip folder so you can give it a go straight away without building if u want.
    i noticed there is a file 'graphics.cpp' file in the zip that is not required in the project so delete.

    this project is working and complete but there are quite a few development areas i never got around to for anybody that would like to carry it on for practice purposes perhaps.
    its SDL graphics, C++;

    It is quite easy to add new functionality as it is state machine based using a virtual class,



    some things i wanted to develop were / are >

    Add a nice graphics image screen as an intro instead of just going straight to the title screen. Also the title or any popups should animate open, and not just appear immediately, eg add a delay in the rendering and increment window opening

    In the 'User Defined' startup add a 'Zoomed in view' option so that the user can more accurately draw in seed pattern or known seed like a glider gun etc.

    Allow a cell size option, small / med / large before starting as the present default is small really, bigger cells might look better sometimes.

    Complete the Save / Load state, allow a library of preset start patterns like glider gun etc as as well as user saves. include a preview window of each save or load slot

    Also the buttons graphics are not really as i would normally do, rushed things a little in general on the graphics, the zip includes the bitmaps for any editing image files are not built into the binary.
    Last edited by rogster001; 04-07-2010 at 06:01 AM.

  9. #114
    Registered User
    Join Date
    Nov 2009
    Posts
    151
    You can download a .zip of my game here
    http://bijanscrap.webng.com/Downloads/Duck_Hunt.zip

    Operating system: Windows 7 (it should still work with vista and XP)
    Compiler: Code::Blocks 10.05
    Graphics library: Win32 API
    Other Libraries: libmsimg32.a, libwinmm.a
    Description: Shoot the ducks as they fly by

    Please PM me if you have any suggestions.
    Last edited by bijan311; 09-12-2010 at 10:00 AM.

  10. #115
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    428

    Sudoku

    Operating system: Windows
    Compiler: Dev-C++ 4.9.9.2
    Graphics Library: OpenGL
    Description: Sudoku (easy - medium)

    Basic Sudoku Program. It randomly generates puzzles and allows the user to play them. All the source code is included. If anyone notices more optimal generation techniques please let me know. It currently takes it 5-30 seconds to generate a new sudoku.

    Playing.. You'll notice a square "highlighted in red" this moves if you press arrow keys.. left, right, up, down. If you want to enter a choice just press a number 1-9 after you have highlighted the square. Pressing enter at ANY time playing will generate a new sudoku puzzle.

    Sudoku.zip

    Enjoy!

    *Update 19th Sept 10 - updated and all update information can be viewed in the readme file included in the zip

    All future projects will be hosted at Sudoku
    Last edited by laserlight; 09-27-2010 at 01:26 PM.

  11. #116
    Registered User
    Join Date
    Nov 2010
    Posts
    1

    Snake

    Here is my first game:

    Language: C
    Compiler: Dev-C++
    OS: Windows.
    Type: Console app.

    To download .exe:
    Wikisend: free file sharing service

    Source Code:

    Code:
    #include <stdio.h>
    #include <ctype.h>
    #include <stdlib.h>
    #include <windows.h>
    #include <conio.h>
    #include <limits.h>
    #include <dos.h>
    #include <stdlib.h>
    #define up 1
    #define down 2
    #define right 3
    #define left 4
    /*Global Variables*///----------------------------------------------------------
    unsigned long long int score;
    int foodx, foody, snake_length, direction = right, digest = 0;
    char keypress;
    struct snake_segment {
      int x, y;
    } snake[2000];
    
    const int snake_start_x = 33, snake_start_y = 7;
    /*Functions*///-----------------------------------------------------------------
    int random (int number_posibilities){  
        static long int h=9;
        h++;
        srand ((time(NULL)+h+9)*h);
    	return ( rand() % number_posibilities );
    }
    //------------------------------------------------------------------------------
    void clear_screen ( void ){
         DWORD n;                         /* Number of characters written */
         DWORD size;                      /* number of visible characters */
         COORD coord = {0};               /* Top left screen position */
         CONSOLE_SCREEN_BUFFER_INFO csbi;
         /* Get a handle to the console */
         HANDLE h = GetStdHandle ( STD_OUTPUT_HANDLE );
         GetConsoleScreenBufferInfo ( h, &csbi );
         /* Find the number of characters to overwrite */
         size = csbi.dwSize.X * csbi.dwSize.Y;
         /* Overwrite the screen buffer with whitespace */
         FillConsoleOutputCharacter ( h, TEXT ( ' ' ), size, coord, &n );
         GetConsoleScreenBufferInfo ( h, &csbi );
         FillConsoleOutputAttribute ( h, csbi.wAttributes, size, coord, &n );
         /* Reset the cursor to the top left position */
         SetConsoleCursorPosition ( h, coord );
    }
    //------------------------------------------------------------------------------
    void gotoxy(int x, int y){
         COORD coord;
         coord.X = x;
         coord.Y = y;
         SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
    }
    //------------------------------------------------------------------------------
    void clearxy (int x, int y){
         DWORD n;
         COORD coord;
         coord.X = x;
         coord.Y = y;
         CONSOLE_SCREEN_BUFFER_INFO csbi;
         HANDLE h = GetStdHandle ( STD_OUTPUT_HANDLE );
         GetConsoleScreenBufferInfo ( h, &csbi );
         FillConsoleOutputCharacter ( h, TEXT ( ' ' ), 1, coord, &n );
         GetConsoleScreenBufferInfo ( h, &csbi );
         FillConsoleOutputAttribute ( h, csbi.wAttributes, 1, coord, &n );
    }
    //------------------------------------------------------------------------------   
    void cursoroff ( void ){
         HANDLE hOut;
         CONSOLE_CURSOR_INFO ConCurInf;
         hOut = GetStdHandle(STD_OUTPUT_HANDLE);
         SetConsoleTitle("No Cursor");
         ConCurInf.dwSize = 10;
         ConCurInf.bVisible = FALSE;
         SetConsoleCursorInfo(hOut, &ConCurInf);
    }
    //------------------------------------------------------------------------------
    void color_red (void){
         HANDLE h;
         h = GetStdHandle(STD_OUTPUT_HANDLE);
         SetConsoleTextAttribute ( h, FOREGROUND_RED | FOREGROUND_INTENSITY );
    }
    //------------------------------------------------------------------------------
    void color_green (void){
         HANDLE h;
         h = GetStdHandle(STD_OUTPUT_HANDLE);
         SetConsoleTextAttribute ( h, FOREGROUND_GREEN | FOREGROUND_INTENSITY );
    }
    //------------------------------------------------------------------------------
    void color_blue (void){
         HANDLE h;
         h = GetStdHandle(STD_OUTPUT_HANDLE);
         SetConsoleTextAttribute ( h, FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY );
    }
    //------------------------------------------------------------------------------
    void color_yellow (void){
         HANDLE h;
         h = GetStdHandle(STD_OUTPUT_HANDLE);
         SetConsoleTextAttribute ( h, FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY );
    }
    //------------------------------------------------------------------------------
    void color_normal (void){
         HANDLE h;
         h = GetStdHandle(STD_OUTPUT_HANDLE);
         SetConsoleTextAttribute ( h, FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE );
    }
    //------------------------------------------------------------------------------
    int getx (void){
        int x;
        HANDLE hOut;
        CONSOLE_SCREEN_BUFFER_INFO SBInfo;
        hOut = GetStdHandle(STD_OUTPUT_HANDLE);
        GetConsoleScreenBufferInfo(hOut, &SBInfo);
        x =SBInfo. dwCursorPosition.X;
        return x;
    }
    //------------------------------------------------------------------------------
    int gety (void){
        int y;
        HANDLE hOut;
        CONSOLE_SCREEN_BUFFER_INFO SBInfo;
        hOut = GetStdHandle(STD_OUTPUT_HANDLE);
        GetConsoleScreenBufferInfo(hOut, &SBInfo);
        y =SBInfo. dwCursorPosition.Y;
        return y;
    }
    //------------------------------------------------------------------------------
    enum
    {
      KEY_ESC     = 27,
      ARROW_UP    = 256 + 72,
      ARROW_DOWN  = 256 + 80,
      ARROW_LEFT  = 256 + 75,
      ARROW_RIGHT = 256 + 77
    };
    //------------------------------------------------------------------------------
    static int get_code (void)
    {
      int ch = getch();
      if ( ch == 0 || ch == 224 )
         ch = 256 + getch();
      return ch;
    }
    //------------------------------------------------------------------------------
    void walls (void){
         int i, j;
         for (i=0;i<=23;i++)
             if (i==0 || i==23){
                for (j=1;j<=80;j++)
                printf ("%c", 177);
             }
             else {
                 printf ("%c", 177);
                 for (j=1;j<=78;j++)
                 printf (" ");
                 printf ("%c", 177);
             }          
    }
    //------------------------------------------------------------------------------
    void intro (void){
         cursoroff();
         color_blue();
         gotoxy(37,10);
         printf ("SNAKE");
         gotoxy(25,13);
         printf ("An Alfio Vidal Amian's creation");
         sleep(3000);
    }
    //------------------------------------------------------------------------------
    void put_food (void){
         int i, x = getx(), y = gety(), same;
         do{
            foodx = random(76)+1 , foody = random(19)+1;
            for (i=0;i<=snake_length;i++)
                if (foodx == (snake[i].x) && foody == (snake[i].y))
                   same = 1;
         }while (same == 1);
         gotoxy (foodx,foody);
         color_red();
         printf ("%c", 2);
         color_normal();
         gotoxy(x,y);  
    }    
    //------------------------------------------------------------------------------
    void set_game (void){
         int i;
         snake_length = 5;
         score = 0;
         keypress = 'z';
         clear_screen();
         color_green();
         walls();
         color_normal();
         put_food();
         printf ("   SCORE: %5d                      Alfio Games %c", score, 184);
         cursoroff();
         for (i=0;i<snake_length;i++)
         {
             snake[i].x = snake_start_x+i;
             snake[i].y = snake_start_y;
         }
    }
    //------------------------------------------------------------------------------
    void display_menu (void){
         clear_screen();
         color_yellow();
         printf ("\n                                      SNAKE");
         printf ("\n\n\n\n");
         printf ("     Press 1 to PLAY\n");
         printf ("     Press 2 for Instructions\n");
    }
    //------------------------------------------------------------------------------
    void display_instructions (void){
         clear_screen();
         printf ("\n\n\n");    
         printf ("\n                  Move arround using the keyboard arrows.");
         printf ("\n                  Press any other key to PAUSE.");
         printf ("\n                  Press ESC to exit game.");
         printf ("\n                  Earn points and grow as you collect food.");
         printf ("\n                  Avoid the walls and yourself.");
         color_red();
         printf ("\n\n\n\n\n                  Press any key to return to MENU");
    }
    //------------------------------------------------------------------------------
    void clear_segment (void){
         int i;
         gotoxy (snake[0].x, snake[0].y);
         printf(" ");
         for (i=1; i<=snake_length; i++)
             snake[i-1] = snake[i];
    }
    //------------------------------------------------------------------------------
    void add_segment()
    {
      switch(direction)
      {
        case(right): snake[snake_length].x=snake[snake_length-1].x+1;
                         snake[snake_length].y=snake[snake_length-1].y;
                         break;
        case(left) : snake[snake_length].x=snake[snake_length-1].x-1;
                         snake[snake_length].y=snake[snake_length-1].y;
                         break;
        case(up)   : snake[snake_length].x=snake[snake_length-1].x;
                         snake[snake_length].y=snake[snake_length-1].y-1;
                         break;
        case(down) : snake[snake_length].x=snake[snake_length-1].x;
                         snake[snake_length].y=snake[snake_length-1].y+1;                 
      }
      gotoxy(snake[snake_length].x,snake[snake_length].y);
      printf ("%c", 219);
    }
    //------------------------------------------------------------------------------
    void show_score (void){
         color_normal();
         gotoxy(2,24);
         printf (" SCORE: %5d                      Alfio Games %c", score,  184);    
    }
    //------------------------------------------------------------------------------
    void collision_detection (void){
         int i;
         if ( (snake[snake_length-1].x>78) || (snake[snake_length-1].x<=0) ||
              (snake[snake_length-1].y>22) || (snake[snake_length-1].y<=0)    )
              keypress = 'x';
         for (i=0;i<snake_length-1;i++){
             if ((snake[snake_length].x)==(snake[i].x)&& (snake[snake_length].y)==(snake[i].y)){
                keypress = 'x'; 
                break;
             }
         }
         if ( (snake[snake_length-1].x == foodx) && (snake[snake_length-1].y == foody) ){
            score+=snake_length;
            show_score();
            digest = 1;
            snake_length++;
            put_food();
          }
    }
    //------------------------------------------------------------------------------
    
    main ()
    {
         int ch, ans, i, menu_op, x, y;
        intro();
    menu:
         cursoroff();
         display_menu();
         sleep(500);
         do{
            menu_op = getch();
         }while (menu_op < 49 || menu_op > 50);
         if (menu_op == 50){
            display_instructions();
            if (getch())
               goto menu;
         }
    game_start: 
         if (menu_op == 49)
            set_game();
            
            for (i=0;i<snake_length;i++)
          {
            gotoxy(snake[i].x,snake[i].y);
            printf("%c", 219);
          }      
      while ( ( ch = get_code() ) != KEY_ESC && keypress != 'x' ) { /* Game loop */  
        switch ( ch ) {
            case ARROW_UP:
                 do{
                 direction = up;
                 add_segment();
                 if (digest == 1){
                    add_segment();
                    digest = 0;
                 }
                 clear_segment();
                 sleep(80);
                 collision_detection();
                 if( kbhit() ) {
                         ch = kbhit();
                         break;
                     }
                 }while (ch == ARROW_UP && keypress !='x');
                 if (keypress !='x')
                    break;
                 break;
            case ARROW_DOWN:
                 do{
                 direction = down;
                 add_segment();
                 if (digest == 1){
                    add_segment();
                    digest = 0;
                 }
                 clear_segment();
                 sleep (80);
                 collision_detection();
                 if( kbhit() ) {
                         ch = kbhit();
                         break;
                     }
                 }while (ch == ARROW_DOWN && keypress !='x');
                  if (keypress !='x')
                    break;
                 break;
            case ARROW_LEFT:
                 do{
                 direction = left;
                 add_segment();
                 if (digest == 1){
                    add_segment();
                    digest = 0;
                 }
                 clear_segment();
                 sleep(60);
                 collision_detection();
                 if( kbhit() ) {
                         ch = kbhit();
                         break;
                     }
                 }while(ch == ARROW_LEFT && keypress !='x');
                  if (keypress !='x')
                    break;
                 break;
            case ARROW_RIGHT:
                 do{
                 direction = right;
                 add_segment();
                 if (digest == 1){
                    add_segment();
                    digest = 0;
                 }
                 clear_segment();
                 sleep(60);
                 collision_detection();
                 if( kbhit() ) {
                         ch = kbhit();
                         break;
                     }
                 }while(ch == ARROW_RIGHT && keypress !='x');
                  if (keypress !='x')
                    break;
                 break;
        }
      }
      if ( ch == KEY_ESC ) 
           goto menu;
      if (keypress=='x'){
         clear_screen();
         walls();
         gotoxy(29,9);
         color_red();
         printf ("G A M E       O V E R");
         color_normal();
         gotoxy (33,11);
         printf ("Score = %5d", score);
         color_yellow();
         gotoxy (32,13);
         printf ("play again? Y/N");
                do{
                   ans = getch();
                }while (ans!=121 && ans!=89 && ans!=78 && ans!=110);
         if (ans == 121 || ans == 89)
            goto game_start;
         else
             goto menu;      
      }
       sleep (10000);       
    }

  12. #117
    Registered User
    Join Date
    Oct 2010
    Posts
    45

    Memory Card Match

    Here is a little 4x4 grid of match the picture cards. There is no score or timer, this is my first go at making a game with graphics.

    The source code is included, minus the pictures - due to the fact I thefted them from online sources.

    Used Code::Blocks and SDL (including SDL_image.h which is an extension lib for using file types other than .BMP).

    I used 199 x 199 sized pics for the cards, if you want to put your own pics in.

    Please leave me some feedback on how things could be better, or how I should have done something other than how I did it.

    Memory.zip

  13. #118
    Registered User
    Join Date
    Oct 2010
    Posts
    45

    Link

    Unable to edit the link, which was missing files apparently. Here is a good link to it.

    Memory.zip

  14. #119
    Registered User
    Join Date
    Nov 2009
    Posts
    151
    I'm not sure if I can post this here, because this isn't a game (but game related), but I want to get this out there. This is a graphics engine (I think that's the appropriate name for it) for windows.

    Operating system: Windows 7 (should work for any)
    Compiler: MinGW
    Graphics Library: Win32 API
    Other Libraries:
    Description: You can use this to load, and manage bitmaps

    message me if you have any suggestions or find any bugs.

    here is the link to it
    http://bimangames.dyndns.org/games/bitmap.zip

  15. #120
    Registered User suda_51's Avatar
    Join Date
    Apr 2011
    Posts
    2
    I have to tell thıs rule when yo start to wrte a program or game (ıs program ) you have to protect your program or code because when user get ınput (wrong) ın program .Program dont do crazy thıngs .

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Resources for professional games
    By EVOEx in forum Game Programming
    Replies: 8
    Last Post: 06-17-2009, 02:42 PM
  2. need help with HTTP POST
    By Anddos in forum Networking/Device Communication
    Replies: 5
    Last Post: 03-22-2009, 08:41 AM
  3. Unknown memory leak with linked lists...
    By RaDeuX in forum C Programming
    Replies: 6
    Last Post: 12-07-2008, 04:09 AM
  4. Auto POST
    By vasanth in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 06-07-2003, 10:42 AM