66#include " player.hpp"
77#include " tile.hpp"
88
9- inline void importFile (std::vector<eintrag> *vec ) {
9+ inline void importFile (std::vector<tile>& tiles ) {
1010 std::ifstream csv;
11- csv.open (" Telefonbuch .csv" );
11+ csv.open (" Tiles .csv" );
1212 std::string line;
1313 const std::string del = " ;" ;
1414
1515 while (std::getline (csv, line)){
16- eintrag s;
16+ tile s;
1717 std::size_t pos = 0 ;
1818 std::size_t start = 0 ;
19+
20+ pos = line.find (del,start);
21+ s.tileIndex = std::stoi (line.substr (start, pos-start));
22+ start = pos + del.length ();
23+
24+ pos = line.find (del,start);
25+ s.ownerId = std::stoi (line.substr (start, pos-start));
26+ start = pos + del.length ();
27+
28+ pos = line.find (del,start);
29+ s.buyable = line.substr (start, pos-start) == " true" ;
30+ start = pos + del.length ();
31+
32+ pos = line.find (del,start);
33+ s.buyPrice = std::stoi (line.substr (start, pos-start));
34+ start = pos + del.length ();
35+
36+ pos = line.find (del,start);
37+ s.isMortgaged = line.substr (start, pos-start) == " true" ;
38+ start = pos + del.length ();
39+
40+ pos = line.find (del,start);
41+ s.housePrice = std::stoi (line.substr (start, pos-start));
42+ start = pos + del.length ();
43+
44+ pos = line.find (del,start);
45+ s.upgradeStage = std::stoi (line.substr (start, pos-start));
46+ start = pos + del.length ();
47+
48+ pos = line.find (del,start);
49+ s.price0 = std::stoi (line.substr (start, pos-start));
50+ start = pos + del.length ();
51+
52+ pos = line.find (del,start);
53+ s.price1 = std::stoi (line.substr (start, pos-start));
54+ start = pos + del.length ();
55+
56+ pos = line.find (del,start);
57+ s.price2 = std::stoi (line.substr (start, pos-start));
58+ start = pos + del.length ();
59+
60+ pos = line.find (del,start);
61+ s.price3 = std::stoi (line.substr (start, pos-start));
62+ start = pos + del.length ();
63+
64+ pos = line.find (del,start);
65+ s.price4 = std::stoi (line.substr (start, pos-start));
66+ start = pos + del.length ();
67+
68+ pos = line.find (del,start);
69+ s.price5 = std::stoi (line.substr (start, pos-start));
70+ start = pos + del.length ();
71+
72+ pos = line.find (del,start);
73+ std::string colorStr = line.substr (start, pos-start);
74+ s.color = stringColorGroupMatcher (colorStr);
75+ start = pos + del.length ();
76+
77+ pos = line.find (del,start);
78+ s.tileName = line.substr (start, pos-start);
79+ start = pos + del.length ();
80+
81+ s.shortName = line.substr (start);
82+
83+ tiles.push_back (s);
84+ }
85+ csv.close ();
86+ }
87+
88+ inline void importFile (std::vector<player>& players) {
89+ std::ifstream csv;
90+ csv.open (" Players.csv" );
91+ std::ifstream ownedStreetsFile;
92+ ownedStreetsFile.open (" OwnedStreets.csv" );
93+ std::string line;
94+ const std::string del = " ;" ;
95+
96+ while (std::getline (csv, line)){
97+ player s;
98+ std::size_t pos = 0 ;
99+ std::size_t start = 0 ;
100+
101+ pos = line.find (del,start);
102+ s.playerId = std::stoi (line.substr (start, pos-start));
103+ start = pos + del.length ();
104+
105+ pos = line.find (del,start);
106+ s.symbol = line.substr (start, pos-start);
107+ start = pos + del.length ();
108+
109+ pos = line.find (del,start);
110+ s.name = line.substr (start, pos-start);
111+ start = pos + del.length ();
112+
113+ pos = line.find (del,start);
114+ s.money = std::stoi (line.substr (start, pos-start));
115+ start = pos + del.length ();
116+
117+ pos = line.find (del,start);
118+ s.currentPosition = std::stoi (line.substr (start, pos-start));
119+ start = pos + del.length ();
120+
121+ pos = line.find (del,start);
122+ s.jailed = line.substr (start, pos-start) == " true" ;
123+ start = pos + del.length ();
124+
125+ pos = line.find (del,start);
126+ std::string colorStr = line.substr (start, pos-start);
127+ s.color = stringColorGroupMatcher (colorStr);
128+ start = pos + del.length ();
19129
20130 pos = line.find (del,start);
21- s.nachname = line.substr (start, pos-start);
131+ s.jailCounter = std::stoi ( line.substr (start, pos-start) );
22132 start = pos + del.length ();
23133
24134 pos = line.find (del,start);
25- s.vorname = line.substr (start, pos-start);
135+ s.jailFreeCard = std::stoi ( line.substr (start, pos-start) );
26136 start = pos + del.length ();
27137
28- s.telefonnummer = std::stoll (line.substr (start));
138+ s.bankrupt = line.substr (start, pos-start) == " true" ;
139+
140+ players.push_back (s);
141+ }
142+ csv.close ();
143+
144+ while (std::getline (ownedStreetsFile, line)){
145+ int playerId;
146+ int tileId;
147+ std::size_t pos = 0 ;
148+ std::size_t start = 0 ;
149+
150+ pos = line.find (del,start);
151+ playerId = std::stoi (line.substr (start, pos-start));
152+ start = pos + del.length ();
153+
154+ tileId = std::stoi (line.substr (start, pos-start));
155+
156+ for (auto & player : players) {
157+ if (player.playerId == playerId) {
158+ player.ownedStreets .push_back (tileId);
159+ break ;
160+ }
161+ }
162+ }
163+ ownedStreetsFile.close ();
164+ }
165+
166+ inline void importFile (int freeParkingMoney, int currentPlayerTurn, std::vector<std::size_t >& turnOrder) {
167+ std::ifstream csv;
168+ csv.open (" otherData.csv" );
169+ std::string line;
170+ const std::string del = " ;" ;
171+
172+ if (std::getline (csv, line)) {
173+ freeParkingMoney = std::stoi (line);
174+ }
175+
176+ if (std::getline (csv, line)) {
177+ currentPlayerTurn = std::stoi (line);
178+ }
179+
180+ while (std::getline (csv, line)){
181+ int s;
182+ std::size_t pos = 0 ;
183+ std::size_t start = 0 ;
184+
185+ pos = line.find (del,start);
186+ s = std::stoi (line.substr (start, pos-start));
187+ start = pos + del.length ();
29188
30- vec-> push_back (s);
189+ turnOrder. push_back (s);
31190 }
32191 csv.close ();
33192}
0 commit comments