Repository navigation
Expand file tree
/
Copy pathReadInputFile.h
More file actions
80 lines (70 loc) · 2.22 KB
/
Copy pathReadInputFile.h
File metadata and controls
80 lines (70 loc) · 2.22 KB
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
#pragma once
#include<iostream>
#include<fstream>
#include"Castle/Castle.h"
#include"Battle.h"
#include"./Enemies/Enemy.h"
#include"./Enemies/Fighter.h"
#include"./Enemies/Freezer.h"
#include"./Enemies/Healer.h"
using namespace std;
void ReadInputFile(string filename, Queue<Enemy*> &Q_Inactive, Castle &BCastle)
{
fstream inputFile("D:\\Study\\Summer21\\Data Structure\\testfile.txt"); // read data from the file
if (inputFile.is_open()) // checking if the file has been opened or not
{
cout << "The input file has been opened successfully!" << endl;
}
else
{
cout << "Error! the input file cannot be opened successfully!" << endl;
}
int CH, N, CP; // CH stands for castle health, N stands for number of enemies the castle could attack at each time step, CP stands for castle power
inputFile >> CH >> N >> CP;
cout << "CASTLE HEALTH IS " << CH << " " << "N is " << N << " " << "CASTLE POWER is " << CP << endl; // print Castle Data on the conselo
BCastle.SetHealth(CH);
BCastle.SetNumberOfEnemies(N);
BCastle.SetPower(CP);
cout << BCastle.GetHealth() << "HIIII" << BCastle.GetNumberOfEnemies() << " " << BCastle.GetPower() << endl;
int M; // M stands for number of enemies
inputFile >> M;
cout << M << " ";
int ID, TYP, AT, H, POW, RLD, SPD; // stands for Enemy ID
Enemy* pE = NULL;
for (int i = 0; i < M; i++)
{
while (!inputFile.eof())
{
inputFile >> ID;
cout << "ID" << " " << ID << endl;
inputFile >> TYP;
cout << "TYP" << " " << TYP << endl;
inputFile >> AT;
cout << "AT" << " " << AT << endl;
if(TYP == 0){
pE = new Fighter(ID, AT);
}else if(TYP == 1){
pE = new Healer(ID, AT);
}else if(TYP == 2){
pE = new Freezer(ID, AT);
}
inputFile >> H;
pE->SetHealth(H);
cout << "H" << " " << H << endl;
inputFile >> POW;
pE->SetPower(POW);
cout << "POW" << " " << POW << endl;
inputFile >> RLD;
pE->SetReloadPeriod(RLD);
cout << "RLD" << " " << RLD << endl;
inputFile >> SPD;
pE->SetSpeed(SPD);
cout << "SPD" << " " << SPD << endl;
pE->SetStatus(INAC); //initiall all enemies are inactive
Q_Inactive.enqueue(pE);
if (inputFile.eof()) break;
}
}
inputFile.close();
cout << "Closed!" << endl;
}