#include
#include
#include
char bg[25][80];
int playerX;
int playerY;
bool fire;
int bulletX;
int bulletY;
void PrintfScreen(void);
void ClearScreen(void);
void GameMain(void);
void KeyControl(void);
void BulletDraw(void);
void PlayerDraw(void);
void main(void)
{
playerX = 0;
playerY = 12;
fire = false;
for(;;)
{
ClearScreen();
GameMain();
PrintfScreen();
}
}
void PrintfScreen(void)
{
bg[24][79] = 0;
printf("%s",bg);
}
void ClearScreen(void)
{
system("cls");
for(int y = 0; y< 25; y++)
{
for(int x = 0; x<80;x++)
{
bg[y][x] = ' ';
}
}
}
void GameMain(void)
{
KeyControl();
BulletDraw();
PlayerDraw();
}
void KeyControl(void)
{
char pressKey;
if(kbhit())
{
pressKey = getch();
switch(pressKey)
{
case 72:
playerY--;
if(playerY < 1)
playerY = 1;
break;
case 75:
playerX--;
if(playerX < 0)
playerX = 0;
break;
case 77:
playerX++;
if(playerX > 75)
playerX = 75;
break;
case 80:
playerY++;
if(playerY > 23)
playerY = 23;
break;
case 32:
if(fire == false)
{
fire = true;
bulletX = playerX + 5;
bulletY = playerY;
}
break;
}
}
}
void BulletDraw(void)
{
if(fire != true)
{
return;
}
bg[bulletY][bulletX - 1] = '-';
bg[bulletY][bulletX + 0] = '>';
bulletX++;
if(bulletX > 79)
{
fire = false;
}
}
void PlayerDraw(void)
{
bg[playerY - 1][playerX + 0] = '-';
bg[playerY - 1][playerX + 1] = '>';
bg[playerY + 0][playerX + 1] = '>';
bg[playerY - 0][playerX + 2] = '>';
bg[playerY - 0][playerX + 3] = '>';
bg[playerY + 1][playerX + 0] = '-';
bg[playerY + 1][playerX + 1] = '>';
}