Vous êtes sur la page 1sur 10

#include<conio.

h>
#include<stdio.h>
#include<stdlib.h>
#include<time.h>

void start(void);
void display(char[50][50]);
void moveup(char);
void movedown(char);
void moveright(char);
void moveleft(char);
void wellcome(void);
void byebye();

int c_new_row;
int c_last_row;
int c_new_col;
int c_last_col;
int m_new_row;
int m_last_row;
int m_new_col;
int m_last_col;
char maze[50][50]={42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,4
2,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,
42,32,42,
42,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,3
2,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
32,32,32,42,
42,42,42,42,42,42,42,42,42,42,42,42,42,32,42,42,32,42,42,4
2,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,32,42,42,42,42,42,42,42,
42,42,32,42,
42,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,3
2,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
32,32,32,42,
42,32,42,42,42,42,42,42,42,42,42,42,42,42,42,4
2,42,42,42,42,42,42,42,42,32,42,42,42,42,42,42,42,42,42,42,42,42,32,42,42,42,42,
42,42,42,42,42,42,42,42,
42,32,32,32,32,32,32,32,32,32,32,32,32,32,32,3
2,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
32,32,32,32,32,32,32,42,
42,42,42,42,42,42,42,42,42,42,42,42,32,42,42,4
2,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,
42,42,42,42,42,42,32,42,
42,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,3
2,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
32,32,32,42,
42,32,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,4
2,42,42,42,42,32,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,
42,42,42,42,
42,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,3
2,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
32,32,32,42,
42,42,42,42,42,42,42,42,42,42,42,42,32,42,42,4
2,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,
42,42,42,42,42,42,32,42,

42.32.42.32.42.4 2.42.32.32.42.42.42.42.42.32.32.42.42.32.32.32.32.32.32.42.42.32.42.42.42.32.42.42.32.32.42.32.32.32.32.42.32.32.42.42.32.32.42.32.42.32.42.42.42.32.42.32.42.32.42.32.42.42.32.42.32.32. 32.32.32.32.42.42.32.32.42. 32.32.42.42.42.32.42.32.42.32.32.32.32.32.42.42.42.42.42.32.42.4 2.32.42.32.42.42.32.32.42.32.42.42. 32.32.32.32.32.42.32.42. 42.42.42.32.32.42.32.32.32.42.32.32.42.42.32.32.42.32.42. 42.4 2.32.42.32.42.32.42.32.42.32.42.42.32.42.42. 32.42.32.32.42.32.42. 42.32.42.32.42.32.42.32.32.32.42. 42.42.32.42.32.42.42.32.42.32.42.32.42.32. 42.42.32.42.32.32.32.42.32.32.32.32.42.42.32.32.32.32.32.32.42.42.42.32. 42.32.42.42.32.32.32.42.32.4 2.42.32.42.32.32.32.42.42.42.32.32.42.42.42.42.3 2.42.32.42.32.42.42.42.42.32.32. 42.32.42.42. 32.42.32. 42. 32.42.42.42.32.32.4 2.32.32.3 2.42.32.32. 42.32.32.32.32.42.32.42.42.42.42.32.42.32.32.42.42.32.32.32.42.32.32.42.32.42.42.42.32.32.32.3 2.42.32.32.32.32.3 2.42.32.42.32.32.32.32.32.3 2.42.42.32.42.32.42.32.32.42.32.42.42.32.32.42.42.32.32.32.32.32.42.42.32.42.32.42.32.42.42.42.42.42.42.32.32.32.4 2.42.32.42.42.42.42.32.42.42.42.42.42.42.32.42.42.32.42.32.42.42.32.32.42.32.32.42.42.42.32.42.3 2.32.42.32.32.32.42.42.32.42.32.32.32.42.32.32.42.42.42.32.42.42.32.42.32.32.32.32.32.32.42.42.42.42.32.42.32.42.42.32.32.32.32.42. 42.42.42.42.42.32.32.32.42.42.42.42.42.32.42.42.32.32.42.32.32. 42.42.42.32.42. 42.32.32.42.32.32.42.42.42.42.32.42.32.42.32.32.42.42.32.42.42.32.32.42.32.32. 42.42.42. 42.42.42.42.42.42.42.32.42.42.42.42.32.42.42.42.42.32.42.42.42.32.32.32.32.42.32.42.42.42.42.32.42.32.42.32.42.42.32.32.4 2.42.42.32.42.42.42.32.32.42.42.32.32.42.42.32.3 2.32.32.42.42.32.32.32.32.32.32.42.32.42.32. 42.32.42.32.32.42.32.42. 42.32.32.32.32.32.32.32.32.42.42.42.32.42.32.3 2.42.32.42.32.32.32.42.32.42.42.32.32.32.32.32.32.32.32.42.42.32.42.42.42.42.32.32.32.42.32.42.32.32.42.42. 42.4 .42.42.32.32.32.42.42.32.42.42.32.32.32.32.42.32.42.32.42.42. 42.32.42.32.42.32. 42.32.32.32.32.32.32.42.32. 42.42.32. 42.32.42.42.42.32.32.32.32.42.32.32.42.32.32.42.42.42.32.42.42.42.32.32.42.32.42.32.32.42.42.32.32.32.32.32.32.32.42.42.32.32.32. 32.32.32.42.42.42.32.32.32.32.42.32.32.32.42.42.42.3 2.32.42.32.42. 42.42.32.42.32.42.32.32.42.32.32.32.42.42.32.42.4 2.42.32.32.42.42. 32.32.42.42.32.42.32.32.42.32.42.42.42.32.32.32.42.42.42. 42.32.32.42.32.42.42.42.32.32.32.32.32.32.42.32.42.42.42.32.42.32.32.32.32.32.32.42.32.42.42.42.32.32.32.42.42.3 2.32. 42.42.32.32.42.42.32.42.32.32.32.42.42.42.42.32.42.32.32.32.32.32.42.42.32.32.32.32.32.32.32.42.32. 42.32.42.32.32.32.32.42.42.42.32.42.32.32.32.32.42.32.32.42.32.42.42.32. 32.42.32.42.32.32.42.42.32.42.42.32.32.42.42.42.32.32.32.42.42.42.32.32.32.32.32.32.32.42.32.42. 42.32.32.32.42.32.42.32.32.32.32.32.32.42.42.32. 42.42.42. 32.42.42.32.32.42.42.32.32.42. 42.32.42.32.42.42.42.32.42.32.42.32.32.42.42.42.32.42.42.42.42.32.42.32.42. 42.42.4 2.32.32.32.32.32.42.42.42.32.42.42.32.42.42.32.32.32.32.32.32.42.42.42.42.42.32.42.32.32.

32.42.42.32.32.42.42.32.32.32.32.32.32.32.42.42.32.42.32.32.42.32.42.42.32.32.42.32.32.42.32.42.42.32.42.42.32.32.42.42.42.32.42.32.42.42.32.42. 42.42.42.32.32.32.32.42.32.42.42.32.32. .32.32.42.42.32.32. 32.32.42.42.32.42.32.42.42.32.32.32.32.42.32.42.42.32.42.42.32.42.32.42.32.32.42.32.32.42.4 2.32.42.42.42.32.32.42.32.42.42.32.32.32.32.42.32.4 2.32.42.32.42.32. 42.32.32.32.32.42.3 2.42.32.42.42.42.42.42.42.42.32.42.42.42.42.32.32.42.42.42.42.42.42.32.42.32.32.42.42.42.42.32.32.32.32.32.42.32.32.42.32.42.42.42.32.32.42.42.32.42.32. 42.32.42.32.32.32.32.42.32.32.42.42.32.32.32.32.32.42.42.42.32.32.32.42.32.32.42. 32.32.32.32.32.3 2.42.42.42.42.42.42.32.32.42.32.42.42.32.32.42.32.32. 42.32.42.42.42.42.32.42. 42.42.42.32.42.42.42.32.42.32.32.42. 42.42.32.32.42.42.32.42.42.42.32.32.42.42.32.42.32.32.42.42.32. 32.32.42.32.32.32.42.32.42.32. 42.42.42.42.42.42.32.4 2.32.32.42.32.32.32.42. 42.2.32.32.32.32.32.3 2.32.42.42.32.32.32.42.32.32.32. 42.42.42.32.32.32.32.42.32.32.32. 32.32.42.42.42.42.42.42.42.32.42.32.42.42.32.32.32.32.32.42.42.42.32.32.42.42.42.32.42.32.32.32.42.32.32.32.42.32.42.32.32.32.42.32.32.42.32.32.32.32.32.32.42.42.42.42.32.42.32.42.42.42.32.32.42.42.32.32.42.42.32. 42.42.42.32.42.32.42.42.42.32. 42.32.32.42.32.32.42.32.42.32.32.32.32.32.42.32.32.42.32.32.32.42.32.42.32.42. 32.32.32.32.32.42.32.32.32.42 .42.32.32.42.32.32.32.42.42.32.42.32.42 .32.32.3 2.32.32.32.32.42.42.32.42.32.42.32.42.32.42.32.32.42.42.32.42.42.32.42.42.42.32.42.32.42.32.42.42.42.42.42.32.32.32.32.42.42.42. 42.42.42.42. 42.3 2.42.32.42.32.32.32.42.32.32.32.32.32.32.42.42.32.32.42.32.32.42.42.32.42.32.3 2.32.32.42.42.42.32.32.32.32.42.42.32.42.32.42.32.42.42.32.42.32.42.42.42.32.32.42.32.32.42.42.4 2.32.42.42.42.32.42.32.32.42.42.32.32.42.32.42.32.42.42.42.32.32.32.32.32.32.32.42.32.32.42.32.42. 42.32.42.42.32.42.42.42.42. 42.42.42.4 2.32.42.42.42.42.42.32.42.32.42.32.4 2. 32.32.42.42.32. 32.42.32.32.42.42.32.32.32.32.42.42.42.42.42.32.32.42.42.42.4 2.32.4 2.42.32.32.42.42.32.42.42.32.42.32.42.32.32.32.42.32.32.32.42.42.32.32.32.42.42.32.42.42.42. 42.32. 42.32.42.42.32.42.32.32.32.42.32.32.32.32.42.32.32. 42.42.32.32.42.42.42.42.32.32.42.32.32.32.42.32.42.32.32.32.32.32.32.42.42.42.42.42.42.32.32.32.42.32.42.32.32. 32.42.32.42.32.42.42.42.32.32.32.32.42.42.42.42.32.32.32.42.32.32.42.42.42.32.32.32.32. 42.32.42.42.42. 32.32.32.32.42.42.32.32.42.42.42.42.42.42.42.32.42.42.32.32.42.32.42.32.42.32.32.32.32.32.32.32.42.3 2.42.32.32.42.32.42.32.42.42.32.42. 42.42.42.32.42.42.42.42.42. 42.42.42.42.32.42.32.32.42.32.4 2.42.32.42.32. 42.32.32.42.42.42.32.42.32.3 2.32.42.42.42.42.32.32.42.42.32.32.42.42.42.42.32.32. 42.42.32.32. 32.32.42.32.42.32.32.42.32.42.42.42.42. 42.3 2.32.42.42.42.32.42.42.32.32.32.32.42.42.32.42.32. 42.32.42.32.32.32.32.32.32.42.42.42.42.32.32.32.32.32.32.42.42.32.32.32. 42.32.42.32.32.42.42.32.32.32.32.32.42.32.32.42.32.32.3 2.42.42.42.42.42.42.42.32.32.42.32.42.42.32.42.32.42.32.32.32.32.32.42.32.42.42.42.32.32.42.42.32.42.42.42.32.42.

42. } // end of case 68 or 100 case 82: case 114: { // start of ase 82 or 114 for D( down) if(maze[c_new_row][c_new_col+1]! =42) . // displays start screen while(cut==1) { // start of while input=getch(). char input.42. switch(input) { // start of swith case 117: case 85: { // start of case 117 or 85 for U(Up) if(maze[c_new_row-1][c_new_col]! =42) { moveup('C'). wellcome().42.chance1.chance2. void main() { // start of main int cut=1. srand(time(NULL)). } break. chance=(1+rand()%2). } // end of case 117 or 85 case 68: case 100: { // start of ase 68 or 100 for D( down) if(maze[c_new_row+1][c_new_col]! =42) { movedown('C'). } break.}.42. start().chance.

} break. moveup('M'). . } // end of case esape } // end of switch if(chance==1) {//if chance=1 if(maze[m_new_row-1][m_new_col]==32) { moveup('M'). } // end of case 82 or 114 case 27: { // start of case esape cut=0. } else if(maze[m_new_row+1][m_new_col]==32) { movedown('M'). break. chance=2. { moveright('C'). } // end of case 82 or 114 case 76: case 108: { // start of ase 82 or 114 for D( down) if(maze[c_new_row][c_new_col-1]! =42) { moveleft('C'). } break. } else if(m_new_col<48) { moveright('M'). movedown('M').

} else if(m_new_col>1) { moveleft('M'). } }//end if chance=2 } // end of while . chance=2. } else if(maze[m_new_row+1][m_new_col]==32) { movedown('M'). } }//end if chance=1 else if(chance==2) {//if chance=2 if(maze[m_new_row-1][m_new_col]==32) { moveup('M'). movedown('M'). chance=1. } else if(m_new_col>1) { moveleft('M'). moveup('M'). } else if(m_new_col<48) { moveright('M'). chance=1.

} // end of start() void display(char maze[50][50]) { // start of display int row. byebye(). c_new_col=25. m_last_row=25. c_last_row=48. } // end of wellcome void start(void) { // start of start() c_new_row=48. printf("\n\t\t\tPress U to move UP "). } // end of main void wellcome(void) { // start of wellome printf("\n\n\n\n\n\n\t\t\tWELLCOME TO CATCH THE RAT GAME "). maze[m_new_row][m_new_col]='M'. printf("\n\t\t\tPress D to move Down "). display(maze). . m_new_col=25. printf("\n\t\t\tPress R to move Right ").col. maze[c_new_row][c_new_col]='C'. m_last_row=25. printf("\n\t\t\tPress any Key to start "). printf("\n\t\t\tPress L to move Left "). m_new_row=25. c_last_col=25. getch(). getch().

} // end of outer for printf("\n\t\t\Press ESC to exit "). c_new_row=c_new_row+1. maze[c_new_row][c_new_col]='C'. c_new_row=(c_new_row-1).row++) { // start of outer for for(col=0. maze[m_new_row][m_new_col]='M'. maze[m_last_row][m_last_col]=32. system("cls"). } // end of display void moveup(char ch) { // start of move up if(ch=='C') { c_last_row=c_new_row.maze[row][col]). c_last_col=c_new_col. } // end of inner for printf("\n"). } else if(ch=='M') { m_last_row=m_new_row. } } // end of move up void movedown(char ch) { // start of down if(ch=='C') { c_last_row=c_new_row. maze[c_last_row][c_last_col]=32. maze[c_new_row][c_new_col]='C'. c_last_col=c_new_col.col<50. for(row=0. display(maze). m_last_col=m_new_col. maze[c_last_row][c_last_col]=32. display(maze). display(maze).col++) { // start of inner for printf("%c". m_new_row=(m_new_row-1).row<50. } .

