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
|
#include <iostream>
#include <limits>
#include <conio.h>
#include <string>
using namespace std;
namespace
{
string board[14] =
{
"################################################################################",
"# #",
"# #",
"# #",
"# #",
"# #",
"# #",
"# #",
"# #",
"# #",
"# #",
"# #",
"# #",
"################################################################################"
};
int curr_x = 1;
int curr_y = 1;
}
void dispboard(int moves);
int main()
{
cout << "Welcome to Duncrawl! Press ENTER to start.\n";
cin.ignore(numeric_limits<streamsize>::max(), '\n');
int moves = 0;
dispboard(moves);
do
{
char c = _getch();
switch (c)
{
case 'w': case 'W':
if(curr_y != 1)
{
(board[curr_y])[curr_x] = ' ';
curr_y--;
dispboard(++moves);
}
break;
case 'a': case 'A':
if(curr_x != 1)
{
(board[curr_y])[curr_x] = ' ';
curr_x--;
dispboard(++moves);
}
break;
case 's': case 'S':
if(curr_y != 12)
{
(board[curr_y])[curr_x] = ' ';
curr_y++;
dispboard(++moves);
}
break;
case 'd': case 'D':
if(curr_x != 78)
{
(board[curr_y])[curr_x] = ' ';
curr_x++;
dispboard(++moves);
}
break;
case 'q': case 'Q':
return 0;
break;
default:
break;
}
}while(true);
}
void dispboard(int moves)
{
(board[curr_y])[curr_x] = '@';
cout << string(100, '\n');
for(int i = 0; i < 14; i++)
cout << board[i];
cout << "Moves: " << moves << endl;
cout << "Up: W\tDown: S\tLeft: A\tRight: D\n";
}
|