ScummVM API documentation
tetris.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#ifndef QDENGINE_MINIGAMES_TETRIS_H
23#define QDENGINE_MINIGAMES_TETRIS_H
24
25#include "common/debug.h"
26
27#include "qdengine/qd_fwd.h"
28#include "qdengine/qdcore/qd_minigame_interface.h"
29
30namespace QDEngine {
31
33public:
35 _flyingObjs = _hiddenObjs = nullptr;
36 }
38 free(_flyingObjs);
39 free(_hiddenObjs);
40 }
41
42 bool init(const qdEngineInterface *engine_interface) {
43 debugC(1, kDebugMinigames, "Tetris::init()");
44
45 _engine = engine_interface;
46 _scene = engine_interface->current_scene_interface();
47 if (!_scene)
48 return false;
49
50 if (!_flyingObjs) {
51 _flyingObjs = (qdMinigameObjectInterface **)malloc(5 * sizeof(qdMinigameObjectInterface *));
52
53 if (!_flyingObjs)
54 return false;
55
56 for (int i = 0; i < 5; i++) {
57 Common::String name = Common::String::format("\xeb\xe5\xf2\xe8\xf2%d", i + 1); // "летит%i"
58 _flyingObjs[i] = _scene->object_interface(_scene->minigame_parameter(name.c_str()));
59 }
60 }
61
62 if (!_hiddenObjs) {
63 _hiddenObjs = (qdMinigameObjectInterface **)malloc(5 * sizeof(qdMinigameObjectInterface *));
64
65 if (!_hiddenObjs)
66 return false;
67
68 for (int i = 0; i < 5; i++) {
69 Common::String name = Common::String::format("\xf1\xea\xf0\xfb\xf2%d", i + 1); // "скрыт%i"
70 _hiddenObjs[i] = _scene->object_interface(_scene->minigame_parameter(name.c_str()));
71 }
72 }
73
74 _lastRowObj = _scene->object_interface(_scene->minigame_parameter("last_row"));
75
76 return true;
77 }
78
79 bool quant(float dt) {
80 debugC(3, kDebugMinigames, "Tetris::quant(%f)", dt);
81
82 for (int i = 0; i < 5; i++ ) {
83 if (_flyingObjs[i]->is_state_active("\xeb\xe5\xf2\xe8\xf2") // "летит"
84 && _hiddenObjs[i]->is_state_active("\xed\xe5\xf2")) { // "нет"
85
86 mgVect2i pos = _flyingObjs[i]->screen_R();
87
88 if (pos.x <= 251) {
89 int activeColumn = getActiveColumn();
90 if (activeColumn < 12)
91 activeColumn = 12;
92 if (pos.y > 535 - 10 * activeColumn)
93 _hiddenObjs[i]->set_state("\xe4\xe0"); // "да"
94 } else {
95 if (pos.y > 535 - 10 * getActiveColumn())
96 _hiddenObjs[i]->set_state("\xe4\xe0"); // "да"
97 }
98 }
99 }
100
101 return true;
102 }
103
104 bool finit() {
105 debugC(1, kDebugMinigames, "Tetris::finit()");
106
107 if (_scene) {
108 _engine->release_scene_interface(_scene);
109 _scene = 0;
110 }
111
112 return true;
113 }
114
115 bool new_game(const qdEngineInterface *engine_interface) {
116 return true;
117 }
118
119 int save_game(const qdEngineInterface *engine_interface, const qdMinigameSceneInterface *scene_interface, char *buffer, int buffer_size) {
120 return 0;
121 }
122
123 int load_game(const qdEngineInterface *engine_interface, const qdMinigameSceneInterface *scene_interface, const char *buffer, int buffer_size) {
124 return 0;
125 }
126
127 enum { INTERFACE_VERSION = 99 };
128 int version() const {
129 return INTERFACE_VERSION;
130 }
131
132private:
133 int getActiveColumn() {
134 if (_lastRowObj->is_state_active("0"))
135 return 0;
136 if (_lastRowObj->is_state_active("1"))
137 return 1;
138 if (_lastRowObj->is_state_active("2"))
139 return 2;
140 if (_lastRowObj->is_state_active("3"))
141 return 3;
142 if (_lastRowObj->is_state_active("4"))
143 return 4;
144 if (_lastRowObj->is_state_active("5"))
145 return 5;
146 if (_lastRowObj->is_state_active("6"))
147 return 6;
148 if (_lastRowObj->is_state_active("7"))
149 return 7;
150 if (_lastRowObj->is_state_active("8"))
151 return 8;
152 if (_lastRowObj->is_state_active("9"))
153 return 9;
154 if (_lastRowObj->is_state_active("10"))
155 return 10;
156 if (_lastRowObj->is_state_active("11"))
157 return 11;
158 if (_lastRowObj->is_state_active("12"))
159 return 12;
160 if (_lastRowObj->is_state_active("13"))
161 return 13;
162 if (_lastRowObj->is_state_active("14"))
163 return 14;
164 if (_lastRowObj->is_state_active("15"))
165 return 15;
166 if (_lastRowObj->is_state_active("16"))
167 return 16;
168 if (_lastRowObj->is_state_active("17"))
169 return 17;
170 if (_lastRowObj->is_state_active("18"))
171 return 18;
172 if (_lastRowObj->is_state_active("19"))
173 return 19;
174 if (_lastRowObj->is_state_active("20"))
175 return 20;
176 if (_lastRowObj->is_state_active("21"))
177 return 21;
178 if (_lastRowObj->is_state_active("22"))
179 return 22;
180 if (_lastRowObj->is_state_active("23"))
181 return 23;
182 if (_lastRowObj->is_state_active("24"))
183 return 24;
184
185 return 0;
186 }
187
188private:
189 const qdEngineInterface *_engine = nullptr;
190 qdMinigameSceneInterface *_scene = nullptr;
191
192 qdMinigameObjectInterface **_flyingObjs = nullptr;
193 qdMinigameObjectInterface **_hiddenObjs = nullptr;
194 qdMinigameObjectInterface *_lastRowObj = nullptr;
195
196};
197
198} // namespace QDEngine
199
200#endif // QDENGINE_MINIGAMES_TETRIS_H
Definition: str.h:59
static String format(MSVC_PRINTF const char *fmt,...) GCC_PRINTF(1
Definition: qd_minigame_interface.h:365
Definition: qd_minigame_interface.h:78
Интерфейс к динамическому объекту.
Definition: qd_minigame_interface.h:230
virtual mgVect2i screen_R() const =0
Возвращает координаты объекта в экранной системе координат.
virtual bool set_state(const char *state_name)=0
Включает состояние с именем state_name.
virtual bool is_state_active(const char *state_name) const =0
Возвращает true, если состояние с именем state_name включено в данный момент.
Интерфейс к сцене.
Definition: qd_minigame_interface.h:315
virtual qdMinigameObjectInterface * object_interface(const char *object_name, bool test=false)=0
Создаёт интерфейс к объекту с именем object_name.
Definition: tetris.h:32
int load_game(const qdEngineInterface *engine_interface, const qdMinigameSceneInterface *scene_interface, const char *buffer, int buffer_size)
Загрузка данных, вызывается при загрузке сцены, на которую повешена миниигра.
Definition: tetris.h:123
int save_game(const qdEngineInterface *engine_interface, const qdMinigameSceneInterface *scene_interface, char *buffer, int buffer_size)
Сохранение данных, вызывается при сохранении сцены, на которую повешена миниигра.
Definition: tetris.h:119
bool finit()
Деинициализация игры.
Definition: tetris.h:104
bool init(const qdEngineInterface *engine_interface)
Инициализация игры.
Definition: tetris.h:42
bool new_game(const qdEngineInterface *engine_interface)
Инициализация миниигры, вызывается при старте и перезапуске игры.
Definition: tetris.h:115
bool quant(float dt)
Обсчёт логики игры, параметр - время, которое должно пройти в игре (в секундах).
Definition: tetris.h:79
void void void void void debugC(int level, uint32 debugChannel, MSVC_PRINTF const char *s,...) GCC_PRINTF(3
Базовый класс для игровых ресурсов.
Definition: console.h:28