Repository navigation
Expand file tree
/
Copy pathcommand.cc
More file actions
147 lines (124 loc) · 3.23 KB
/
Copy pathcommand.cc
File metadata and controls
147 lines (124 loc) · 3.23 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
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
export module command;
import <string>;
import <map>;
import <vector>;
import <memory>;
import game;
// Abstract Command class
export class Command {
public:
virtual ~Command() = default;
virtual void execute(Game* game) = 0;
virtual bool canMultiply() const;
};
// Movement commands
export class LeftCommand : public Command {
public:
void execute(Game* game) override;
};
export class RightCommand : public Command {
public:
void execute(Game* game) override;
};
export class DownCommand : public Command {
public:
void execute(Game* game) override;
};
export class DropCommand : public Command {
public:
void execute(Game* game) override;
};
// Rotation commands
export class RotateClockwiseCommand : public Command {
public:
void execute(Game* game) override;
};
export class RotateCounterClockwiseCommand : public Command {
public:
void execute(Game* game) override;
};
// Level commands
export class LevelUpCommand : public Command {
public:
void execute(Game* game) override;
};
export class LevelDownCommand : public Command {
public:
void execute(Game* game) override;
};
// Random mode commands
export class RandomCommand : public Command {
public:
void execute(Game* game) override;
bool canMultiply() const override;
};
export class NoRandomCommand : public Command {
public:
void execute(Game* game) override;
bool canMultiply() const override;
};
// Restart command
export class RestartCommand : public Command {
public:
void execute(Game* game) override;
bool canMultiply() const override;
};
// Sequence command - execute commands from file
export class SequenceCommand : public Command {
public:
void execute(Game* game) override;
bool canMultiply() const override;
};
// Test commands - replace current block with specified type
export class IBlockCommand : public Command {
public:
void execute(Game* game) override;
bool canMultiply() const override;
};
export class JBlockCommand : public Command {
public:
void execute(Game* game) override;
bool canMultiply() const override;
};
export class LBlockCommand : public Command {
public:
void execute(Game* game) override;
bool canMultiply() const override;
};
export class OBlockCommand : public Command {
public:
void execute(Game* game) override;
bool canMultiply() const override;
};
export class SBlockCommand : public Command {
public:
void execute(Game* game) override;
bool canMultiply() const override;
};
export class ZBlockCommand : public Command {
public:
void execute(Game* game) override;
bool canMultiply() const override;
};
export class TBlockCommand : public Command {
public:
void execute(Game* game) override;
bool canMultiply() const override;
};
// Help command
export class HelpCommand : public Command {
public:
void execute(Game*) override;
bool canMultiply() const override;
};
// Command Interpreter
export class CommandInterpreter {
std::map<std::string, std::unique_ptr<Command>> commands;
Game* game;
public:
CommandInterpreter(Game* g);
void registerCommands();
std::string matchCommand(const std::string& prefix);
void executeCommand(const std::string& input);
void executeSequenceFile(const std::string& filename);
};