Home > Back-end >  0 x00512031 (located in sandanfeiji. Exe) caused by abnormal: 0 xc0000005: when writing position 0 x
0 x00512031 (located in sandanfeiji. Exe) caused by abnormal: 0 xc0000005: when writing position 0 x

Time:11-17

# pragma warning (4996) disable:
#include
#include
#include
#include

15//# define High game screen size
# define Width 25
# define EnemyNum 5//the number of enemy planes

//global variable
Int position_x position_y;//the location of the plane
Int enemy_x [EnemyNum], enemy_y [EnemyNum];//the location of the enemy planes
Int canvas [High] [Width]={0};//corresponding element in the two-dimensional array memory game canvas
//0 for Spaces, 1 * for aircraft, 2 for the bullet |, 3 for the enemy aircraft @
Int score;//score
Int BulletWidth;//the width of the bullets
Int EnemyMoveSpeed;//the enemy's movement speed by

Void HideCursor ()//hide the cursor
{
CONSOLE_CURSOR_INFO cursor_info={1, 0};//the second value of 0 means hide the cursor
SetConsoleCursorInfo (GetStdHandle (STD_OUTPUT_HANDLE), & amp; Cursor_info);
}

Void gotoxy (int x, int y)//move the cursor to position (x, y)
{
HANDLE HANDLE=GetStdHandle (STD_OUTPUT_HANDLE);
COORD pos.
Pos. X=X;
Pos. Y=Y;
SetConsoleCursorPosition (handle, pos);
}

Void startup ()//data initialization
{
Position_x=High - 1;
Position_y=Width/2;
Canvas [position_x] [position_y]=1;
Int k;
For (k=0; k {
Enemy_x [k]=rand () % 2;
Enemy_y [k]=rand () % Width;
Canvas [enemy_x [k]] [enemy_y [k]]=3;
}
Score=0;
BulletWidth=0;
EnemyMoveSpeed=20.
}

Void the show ()//show the picture
{
Gotoxy (0, 0);
int i, j;
for (i=0; i {
For (j=0; J & lt; Width; J++)
{
If (canvas [I] [j]==0)
printf(" ");
Else if (canvas [I] [j]==1)
printf("*");
Else if (canvas [I] [j]==2)
Printf (" | ");
Else if (canvas [I] [j]==3)
Printf (" @ ");
}
printf("\n");
}
Printf (" \ n score: % d ", score).
Sleep (20);
}

Void updateWidthoutInput ()//has nothing to do with the user to enter the updated
{
Int I, j, k;
for (i=0; i {
For (j=0; J & lt; Width; J++)
{
If (canvas [I] [j]==2)
{
For (k=0; k {
If ((I==enemy_x [k]) & amp; & (j==enemy_y [k]))//the bullet hit the enemy
{
Score++;
If (score 5==% 0 & amp; & EnemyMoveSpeed & gt; 3)//reach certain points after the enemy planes faster
EnemyMoveSpeed -;
If (score % 5==0)//reaches a certain integral bullets become ill after
BulletWidth++;
Canvas [enemy_x [k]] [enemy_y [k]]=0;
Enemy_x [k]=rand () % 2;//create new aircraft
Enemy_y [k]=rand () % Width;
Canvas [enemy_x [k]] [enemy_y [k]]=3;
Canvas [I] [j]=0;//the bullet disappear
}
}
//the bullet moving up
Canvas [I] [j]=0;
If (I & gt; 0)
Canvas [I - 1) [j]=2;
}
}
}

Static int speed=0;
If (speed & lt; EnemyMoveSpeed)
Speed++;

For (k=0; k {
If ((position_x==enemy_x [k]) & amp; & (position_y==enemy_y [k]))//enemy planes hit my machine
{
Printf (" failed! \n");
Sleep (3000);
system("pause");
The exit (0);
}

If (enemy_x [k] & gt; High)//by enemy planes flying in and ran out of the display screen
{
Canvas [enemy_x [k]] [enemy_y [k]]=0;
Enemy_x [k]=rand () % 2;//create new aircraft
Enemy_y [k]=rand () % Width;
Canvas [enemy_x [k]] [enemy_y [k]]=3;
Score -;//points
}

If (speed==EnemyMoveSpeed)
{
//the enemy down
For (k=0; k {
Canvas [enemy_x [k]] [enemy_y [k]]=0;
Enemy_x [k] + +;
Speed=0;
Canvas [enemy_x [k]] [enemy_y [k]]=3;
}

}
}
}

Void updateWithInput ()//associated with the user to enter the update
{
Char input;
If (kbhit ())//judge whether to have input
{
Input=getch ();//depending on the user input to move, don't need to input the enter
If (input=='a' & amp; & Position_y & gt; 0)
{
Canvas [position_x] [position_y]=0;
Position_y -;//position left
Canvas [position_x] [position_y]=1;
}
Else if (input=='d' & amp; & Position_y & lt; Width - 1)
{
Canvas [position_x] [position_y]=0;
Position_y + +;//position moves to the right
Canvas [position_x] [position_y]=1;
}
Else if (input=='w')
{
Canvas [position_x] [position_y]=0;
Position_x -;//position up
Canvas [position_x] [position_y]=1;
}
Else if (input=='a' & amp; & Position_y & gt; 0)
{
Canvas [position_x] [position_y]=0;
Position_x + +;//position down
Canvas [position_x] [position_y]=1;
}
Else if (input==' ')//shoot
{
Int left=position_y - BulletWidth;
Int right=position_y + BulletWidth;
If (left & lt; 0)
Left=0;
If (right & gt; Width - 1)
Right=Width - 1;
Int k;
For (k=left; k <=right; K + +)//shoot
Canvas [position_x - 1] [k]=2;//launch bullet initial position in the plane of the above
}
}
}

Int main ()
{
HideCursor ();
Startup ();//data initialization
While (1)//game loop execution
{
Show ();//display picture
UpdateWidthoutInput ();//has nothing to do with the user to enter the update
UpdateWithInput ();//associated with the user to enter the updated
}

return 0;
}

CodePudding user response:

nullnullnullnullnullnullnull
  • Related