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 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
|
#include <fstream>
#include <iostream>
#include <cctype>
#include "map.h"
map::map(std::string text_file)
{
std::ifstream load_map;
load_map.open( text_file.c_str() );
for ( int x = 0; x < height; x++ )
{
for ( int y = 0; y < width; y++ )
{
load_map >> gameMap[x][y];
}
}
load_map.close();
xCoord = 1;
yCoord = 2;
currentLocation = gameMap[xCoord][yCoord];
vehicleBoat = false;
}
void map::goNorth()
{
if ( gameMap[xCoord - 1][yCoord] != "WALL" && gameMap[xCoord - 1][yCoord] != "LAKE" )
{
xCoord--;
lastLocation = currentLocation;
currentLocation = gameMap[xCoord][yCoord];
}
else if ( gameMap[xCoord - 1][yCoord] == "WALL" )
{
std::cout << "I shouldn't venture in that direction." << std::endl;
}
else if ( gameMap[xCoord - 1][yCoord] == "LAKE" && vehicleBoat == false )
{
std::cout << "I should find a boat if I want to venture out into the enormous lake." << std::endl;
}
else if ( gameMap[xCoord - 1][yCoord] == "LAKE" && vehicleBoat == true )
{
xCoord--;
}
}
void map::goSouth()
{
if ( gameMap[xCoord + 1][yCoord] != "WALL" && gameMap[xCoord + 1][yCoord] != "LAKE" )
{
xCoord++;
lastLocation = currentLocation;
currentLocation = gameMap[xCoord][yCoord];
}
else if ( gameMap[xCoord + 1][yCoord] == "WALL" )
{
std::cout << "I shouldn't venture in that direction." << std::endl;
}
else if ( gameMap[xCoord + 1][yCoord] == "LAKE" && vehicleBoat == false )
{
std::cout << "I should find a boat if I want to venture out into the enormous lake." << std::endl;
}
else if ( gameMap[xCoord + 1][yCoord] == "LAKE" && vehicleBoat == false )
{
xCoord++;
}
}
void map::goEast()
{
if ( gameMap[xCoord][yCoord + 1] != "WALL" && gameMap[xCoord][yCoord + 1] != "LAKE" )
{
yCoord++;
lastLocation = currentLocation;
currentLocation = gameMap[xCoord][yCoord];
}
else if ( gameMap[xCoord][yCoord + 1] == "WALL" )
{
std::cout << "I shouldn't venture in that direction." << std::endl;
}
else if ( gameMap[xCoord][yCoord + 1] == "LAKE" && vehicleBoat == false )
{
std::cout << "I should find a boat if I want to venture out into the enormous lake." << std::endl;
}
else if ( gameMap[xCoord][yCoord + 1] == "LAKE" && vehicleBoat == true )
{
yCoord++;
}
}
void map::goWest()
{
if ( gameMap[xCoord][yCoord - 1] != "WALL" && gameMap[xCoord][yCoord - 1] != "LAKE" )
{
yCoord--;
lastLocation = currentLocation;
currentLocation = gameMap[xCoord][yCoord];
}
else if ( gameMap[xCoord][yCoord - 1] == "WALL" )
{
std::cout << "I shouldn't venture in that direction." << std::endl;
}
else if ( gameMap[xCoord][yCoord - 1] == "LAKE" && vehicleBoat == false )
{
std::cout << "I should find a boat if I want to venture out into the enormous lake." << std::endl;
}
else if ( gameMap[xCoord][yCoord - 1] == "LAKE" && vehicleBoat == true )
{
yCoord--;
}
}
void map::getMove()
{
std::string userInput = " ";
std::cout << std::endl;
std::cout << "What would you like to do?" << std::endl;
getline(std::cin, userInput);
for ( unsigned int i = 0; i < userInput.length(); i++ )
{
userInput[i] = tolower(userInput[i]);
}
checkCommand(userInput);
}
void map::checkCommand(std::string command)
{
if ( command == "north" || command == "go north" || command == "move north" )
{
goNorth();
}
else if ( command == "south" || command == "go south" || command == "move south" )
{
goSouth();
}
else if ( command == "east" || command == "go east" || command == "move east" )
{
goEast();
}
else if ( command == "west" || command == "go west" || command == "move west" )
{
goWest();
}
else if ( command == "commands" )
{
displayCommands();
}
else
{
std::cout << "'" << command << "' is not a recognized command, for a available list of commands, type 'commands'." << std::endl;
}
}
void map::displayCommands()
{
std::cout << std::endl;
std::cout << "When accessing some commands, for instance, south, you may use 'go south' or 'move south', or just 'south'." << std::endl;
std::cout << "---List of Commands---" << std::endl << std::endl;
std::cout << "North, South, East, or West" << std::endl;
std::cout << "Grab <item>, get <item>." << std::endl;
std::cout << "Examine, look around, and talk to." << std::endl;
}
void map::displayAreaDescription()
{
std::ifstream load_description;
load_description.open("description.txt");
std::string description;
std::string search = currentLocation;
while (!load_description.eof() )
{
getline(load_description, description);
if ( description.find(search) != std::string::npos )
{
std::cout << description;
}
load_description.close();
}
}
void map::display()
{
for ( int x = 0; x < height; x++ )
{
for ( int y = 0; y < width; y ++ )
{
std::cout << gameMap[x][y] << " ";
}
std::cout << std::endl;
}
}
|