-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFileInput.cpp
More file actions
92 lines (73 loc) · 1.56 KB
/
FileInput.cpp
File metadata and controls
92 lines (73 loc) · 1.56 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
81
82
83
84
85
86
87
88
89
90
91
92
#include "stdafx.h"
#include "FileInput.h"
#include <fstream>
#include <sstream>
#include <string>
#include "Game.h"
FileInput::FileInput()
{}
FileInput::~FileInput()
{}
//
const Info& FileInput::GetInfo()
{
//If file is for some reason not open
if (!File)
{
Game::Error("File not open");
return m_info;
}
//temporary variables to hold input from file
std::string object;
float x, y;
//Load background name
File >> m_info.backgroundFilename;
#ifdef DEBUG
std::cout << m_info.backgroundFilename << std::endl;
#endif
//while file is not finished
while (!File.eof())
{
//Enter info into temp variables
File >> object;
File >> x;
File >> y;
#ifdef DEBUG
std::cout << object << std::endl;
std::cout << x << std::endl << y << std::endl;
#endif
//Add information to info object
m_info.m_object.push_back(object);
m_info.m_x.push_back(x);
m_info.m_y.push_back(y);
}
return m_info;
}
//Initialize the File with correct room
bool FileInput::SetRoom(int roomNumber)
{
//change roomNumber to string
std::stringstream ss;
ss << roomNumber;
std::string m_room = "room" + ss.str();
//Open correct Room file
File.open("RoomSetup/" + m_room + ".txt");
//Ensure that it opened
if (!File)
{
Game::Error("File could not be opened");
}
return true;
}
//Close file and prepare info object to be reused
void FileInput::Close()
{
File.close();
m_info.m_object.clear();
m_info.m_x.clear();
m_info.m_y.clear();
}
//Info object returned in GetInfo()
Info FileInput::m_info;
//File to be read --> Opened in SetRoom()
std::ifstream FileInput::File;