Home > Back-end >  C snake mailbox console error
C snake mailbox console error

Time:01-19

Console of the snake is such a * * * * @ the right, move up and down or so will appear, such as words,

This is what? For a great god,







CodePudding user response:

No code, don't know how you wrote it

CodePudding user response:

Garbled words can also have other reasons to
In the up and down or so can be to you like this

CodePudding user response:

#include
#include
#include

60//# define MAP_WIDTH average width
The average height 20//# define MAP_HEIGHT

Struct snake
{
//coordinates x
Int x;

//y
Int y;

//@ or *
Char ch;
};
//array structure: on behalf of the snake
Struct snake g_snake [MAP_WIDTH * MAP_HEIGHT];
//the length of the snake actual
Int g_snake_length=5;
Void SetPos (int x, int y)
{

COORD point={x, y};//the location of the cursor to set up the x, y
HANDLE HOutput=GetStdHandle (STD_OUTPUT_HANDLE);//use the GetStdHandle (STD_OUTPUT_HANDLE) to obtain a handle to the standard output
SetConsoleCursorPosition (HOutput, point);//set the cursor position
}

Void DrawSnake ()
{
int i=0;
For (I=0; I & lt; G_snake_length; I++)
{
//set the coordinates to (0, 0)
SetPos (g_snake [I]. X, g_snake [I] y);

//draw the snake * * * *
Printf (" % c ", g_snake [I] ch);
}


}

Void HideCorsor ()

{

HANDLE fd=GetStdHandle (STD_OUTPUT_HANDLE);

CONSOLE_CURSOR_INFO cinfo;

Cinfo. BVisible=0;

Cinfo. DwSize=1;

If (SetConsoleCursorInfo (fd, & amp; Cinfo))

Printf (" execution success \ n ");

The else

Failed to perform printf (" \ n ");



}
Int main ()
{
//hide the cursor
HideCorsor ();
Int I, j;
//[0, 25)
For (j=0; J & lt; MAP_HEIGHT + 1; J++)
{
If (j==MAP_HEIGHT)
{
//to draw a line
For (I=0; I & lt; MAP_WIDTH; I++)
{
Printf (" - ");
}
printf("\n");

}
The else
{//drawing blank lines
For (I=0; I & lt; MAP_WIDTH; I++)
{
Printf (" ");
}
Printf (" | ");
printf("\n");
}

}
G_snake_length=5;

G_snake [0]. X=0;
G_snake [0]. Y=0;
G_snake [0]. Ch='*';

G_snake [1]. X=1;
G_snake [1]. The y=0;
G_snake [1]. Ch='*';

G_snake [2]. X=2;
G_snake [2]. The y=0;
G_snake [2]. Ch='*';

G_snake [3]. X=3;
G_snake [3]. The y=0;
G_snake [3]. Ch='*';

G_snake [4]. X=4;
G_snake [4]. The y=0;
G_snake [4]. Ch='@';

//draw the snake * * * *
DrawSnake ();

While (1)
{
Int tail_x=g_snake [0]. X;
Int tail_y=g_snake [0]. Y;
//to the right one
//(0, 0), (1, 0), (2, 0), (3, 0), (4, 0) @
//(1, 0), (2, 0), (3, 0), (4, 0), (5, 0) @

//[0, 5)
For (I=0; I & lt; G_snake_length - 1; I++)
{
G_snake [I]. X=g_snake [I + 1] x;
G_snake [I] y=g_snake [I + 1] y;
}
Int key=_getch ();
The switch (key)
{
The case 'w' ://
Printf (" on ");
G_snake [g_snake_length - 1]. - y=1;
break;

Case 'a' ://port
Printf (" left ");
G_snake [g_snake_length - 1]. X=1;
break;

Under the case 's' ://
Printf (" ");
G_snake [g_snake_length - 1]. + y=1;
break;

Case 'd' ://right
Printf (" right ");
G_snake [g_snake_length - 1]. X +=1;
break;
}
//remove the tail coordinate
SetPos (tail_x tail_y);
Putchar (");


//draw the snake * * * *
DrawSnake ();


}




return 0;
}

CodePudding user response:

Please refer to the "VS2015 snake code analysis (10-1)"
Wish I could help you!
  • Related