1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
#include <iostream>
#include <stdio.h>
#include "windows.h"
using namespace std;
const int mapx = 40;
const int mapy = 20;
char map[mapy][mapx] ={"#######################################",
"# #",
"# #",
"# #",
"# #",
"# #",
"# #",
"# #",
"# #",
"# #",
"# #",
"# #",
"# #",
"# #",
"# #",
"# #",
"# X #",
"# #",
"#######################################"};
struct pos
{
int x;
int y;
}
pos char_pos{19,16};
pos projectile_pos{-1,-1}; // Does not occur
bool game_running = true;
char KeyCommandsFunction()
{
if (GetAsyncKeyState(VK_DOWN))
{
char y2 = y + 1;
if (map[y2][x] == ' ') //If the space is empty in the array
{
map[y][x] = ' ';
y++;
map [y][x] = 'X';
}
}
if (GetAsyncKeyState(VK_UP))
{
int y2 = y - 1;
if (map[y2][x] == ' ') //If the space is empty in the array
{
map[y][x] = ' ';
y--;
map [y][x] = 'X';
}
}
if (GetAsyncKeyState(VK_LEFT))
{
int x2 = x - 1;
if (map[y][x2] == ' ') //If the space is empty in the array
{
map[y][x] = ' ';
x--;
map [y][x] = 'X';
}
}
if (GetAsyncKeyState(VK_RIGHT))
{
int x2 = x + 1;
if (map[y][x2] == ' ') //If the space is empty in the array
{
map[y][x] = ' ';
x++;
map [y][x] = 'X';
}
}
if (GetAsyncKeyState(VK_SPACE))
{
for (int i = 0; i < 20; i++)
{
if (map[i][x] == ' ') //If the space is empty in the array
{
map[y][x] = ' ';
y--;
map [y][x] = '|';
}
}
}
if (GetAsyncKeyState(VK_ESCAPE))
{
game_running = false;
}
}
int GameFunction()
{
while (game_running == true) //This loop is the game.
{
system("cls");
for(int display = 0; display < 20; display++)
{
cout << map[display] << endl;
}
system("pause > null"); //display nothing when it's paused.
KeyCommandsFunction();
}
}
int main()
{
GameFunction();
KeyCommandsFunction();
system("cls");
cout << "Game Over." << endl;
}
|