display(maze). } } // end of move right void moveleft(char ch) { //start of move left if(ch=='C') { c_last_row=c_new_row. c_last_col=c_new_col. } else if(ch=='M') { m_last_row=m_new_row. maze[c_new_row][c_new_col]='C'. maze[c_new_row][c_new_col]='C'. m_new_col=m_new_col+1. display(maze). c_new_col=c_new_col-1. . else if(ch=='M') { m_last_row=m_new_row. c_new_col=c_new_col+1. c_last_col=c_new_col. maze[c_last_row][c_last_col]=32. maze[m_new_row][m_new_col]='M'. m_last_col=m_new_col. maze[m_last_row][m_last_col]=32. m_new_row=m_new_row+1. maze[m_last_row][m_last_col]=32. m_last_col=m_new_col. } } // end of down void moveright(char ch) { //start of move right if(ch=='C') { c_last_row=c_new_row. display(maze). maze[m_new_row][m_new_col]='M'. display(maze). maze[c_last_row][c_last_col]=32.

m_new_col=m_new_col-1. printf("\n\t\t\tPress any Key to QUIT"). } } // end of move left void byebye(void) { // start of byebye system("cls"). m_last_col=m_new_col. } else if(ch=='M') { m_last_row=m_new_row. maze[m_new_row][m_new_col]='M'. } // end of byebye . printf("\n\n\n\n\n\n\t\t\tThanks for playing CATCH THE RAT GAME "). maze[m_last_row][m_last_col]=32. display(maze).