Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
4000CEMGameGithub/Source.cpp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
173 lines (161 sloc)
4.34 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Header.h" | |
class MapClass | |
{ | |
public: | |
char Map[25][25]; | |
void initialiseMap() | |
{ | |
for (int x = 0; x < 26; x++) | |
{ | |
for (int y = 0; y < 26; y++) | |
{ | |
Map[x][y] = '.'; | |
} | |
} | |
} | |
void printMap() | |
{ | |
system("CLS"); | |
string alphabet = "abcdefghijklmnopqrstuvwxyz"; | |
for (int y = -1; y < 26; y++) | |
{ | |
for (int x = -1; x < 26; x++) | |
{ | |
if (y == -1) | |
{ | |
if (x == -1) | |
{ | |
cout << " "; | |
} | |
else if (x == 25) | |
{ | |
cout << alphabet[x] << endl; | |
} | |
else { | |
cout << alphabet[x] << " "; | |
} | |
} | |
else if (x == -1) | |
{ | |
if (y + 1 < 10) | |
{ | |
cout << y + 1 << " "; | |
} | |
else | |
{ | |
cout << y + 1; | |
} | |
} | |
else if (x == 25) | |
{ | |
cout << Map[x][y] << " " << endl; | |
} | |
else { | |
cout << Map[x][y] << " "; | |
} | |
} | |
} | |
} | |
void AddBuilding() | |
{ | |
char buildingType; | |
string coordinates; | |
cout << "What type of building would you like to add? "; | |
cin >> buildingType; | |
cout << "At what coordinates would you like to add it? "; | |
cin >> coordinates; | |
string alphabet = "abcdefghijklmnopqrstuvwxyz"; | |
//add validation to this bit | |
int xCoord; | |
int yCoord; | |
char xCoordChar; | |
if (coordinates.length() == 3) | |
{ | |
xCoordChar = coordinates[0]; | |
char yCoord1stChar = coordinates[1]; | |
char yCoord2ndChar = coordinates[2]; | |
int yCoordTemp1 = yCoord1stChar - 48; | |
int yCoordTemp2 = yCoord2ndChar - 48; | |
//cout << yCoordTemp1 << endl; | |
//cout << yCoordTemp2 << endl; | |
yCoord = (yCoordTemp1 * 10) + yCoordTemp2; | |
//cout << yCoord << endl; | |
} | |
else | |
{ | |
xCoordChar = coordinates[0]; | |
char yCoordChar = coordinates[1]; | |
yCoord = yCoordChar - 48; | |
} | |
for (int i = 0; i < 26; i++) | |
{ | |
if (xCoordChar == alphabet[i]) | |
{ | |
xCoord = i; | |
} | |
} | |
//cout << xCoord << ", " << yCoord << endl; | |
Map[xCoord][yCoord - 1] = buildingType; | |
} | |
int searchMap(char buildingType) | |
{ | |
int noOfBulding = 0; | |
for (int x = 1; x < 26; x++) | |
{ | |
for (int y = 1; y < 26; y++) | |
if (Map[x][y] == buildingType) | |
{ | |
if (noOfBulding == 0) | |
{ | |
noOfBulding = 1; | |
} | |
else { | |
noOfBulding++; | |
} | |
} | |
} | |
return noOfBulding; | |
} | |
}; | |
void TempUI(MapClass Map) | |
{ | |
int userIn; | |
cout << "What would you like to do?" << endl; | |
cout << "1. Show Map" << endl; | |
cout << "2. Add a building" << endl; | |
cout << "3. Show how many of a building are present" << endl; | |
cout << "4. Go to Main Screen" << endl; | |
cin >> userIn; | |
switch (userIn) | |
{ | |
case 1: | |
Map.printMap(); | |
break; | |
case 2: | |
Map.AddBuilding(); | |
Map.printMap(); | |
break; | |
case 3: | |
char buildingType; | |
cout << "What building would you like to search for? "; | |
cin >> buildingType; | |
cout << "There are " << Map.searchMap(buildingType) << " of " << buildingType << " on the map." << endl; | |
system("cls"); | |
break; | |
case 4: | |
system("cls"); | |
GameEngine(); | |
default: | |
TempUI(Map); | |
} | |
TempUI(Map); | |
} | |
void Draw() | |
{ | |
MapClass Map; | |
Map.initialiseMap(); | |
TempUI(Map); | |
//Map.printMap(); | |
//Map.AddBuilding(); | |
//Map.printMap(); | |
} |