Add to Favorites    Make Home Page 3225 Online  
 Language Categories  
 Our Services  

Home » C Home » Games and Graphics Home » Game Of Numbers- Without Graphics But with Colors

A D V E R T I S E M E N T

Search Projects & Source Codes:

Title Game Of Numbers- Without Graphics But with Colors
Author Jiten Sharma
Author Email hottyice_cooldude [at] yahoo.com
Description
Category C » Games and Graphics
Hits 371417
Code Select and Copy the Code
/* GAME OF NUMBERS IMPLEMENTATION FOR C++ 3.0. /* Game Implementation */ /* GAME.C */ */ # include <stdio.h> # include <conio.h> # include <dos.h> # include <process.h> # define UP_ARROW 72 /* Scan code of up arrow */ # define DOWN_ARROW 80 /* Scan code of down arrow */ # define LEFT_ARROW 75 /* Scan code of left arrow */ # define RIGHT_ARROW 77 /* Scan code of right arrow */ # define ESC 1 /* Scan code of escape key */ int a[4][4]={ /* Array to store the numbers */ {4,6,12,1}, {2,8,10,14}, {3,7,13,9}, {5,11,15,0} }; int r=3; /* Row of the array */ int c=3; /* Coloumn of the array */ int moves=0; /* To count no. of moves */ /* Prototype Declaration */ void Display(void); /* Prototype of display function */ void Boxes(void); /* Prototype of boxes function */ void Game(void); /* Prototype of game function */ void Esc(void); /* Prototype of escape function */ int Getkey(void); /* Prototype of getkey function */ void Install(void); /* Prototype of install function */ void Rules(void); /* Prototype of rules function */ void Win(void); /* Prototype of win function */ /* Main Game Function */ void Game(void) { int ch; int temp; Boxes(); Display(); while(1) { ch=Getkey(); switch(ch) { case DOWN_ARROW : if(r==0) { printf("a"); break; } temp=a[r][c]; a[r][c]=a[r-1][c]; a[r-1][c]=temp; r--; moves++; Display(); break; case UP_ARROW : if(r==3) { printf("a"); break; } temp=a[r][c]; a[r][c]=a[r+1][c]; a[r+1][c]=temp; r++; moves++; Display(); break; case LEFT_ARROW : if(c==3) { printf("a"); break; } temp=a[r][c]; a[r][c]=a[r][c+1]; a[r][c+1]=temp; c++; moves++; Display(); break; case RIGHT_ARROW : if(c==0) { printf("a"); break; } temp=a[r][c]; a[r][c]=a[r][c-1]; a[r][c-1]=temp; c--; moves++; Display(); break; case ESC : Esc(); break; default : break; } } } /* Escape Function */ void Esc(void) { Win(); gotoxy(27,22); textcolor(LIGHTGREEN); cprintf("No. of moves = %d",moves); getch(); exit(0); } /* Display Function */ void Display(void) { int r1=9,c1=30; int i,j; textcolor(MAGENTA); for(i=0;i<4;i++) { for(j=0;j<4;j++) { if(a[i][j]==0) { gotoxy(c1,r1); cprintf(" "); } else { gotoxy(c1,r1); cprintf("%d",a[i][j]); } c1=c1+3; } c1=30; r1=r1+2; } } /* Function To Draw Boxes */ void Boxes(void) { int i,j; gotoxy(26,3); textcolor(MAGENTA); cprintf("GAME OF THE CENTURY"); textcolor(YELLOW); for(i=8;i<=16;i=i+2) { for(j=29;j<=41;j++) { gotoxy(j,i); cprintf("%c",196); } } for(i=29;i<=42;i=i+3) { for(j=8;j<=16;j++) { gotoxy(i,j); cprintf("%c",179); } } gotoxy(29,8); cprintf("%c",218); gotoxy(29,16); cprintf("%c",192); gotoxy(41,8); cprintf("%c",191); gotoxy(41,16); cprintf("%c",217); for(i=32;i<=38;i=i+3) { gotoxy(i,8); cprintf("%c",194); } for(i=32;i<=38;i=i+3) { gotoxy(i,16); cprintf("%c",193); } for(i=10;i<=14;i=i+2) { for(j=32;j<=38;j=j+3) { gotoxy(j,i); cprintf("%c",197); } } for(i=10;i<=14;i=i+2) { gotoxy(29,i); cprintf("%c",195); } for(i=10;i<=14;i=i+2) { gotoxy(41,i); cprintf("%c",180); } } /* Function To Get The Scan Code of Key */ int Getkey(void) { union REGS i,o; while(!kbhit()); i.h.ah=0; int86(22,&i,&o); return(o.h.ah); } /* Install Menu Function */ void Install(void) { int i,j; int c=11,r=19; int time=0; gotoxy(32,13); textcolor(BROWN); cprintf("INSTALLING MENU"); textcolor(YELLOW); gotoxy(1,19); cprintf("Installing"); for(i=20;i<=22;i=i+2) { for(j=1;j<=80;j++) { gotoxy(j,i); cprintf("%c",196); } } for(i=20;i<=22;i++) { gotoxy(1,i); cprintf("%c",179); } for(i=20;i<=22;i++) { gotoxy(80,i); cprintf("%c",179); } gotoxy(1,20); cprintf("%c",218); gotoxy(1,22); cprintf("%c",192); gotoxy(80,20); cprintf("%c",191); gotoxy(80,22); cprintf("%c",217); for(i=2;i<=79;i++) { gotoxy(i,21); printf("%c",176); } for(i=2;i<=79;i++) { gotoxy(i,21); delay(500); textcolor(BLUE); cprintf("%c",219); gotoxy(67,19); printf(" "); if(c==15) { for(j=11;j<=15;j++) { gotoxy(j,19); printf(" "); } c=11; } gotoxy(c,r); textcolor(YELLOW); cprintf("."); c++; gotoxy(67,19); textcolor(YELLOW); cprintf("%d% Completed",time); if(time<=60) { time++; } else if(time<=71) time=time+2; else time=time+3; if(i==78) time=time-3; } } /* Rules Menu Function */ void Rules(void) { int i; textcolor(LIGHTCYAN); gotoxy(39,5); cprintf("RULES"); textcolor(GREEN); gotoxy(18,7); cprintf("1. Your aim is to arrange numbers in ascending order"); gotoxy(18,9); cprintf("2. The player with minimum no. of moves wins the game"); textcolor(LIGHTGRAY); for(i=17;i<=71;i++) { gotoxy(i,6); cprintf("%c",196); } for(i=17;i<=71;i++) { gotoxy(i,10); cprintf("%c",196); } for(i=6;i<=10;i++) { gotoxy(17,i); cprintf("%c",179); } for(i=6;i<=10;i++) { gotoxy(71,i); cprintf("%c",179); } gotoxy(17,6); cprintf("%c",218); gotoxy(17,10); cprintf("%c",192); gotoxy(71,6); cprintf("%c",191); gotoxy(71,10); cprintf("%c",217); } /* Function To Check For Win */ void Win(void) { int i,j,pos; int flag=1; int arr[20]; for(i=0;i<4;i++) { for(j=0;j<4;j++) { pos=i*4+j; arr[pos]=a[i][j]; } } for(i=0;i<pos;i++) { if(arr[i]>arr[i+1]) { flag=0; break; } } if(flag==1) { gotoxy(30,21); printf("YOU WIN"); } } /* The Main Function */ void main(void) { clrscr(); Install(); sleep(1); clrscr(); Rules(); getch(); clrscr(); Game(); getch(); }

