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
|
#include <iostream>
#include <string>
using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::getline;
char keyPressed;
bool inGame = true;
void retrieveAction();
void retrieveAction(char menu);
void processAction();
void openJournal();
const int wmx = 10;
const int wmy = 10;
string worldMap[wmy][wmx] = {
{ "Yesteryear", "Graveyard", "Golden Palace", "Yarven's Lake", "Helms Peak", "Wasteland", "Dragonstone", "Troll Cave", "Murky Cavern", "Blackwater" },
{ "", "", "", "", "", "", "", "", "", "" },
{ "", "", "", "", "", "", "", "", "", "" },
{ "", "", "", "", "", "", "", "", "", "" },
{ "", "", "", "", "", "", "", "", "", "" },
{ "", "", "", "", "", "", "", "", "", "" },
{ "", "", "", "", "", "", "", "", "", "" },
{ "", "", "", "", "", "", "", "", "", "" },
{ "", "", "", "", "", "", "", "", "", "" },
{ "", "", "", "", "", "", "", "", "", "" }
};
struct playerOne
{
string heroName;
string heroClass;
int heroX;
int heroY;
string heroLocation()
{
return worldMap[heroY][heroX];
}
bool canMove(int nHeroX, int nHeroY)
{
if((nHeroX < 0 || nHeroX >= wmx) && (nHeroY < 0 || nHeroY >= wmy))
{
return false;
}
return true;
}
}plr;
void createPlayer();
int main()
{
createPlayer();
while(inGame)
{
retrieveAction();
processAction();
}
return 0;
}
void retrieveAction()
{
cout << "$> ";
cin >> keyPressed;
}
void retrieveAction(char menu)
{
switch(menu)
{
case 'j':
cout << "$>Journal> ";
cin >> keyPressed;
cin.ignore();
// processJournalAction()
return;
default: cout << "\nNo action found\n" << endl;
}
}
void processAction()
{
char *action;
action = &keyPressed;
switch(*action)
{
case 'w':
if(plr.canMove(plr.heroX, plr.heroY + 1))
{
plr.heroY++;
}
else
{
cout << "\nIt would be unwise to travel into the wilderness." << endl;
}
return;// move north
case 's':
if(plr.canMove(plr.heroX, plr.heroY - 1))
{
plr.heroY--;
}
else
{
cout << "\nIt would be unwise to travel into the wilderness." << endl;
}
return;// move south
case 'a':
if(plr.canMove(plr.heroX - 1, plr.heroY))
{
plr.heroX--;
}
else
{
cout << "\nIt would be unwise to travel into the wilderness." << endl;
}
return;// move west
case 'd':
if(plr.canMove(plr.heroX + 1, plr.heroY))
{
plr.heroX++;
}
else
{
cout << "\nIt would be unwise to travel into the wilderness." << endl;
}
return;// move east
case 'j':
openJournal();
while(*action != 'x')
{
retrieveAction(keyPressed);
}
return;
default: cout << "\nNo action found\n" << endl;
}
}
void openJournal()
{
cout << "\n[Player] " << plr.heroName << "\t[Class] " << plr.heroClass << "\t[Location] " << plr.heroLocation() << endl;
}
void createPlayer()
{
cout << "Welcome to Rogue." << endl;
cout << "Great adventures await..." << endl;
cout << "\nWhat is your name? ";
getline(cin, plr.heroName);
plr.heroX = 0;
plr.heroY = 0;
}
|