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
|
#include <iostream>
using namespace std;
string home_town[5][5] = { // BEGIN MAPS < ----
{ "wall", "wall", "wall", "wall", "wall" },
{ "wall", "farm", "dock", "wall", "wall" },
{ "wall", "yard", "wall", "path", "exit" },
{ "wall", "home", "path", "path", "wall" },
{ "wall", "wall", "wall", "wall", "wall" } };
class CHARACTER {//BEGIN CHARACTER CLASS < ----
public:
CHARACTER::CHARACTER();
void setLocation(string map[][5]);
void displayLocation(string map[][5]);
void canMove(string map[][5]);
bool move(string map[][5], string decision);
private:
int xCoord, yCoord;
string currentLocation;
string username;
};
CHARACTER::CHARACTER(){
xCoord = 3;//start location
yCoord = 1;}
void CHARACTER::setLocation(string map[][5]){
currentLocation = map[xCoord][yCoord];}
void CHARACTER::displayLocation(string map[][5]){
cout << currentLocation << endl;}
void CHARACTER::canMove(string map[][5]){
cout << "You can move in the following directions:" << endl;
if (map[xCoord - 1][yCoord] != "wall")
{cout << "North" << endl;}
if (map[xCoord + 1][yCoord] != "wall")
{cout << "South" << endl;}
if (map[xCoord][yCoord + 1] != "wall")
{cout << "East" << endl;}
if (map[xCoord][yCoord - 1] != "wall")
{cout << "West" << endl;} }
bool CHARACTER::move(string map[][5], string decision){
if ( decision == "north" && map[xCoord - 1][yCoord] != "wall" || decision == "North" && map[xCoord - 1][yCoord] != "wall" )
{ xCoord = xCoord - 1; setLocation(map); return true;}
else if ( decision == "south" && map[xCoord +1][yCoord] != "wall" || decision == "South" && map[xCoord +1][yCoord] != "wall" )
{ xCoord = xCoord + 1; setLocation(map); return true; }
else if ( decision == "east" && map[xCoord][yCoord + 1] != "wall" || decision == "East" && map[xCoord][yCoord + 1] != "wall" )
{ yCoord = yCoord + 1; setLocation(map); return true; }
else if ( decision == "west" && map[xCoord][yCoord - 1] != "wall" || decision == "West" && map[xCoord][yCoord - 1] != "wall" )
{ yCoord = yCoord - 1; setLocation(map); return true; }
else { cout << "You can't move in that direction." << endl; return false; }
}
int main() // BEGIN MAIN FUNCTION HERE < ----
{
CHARACTER hero;
system("PAUSE");
return 0;
}
|