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
|
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include "monster.h"
using namespace std;
void createMonster(string weather, string humid, string tide, int count);
int main() {
string weather;
string humid;
string tide;
int count = 0;
ifstream input;
input.open("conditions.txt");
Monster* mon[100];
string line;
while(!input.eof()) {
getline(input,line);
stringstream ss(line);
ss >> weather >> humid >> tide;
void createMonster(string weather, string humid, string tide, int count);
++count;
}
for (int i=0;i<count;i++) { // not sure why this isn't giving any output
mon[i]->attack();
}
}
void createMonster(string weather, string humid, string tide, int count, Monster* mon[100]) {
if (weather=="rainy") {
if (humid=="low") {
if (tide=="low") {
mon[count] = new Cat(weather, humid, tide);
}
else {
mon[count] = new Pidgeon(weather, humid, tide);
}
}
else {
if (tide=="low") {
mon[count] = new Horse(weather, humid, tide);
}
else {
mon[count] = new Rat(weather, humid, tide);
}
}
}
else if(weather=="thunder") {
if (humid=="low") {
if (tide=="low") {
mon[count] = new Dog(weather, humid, tide);
}
else {
mon[count] = new Fish(weather, humid, tide);
}
}
else {
if (tide=="low") {
mon[count] = new Hamster(weather, humid, tide);
}
else {
mon[count] = new Snake(weather, humid, tide);
}
}
}
else if(weather=="shower") {
if (humid=="low") {
if (tide=="low") {
mon[count] = new Tiger(weather, humid, tide);
}
else {
mon[count] = new Goat(weather, humid, tide);
}
}
else {
if (tide=="low") {
mon[count] = new Wolf(weather, humid, tide);
}
else {
mon[count] = new Rabbit(weather, humid, tide);
}
}
}
}
|