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
|
#include <iostream>
#include <string>
#include <vector>
using namespace std;
void DrawMap(int rows, int columns, char mapChar, vector<vector<char> > gameMap, char player, int plrPosX, int plrPosY);
void InputMovement(int& plrPosX, int& plrPosY, int& direction);
void GameDetails(string& gameName);
int main()
{
const int rows = 10;
const int columns = 20;
int plrPosX = 3, plrPosY = 3;
char mapChar = '.';
char player = '#';
int direction = 0;
//char g_map[rows][columns];
vector<vector<char> > gameMap(rows, vector<char>(rows));
bool loopEnd = false;
DrawMap(rows, columns, mapChar, gameMap, player, plrPosX, plrPosY);
while(!loopEnd)
{
cout << "\nWhich direction would you like to go?" << endl;
cout << "1) Up" << endl;
cout << "2) Down" << endl;
cout << "3) Left" << endl;
cout << "4) Right" << endl;
cout << ">";
cin >> direction;
InputMovement(plrPosX, plrPosY, direction);
DrawMap(rows, columns, mapChar, gameMap, player, plrPosX, plrPosY);
}
return 0;
}
void DrawMap(int rows, int columns, char mapChar, vector<vector<char> > gameMap, char player, int plrPosX, int plrPosY)
{
for(int r = 0; r < rows; r++)
{
for(int c = 0; c < columns; c++)
{
gameMap[r][c] = mapChar;
gameMap[plrPosX][plrPosY] = player;
cout << gameMap[r][c];
}
cout << endl;
}
}
void InputMovement(int& plrPosX, int& plrPosY, int& direction)
{
if(direction == 1)
{
plrPosX -= 1;
}
if(direction == 2)
{
plrPosX += 1;
}
if(direction == 3)
{
plrPosY -= 1;
}
if(direction == 4)
{
plrPosY += 1;
}
}
//Dev use only. Used to create maps in the game world.
void MapCreator()
{
}
void GameDetails(string& gameName)
{
cout << "Enter a name for your game(Can be changed later)" << endl;
getline(cin, gameName);
}
void MapDetails()
{
}
|