Home > Back-end >  Double snake, the second boss ask what keep?
Double snake, the second boss ask what keep?

Time:11-29

#include
#include
#include
#include
#include

Char qipan [20] [80].
Int the snake=1;

Int change (int * head, tail, int * int * score, char * direction, int zuobiao [2] [80])
{
int x, y;
The switch direction (*)
{
Case: 72
X=zuobiao [0] [* head] - 1;
Y=zuobiao [1] [* head];
break;
Case: 87
X=zuobiao [0] [* head] - 1;
Y=zuobiao [1] [* head];
break;
Case: 80
X=zuobiao [0] [* head] + 1;
Y=zuobiao [1] [* head];
break;
Case: 83
X=zuobiao [0] [* head] + 1;
Y=zuobiao [1] [* head];
break;
Case: 74
X=zuobiao [0] [* head];
Y=zuobiao [1] [* head] - 1;
break;
Case: 75
X=zuobiao [0] [* head];
Y=zuobiao [1] [* head] - 1;
break;
Case: 76
X=zuobiao [0] [* head];
Y=zuobiao [1] [* head] + 1;
break;
Default:
X=zuobiao [0] [* head];
Y=zuobiao [1] [* head] + 1;
}
If (qipan [x] [y]=='_' | | qipan [x] [y]=='|' | | qipan [x] [y]=='*')
return 1;
If (qipan [x] [y]==' ')
{
Qipan [zuobiao [0] [* tail]] [zuobiao [1] [* tail]]=' ';
* tail=(* tail + 1) % 80;
Qipan [zuobiao [0] [* head]] [zuobiao [1] [* head]]='*';
* head=(* head + 1) % 80;
Zuobiao [0] [* head]=x;
Zuobiao [1] [* head]=y;
Qipan [x] [y]='#';
return 0;
}
If (qipan [x] [y]=='@')
{
Qipan [zuobiao [0] [* head]] [zuobiao [1] [* head]]='*';
* head=(* head + 1) % 80;
Zuobiao [0] [* head]=x;
Zuobiao [1] [* head]=y;
Qipan [x] [y]='#';
* score +=1;
return 0;
}
}
Void gotoxy (int x, int y)//position function
{
COORD pos.

Pos. X=X;

Pos. Y=Y;

SetConsoleCursorPosition (GetStdHandle (STD_OUTPUT_HANDLE), pos);
}
Void color/color/function (int a)
{

SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE), a);

}
Void show_start ()
{

Gotoxy (20, 0);
Color (1);
Int u;
For (u=0; U & lt; 18; U + +)
Printf (" * ");
Gotoxy (20, 12);
For (u=0; U & lt; 18; U + +)
Printf (" * ");
Gotoxy (28, 2);
Color (13);
Printf (" S N A K E G A M E ");
Gotoxy (31, 5);
Color (14);
Printf (" # ");
Gotoxy (34, 5);
Color (11);
Printf (" One snake ");
Gotoxy (34, 7);
Printf (" Two snakes ");
Gotoxy (28, 9);
Printf (" The speed you want: ");

Gotoxy (31, 5);
Char temp='a';
Color (14);
While (1)
{
while(! Kbhit ());
Temp=getch ();
If (temp==72 | | temp==80)
{
Gotoxy (31, 5 + 2 * (snake - 1));
Printf (" ");
Snake snake %=2 + 1;
Gotoxy (31, 5 + 2 * (snake - 1));
Printf (" # ");
Gotoxy (31, 5 + 2 * (snake - 1));
}
If (temp==13)
break;
}

Gotoxy (27, 10);
Color (10);
Printf (" GOOD LUCK TO YOU!" );
}






Int main ()
{
Srand (time (0));

Int head1=3, tail1=0, score1=0;
Int head2=3, tail2=0, score2=0;
Int zuobiao1 [2] [80].
Int zuobiao2 [2] [80].

/* checkerboard initialization 20 x 80 */
for(int i=0; I & lt; 20; I++)
{
For (int j=0; J & lt; 80; J++)
{
Qipan [I] [j]=' ';
}
}
for(int i=0; I & lt; 20; I++)
{
Qipan [I] [0]=qipan [I] [79]='|';//the first column, the last column is wall 20 * 1
}
for(int i=0; I & lt; 80; I++)
{
Qipan [0] [I]=qipan [19] [I]='_'.//the first row, the last line is the wall 1 * 80
}

/* snake 2 x 8 initialization, the coordinates of the snake on board */
Int the x1=1, x2=18, y, temp=0;

For (int m=tail1; M & lt; Head1; M++)
{
Zuobiao1 [0] [m]=x1;//the initial line number
Y=zuobiao1 [1] [m]=+ + temp;//the initial column number
Qipan [x1] [y]='*';
}
Zuobiao1 [0] [head1]=x1;//the initial line number
Y=zuobiao1 [1] [head1]=+ + temp;//the initial column number
Qipan [x1] [y]='#';//the snake

Show_start ();

If (snake==2)
{
Temp=0;
For (int m=tail2; M & lt; Head2; M++)
{
Zuobiao2 [0] [m]=x2;//the initial line number
Y=zuobiao2 [1] [m]=+ + temp;//the initial column number
Qipan [x2] [y]='*';
}
Zuobiao2 [0] [head2]=x2;//the initial line number
Y=zuobiao2 [1] [head2]=+ + temp;//the initial column number
Qipan [x2] [y]='#';//the snake
}

Clock_t start;
Int timeover.
Char direction1=77;//72 88 75 77
Char direction2=68;//87 83 65 68
Char new_direction;
Char new_direction1;
Char new_direction2;

Int gamespeed;
Gotoxy (48, 9);
Color (14);
The scanf (" % d ", & amp; Gamespeed);
Int rand_i=rand () % + 1;
Int rand_j=rand () % 78 + 1;
Qipan [rand_i] [rand_j]='@';

system("cls");
Gotoxy (10, 1);
Color (10);
Printf (" Your present score: ");
Gotoxy (30, 1);
Color (11);
Printf (" % d ", score1);
Gotoxy (0, 4);
for(int i=0; I & lt; 20; I++)//print out the chessboard
For (int j=0; J & lt; 80; J++)
{
If (qipan [I] [j]=='*' | | qipan [I] [j]=='#')
Color (13);
Else if (qipan [I] [j]=='@')
Color (12);
The else
Color (15);
Printf (" % c ", qipan [I] [j]);
}
While (1)//87 83 65 68
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related