forked from navyamehta/enhancedgamedev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlevel0.cc
60 lines (58 loc) · 1008 Bytes
/
level0.cc
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
#include "level.h"
#include "level0.h"
#include "piece.h"
#include "pieceI.h"
#include "pieceO.h"
#include "pieceT.h"
#include "pieceS.h"
#include "pieceZ.h"
#include "pieceJ.h"
#include "pieceL.h"
#include "cell.h"
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
using namespace std;
LevelZero::LevelZero(string s) {
pos = 0;
fl = s;
ifstream file1{s};
len = 0;
string p;
while (file1 >> p) { ++len; }
}
Piece* LevelZero::nextPiece(vector<vector<unique_ptr<Cell>>> &t) {
string piece;
ifstream file1{fl};
for (int i=0; i<=pos; i++) {
file1 >> piece;
}
++pos;
if (pos==len) {
pos = 0;
}
Piece *pc = nullptr;
if (piece=="I") {
pc = new PieceI(t);
}
else if (piece=="O") {
pc = new PieceO(t);
}
else if (piece=="T") {
pc = new PieceT(t);
}
else if (piece=="S") {
pc = new PieceS(t);
}
else if (piece=="Z") {
pc = new PieceZ(t);
}
else if (piece=="J") {
pc = new PieceJ(t);
}
else if (piece=="L") {
pc = new PieceL(t);
}
return pc;
}