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
|
//Library Includes
#include <iostream>
#include <fstream>
//Header Includes
#include "baseUnit.h"
#include "list.h"
#include "leader.h"
#include "object.h"
//#include "mapSquares.h"
//#include "mapList.h"
using namespace std;
//Forward-declare methods.
void NewGame(); //start new game
void Continue(); //continue old game
void save(); //saves data
void gameMenu(); //Main Game Screen
list* addUnit(); //add a unit
list* addUnit(string newName); //add a unit given name
//Global Variables
list* unitsHead; //head of the Unit list
leader* myLeader;
//town* myTown;
int main()
{
char selection='~'; //menu selection character.
while(selection != 'q' && selection != 'Q') //Game Main Menu, until select first option.
{
// display options, take selection
cout << "New Game: N" << endl << "Continue: C (Not Implemented)" << endl << "Quit: Q" << endl;
cin >> selection;
//switch statement for selection
switch(selection)
{
case 'n':
case 'N':
NewGame();
selection = 'q';
break;
case 'c':
case 'C':
Continue();
selection = 'q';
break;
//if none above, break.
default: break;
}
}
return 0;
}
//NOT IMPLEMENTED
void Continue()
{
/*myLeader=new leader("blank");
fstream myFile ("data.bin", ios::in | ios::out | ios::binary);
myFile.seekg (0);
myFile.read ((char*)&myLeader, sizeof (myLeader));
cout << myLeader->getFullName();
return;*/
}
//start a new game, initialize first troops and leader.
void NewGame()
{
cout << "Name your Leader: ";
string myName;
cin >> myName;
myLeader = new leader(myName);
cout << "Name your Town: ";
cin.clear();
string myTown;
cin >> myTown;
//myTown= new town(myTown);
cin.clear();
for(int x=1;x<6;x++)
{
cout << "Name Troop: ";
cin >> myName;
unitsHead=addUnit(myName);
cin.clear();
}
//for(list *unit=unitsHead; unit; unit = unit->next) //parses the list
cout << "Welcome, " << myLeader->getFullName() << endl << "Press ENTER to Continue.";
cin.clear();cin.ignore(255, '\n');cin.get();
save();
gameMenu();
return;
}
//game menu, after data retrieval/creation
void gameMenu()
{
char selection='~'; //menu selection character.
while(selection != 'q' && selection != 'Q')
{
// display options, take selection
cout << "Build: B" << endl << "Gather Resources: G" << endl << "Quit: Q" << endl;
cin >> selection;
//switch statement for selection
/*switch(selection)
{
if none above, break.
default: break;
}*/
}
}
//method to save, partially copied from online tutorial.
void save()
{
fstream myFile ("save.tes", ios::in | ios::out | ios::binary);
if (!myFile.good()) {
cout << "Could not open data.bin for I/O." << endl;
return;
}
myFile.seekp (0);
myFile.write ((char*)&myLeader, sizeof (myLeader));
myFile.close();
}
//adds a new Unit, blank template
list* addUnit()
{
return insert(unitsHead, *(new baseUnit));
}
//adds a new Unit, given Name
list* addUnit(string newName)
{
return insert(unitsHead, *(new baseUnit(newName)));
}
|