Home > Back-end >  [C] [the war] the cursor does not move
[C] [the war] the cursor does not move

Time:11-02

As title, enemy planes flying in and out to test the $character in never falling
 
# include
# include
# include
Int position_x position_y;//the plane position
Int wide, high;//area
Int enemy_x enemy_y;//the enemy position
Int victor.
Void HideCusor ()//hide the cursor
{
CONSOLE_CURSOR_INFO cursor_info={1, 0};//value is 0, the second said to hide the cursor
SetConsoleCursorInfo (GetStdHandle (STD_OUTPUT_HANDLE), & amp; Cursor_info);
}
Void gotoxy (int x, int y)//the cursor
{
HANDLE HANDLE=GetStdHandle (STD_OUTPUT_HANDLE);
COORD pos.
Pos. X=X;
Pos. Y=Y;
SetConsoleCursorPosition (handle, pos);
}
Void startup initialization ()//
{
Wide=30;
High=20;
Position_x=wide/2;
Position_y=high - 3;
Enemy_x=5;
Enemy_y=0;
Victor=1;
HideCusor ();
}
Void the show ()
//functions: display the game interface
{
Gotoxy (0, 0);//the cursor to the origin
int i, j;//row count and column count
for (i=0; I & lt; High; I++)
{
For (j=0; J & lt; wide; J++)
{
If ((I==position_y) & amp; & (j==position_x))//plane
Printf (" * ");
Else if ((I==enemy_y) & amp; & (j)==enemy_x)//enemy planes
Printf (" $");
The else
Printf (" ");
If ((enemy_x==position_x) & amp; & (enemy_y==position_y))//judge the outcome
{
Enemy_y=1;
Victor=0;
}

}
printf("\n");
}

}
Void UpdateWithoutInput ()
{
//function: control the enemy move

Static int speed;//slow the progress of the $down
Srand ((unsigned) time (NULL));
If (speed & lt; 100)
Speed 20 +=rand () % 100;
If (speed==100)
{
If (enemy_y & gt; High)
{
Enemy_x=rand () % of 31;
Enemy_y=0;
}
The else
{
Enemy_y + +;
Speed=0;
}
}
}
Void UpdateWithInput ()
//function: through the button control their movements
{
Char input;
If (_kbhit ())
{
Input=_getch ();//enter
If (input=='w')
Position_y -;
If (input=='s')
Position_y + +;
If (input=='a')
Position_x -;
If (input=='d')
Position_x + +;

}
}
Int main ()
{
Printf (" ready to start? \n");
Char ready=_getch ();
If (ready=='y') {
Startup ();
While (victor)
{
Show ();
UpdateWithoutInput ();
UpdateWithInput ();
}
Printf (" GAME OVER! \ nhaha \ n ");

}
Printf (" game over ");
return 0;
}
  • Related