/* Creature Feature */
#include <iostream>
#include <iomanip>
#include <algorithm> // for forcing input to lowercase
#include <vector> // for creating/storing dynamic sub-class objects
#include <fstream> // for file read
#include <unistd.h> // for using system commands and invoking delays
#include "balrog.h"
#include "cyberdemon.h"
#include "elf.h"
#include "human.h"
#include "functions.h"
using namespace std;
typedef Creature* CreaturePtr;
void loadPlayers (ifstream& is, vector<CreaturePtr>& GoodGuys,
vector<CreaturePtr>& BadGuys);
void battle (vector<CreaturePtr>& attacks, vector<CreaturePtr>& defends);
// main delegator
int main ()
{
string playerName, fileName, move;
ifstream fileIn;
vector<CreaturePtr> GoodGuys;
vector<CreaturePtr> BadGuys;
title();
cout << setw(37) << "Enter your name: ";
cin >> playerName;
cout << endl;
cout << setw(23) << playerName << ", prepare for battle!\n" << endl;
/*
chooseCharacter();
sleep(5);
system("clear");
*/
cout << "Enter a filename, " << playerName << " the "
<< characterType(playersCharacter) << "... (include .txt)" << endl;
cout << "Filename: ";
cin >> fileName;
while (!validateFileExtension(fileName)) {
cout << "File type is invalid. TXT files only." << endl;
cout << "Enter a filename to open (include .txt), or be slain! : ";
cin >> fileName;
fileIn.open( fileName.c_str() );
}
if (fileIn.fail() ) {
cout << "Failed to open input file." << endl;
cout << "Enter a filename to open (include .txt), or be slain! : ";
cin >> fileName;
fileIn.open( fileName.c_str() );
}
cout << "file opened" << endl; // DELETE ME!!!
loadPlayers (fileIn, GoodGuys, BadGuys);
cin >> move;
fileIn.close();
return (0);
}
void loadPlayers (ifstream& is, vector<CreaturePtr>& GoodGuys,
vector<CreaturePtr>& BadGuys) {
int species, strength, hitpoints;
int count = 0;
string line;
if( is.good() ){
for (int i = 0; i < 4; i++) {
cout << "in good guy while loop... I should read data!" << endl; // DELETE ME!!!
is >> species >> strength >> hitpoints;
cout << species << strength << hitpoints;
// if human type
if(species == 0)
{
cout << "did I make it here? ";
GoodGuys.push_back(new Human(strength, hitpoints));
count ++;
cout << "Good Human " << i << endl;
}
// if cyberdemon type
else if(species == 1)
{
GoodGuys.push_back(new CyberDemon(strength, hitpoints));
count ++;
cout << "Good CyberDemon " << i << endl;
}
// if balrog type
else if(species == 2)
{
GoodGuys.push_back(new Balrog(strength, hitpoints));
count ++;
cout << "Good Balrog " << i << endl;
}
// if elf type
else if(species == 3)
{
GoodGuys.push_back(new Elf(strength, hitpoints));
count ++;
cout << "Good Elf " << i << endl;
}
// if data is invalid
else {
cout << is << " ";
cout << "Error in file. Invalid creature. " << endl;
return;
}// end else
}
if (count >= 4) {
for (int i = 0; i < 4; i++) {
cout << "in bad guy loop... I should read data!" << endl; // DELETE ME!!!
is >> species >> strength >> hitpoints;
if (species > 0) {
cout << "bad species greater than zero" << endl;
}
else {
cout << "Error in file. Invalid creature. " << endl;
return;
}// end else
}
}
}
}