-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLevel.h
156 lines (131 loc) · 4.09 KB
/
Level.h
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#ifndef _LEVEL_
#define _LEVEL_
#include "FileIO.h"
#include "Block.h"
#include "AbstractBlockFactory.h"
#include <string>
#include <vector>
#include <memory>
#include <map>
class BoardSubject;//for postMove
extern std::string defaultFilePath;
//use strategy pattern to get next block
//could use some sort of member variable and if statement to achieve the same thing
//but the coupling is huge
//each Level instancce will hold a reference to GenBlock (or a child of it)
//each level will call getNextBlockType() to determine what is the next block it is going to generate
//then level takes the result and use it in nextBlock() to generate a shared_ptr<Block>
class GenBlock {
public:
virtual std::string getNextBlockType() = 0;
virtual bool isReadingFromFile() const = 0;
virtual std::string getFileName();
};
struct PGenBlockFromFile {
//sequence of block to be generated
std::vector<std::string> blockSeq_;
//current block
std::vector<std::string>::iterator curr_;
std::string filename_;
};
class GenBlockFromFile: public GenBlock {
private:
std::shared_ptr<PGenBlockFromFile> gb_;
public:
GenBlockFromFile(std::string path = defaultFilePath);
std::string getFileName() override;
std::string getNextBlockType() override;
bool isReadingFromFile() const override;
};
struct PGenRandomBlock {
// <char of block type, probability of it being generated>
std::map<char, double> blockProbabilities_;
};
class GenRandomBlock: public GenBlock {
protected:
std::shared_ptr<PGenRandomBlock> gb_;
public:
GenRandomBlock();
std::string getNextBlockType() override;
bool isReadingFromFile() const override;
};
class GenRandomBlockLvl1: public GenRandomBlock {
public:
GenRandomBlockLvl1();
};
class GenRandomBlockLvl2: public GenRandomBlock {
public:
GenRandomBlockLvl2();
};
class GenRandomBlockLvl3: public GenRandomBlock {
public:
GenRandomBlockLvl3();
};
class GenRandomBlockLvl5: public GenRandomBlock {
public:
GenRandomBlockLvl5();
};
struct PImplLevel{
AbstractBlockFactory& blockFactory_;
std::shared_ptr<GenBlock> blockGen_;
PImplLevel();
};
class Level{
protected:
std::shared_ptr<PImplLevel> lv_;
public:
virtual void postMove(std::shared_ptr<Block> block, std::shared_ptr<BoardSubject> bd); //for "heavy" blocks, empty for level < 3
virtual void postDrop(std::shared_ptr<BoardSubject> bd); //for * blocks generated after drop, empty for level < 4
virtual void resetCounter(); //counter of drop that doesn't eliminate rows, empty for level < 4
virtual std::shared_ptr<Block> nextBlock();
virtual unsigned int whatLevel() const = 0;
virtual void switchToReadFile(std::string path = defaultFilePath);
virtual void switchToRandom();
virtual bool isReadingFromFile();
virtual std::string getFileName();
virtual void reset();
// virtual Block generateBlock(string b) = 0;
};
class Level0: public Level {
public:
Level0();
unsigned int whatLevel() const override;
void reset() override;
};
class Level1: public Level {
public:
Level1();
unsigned int whatLevel() const override;
};
class Level2: public Level {
public:
Level2();
unsigned int whatLevel() const override;
};
class Level3: public Level {
public:
Level3();
void switchToReadFile(std::string path = defaultFilePath) override;
void switchToRandom() override;
unsigned int whatLevel() const override;
void postMove(std::shared_ptr<Block> block, std::shared_ptr<BoardSubject> bd) override;
};
class Level4: public Level3 {
private:
//how many times you placed a block without eliminating a row
unsigned int dropCounter_;
public:
Level4();
unsigned int whatLevel() const override;
void postDrop(std::shared_ptr<BoardSubject> bd); //empty for level < 4
void resetCounter();
void reset() override;
};
class Level5: public Level {
public:
Level5();
unsigned int whatLevel() const override;
};
//global function to change default file path (external variablle)
void changeDefaultFilePath(std::string);
#endif