Related Source Codes

Script Name Author
The Game Opposite as seen on Nokia 2300 Mobile Manikanta
RECURSIVE BALANCED QUICK SORT ashish
Radix Sort ashish
Change your mouse pointer Ashim
The blinking star Shashank
Data Validation Crylittlebaby
To search a file by giving file type like mp3 or mpeg or doc Prashanth SR
Menus Demonstration B.Chidhambaram
Employee Database Project Using C. Reenku Raman Nayak
Creating a Lexical Analyzer in c fahad bader al-buhairi ¦Õ¤ ?¤Ð Ãß??ÝÐÝ
Calendar Program Omkar & Devendra
Stop double Process for start in C Cedrik Jurak
Stop double Process for start in C Cedrik Jurak
Time Scheduler Atiq Anwar
A timepass game between atmost two players Rahul Roy

A D V E R T I S E M E N T




Google Groups Subscribe to SourceCodesWorld - Techies Talk
Email:

Free eBook - Interview Questions: Get over 1,000 Interview Questions in an eBook for free when you join JobsAssist. Just click on the button below to join JobsAssist and you will immediately receive the Free eBook with thousands of Interview Questions in an ebook when you join.

New! Click here to Add your Code!


ASP Home | C Home | C++ Home | COBOL Home | Java Home | Pascal Home
Source Codes Home Page

 Advertisements  

Google Search

Google

Source Codes World.com is a part of Vyom Network.

Vyom Network : Web Hosting | Dedicated Server | Free SMS, GRE, GMAT, MBA | Online Exams | Freshers Jobs | Software Downloads | Interview Questions | Jobs, Discussions | Placement Papers | Free eBooks | Free eBooks | Free Business Info | Interview Questions | Free Tutorials | Arabic, French, German | IAS Preparation | Jokes, Songs, Fun | Free Classifieds | Free Recipes | Free Downloads | Bangalore Info | Tech Solutions | Project Outsourcing, Web Hosting | GATE Preparation | MBA Preparation | SAP Info | Software Testing | Google Logo Maker | Freshers Jobs

Sitemap | Privacy Policy | Terms and Conditions | Important Websites
Copyright ©2003-2024 SourceCodesWorld.com, All Rights Reserved.
Page URL: http://www.sourcecodesworld.com/source/show.asp?ScriptID=1106


Download Yahoo Messenger | Placement Papers | Free SMS | C Interview Questions | C++ Interview Questions | Quick2Host Review