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
|
#include <iostream>
#include <cstdlib>
#include <string>
#include <conio.h>
using namespace std;
char key;
const char character = '|';
const char item = '`';
const int maplength = 10;
const int mapwide = 20;
char gamemap[maplength][mapwide] =
{
{' ','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-',' '},
{'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'},
{'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'},
{'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'},
{'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'},
{'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'},
{'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'},
{'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'},
{'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'},
{' ','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-',' '},
};
void printmap();
void charmove();
bool checkwin();
int main()
{
gamemap[1][1] = item;
gamemap[4][9] = character;
printmap();
charmove();
}
void printmap()
{
system("cls");
int X, Y;
for (X = 0; X < 10; X++)
{
cout << endl;
for (Y = 0; Y < 20; Y++)
{
cout << gamemap[X][Y];
}
}
}
void charmove()
{
bool checkkey;
int x = 4, y = 9;
key = getch();
do
{
if (key = 'w')
{
gamemap[x][y] = ' ';
x--;
gamemap[x][y] = '|';
checkkey = true;
}
else if(key = 's')
{
gamemap[x][y] = ' ';
x++;
gamemap[x][y] = '|';
checkkey = true;
}
else if(key = 'a')
{
gamemap[x][y] = ' ';
y--;
gamemap[x][y] = '|';
checkkey = true;
}
else if(key = 'd')
{
gamemap[x][y] = ' ';
y++;
gamemap[x][y] = '|';
checkkey = true;
}
else
{
checkkey = false;
}
}while (checkkey == false);
printmap();
}
|