Stefan Schuermans commited on 2019-08-14 18:16:13
Showing 11 changed files, with 76 additions and 15 deletions.
| ... | ... |
@@ -62,9 +62,27 @@ |
| 62 | 62 |
<tr><td><code>backgroundColor</code></td> |
| 63 | 63 |
<td></td> |
| 64 | 64 |
<td>background of the tetris field</td></tr> |
| 65 |
- <tr><td><code>stoneColor</code></td> |
|
| 65 |
+ <tr><td><code>stoneIColor</code></td> |
|
| 66 | 66 |
<td></td> |
| 67 |
- <td>stones - falling stone as well as fixed stones</td></tr> |
|
| 67 |
+ <td>stones of type "I" (falling and fixed)</td></tr> |
|
| 68 |
+ <tr><td><code>stoneJColor</code></td> |
|
| 69 |
+ <td></td> |
|
| 70 |
+ <td>stones of type "J" (falling and fixed)</td></tr> |
|
| 71 |
+ <tr><td><code>stoneLColor</code></td> |
|
| 72 |
+ <td></td> |
|
| 73 |
+ <td>stones of type "L" (falling and fixed)</td></tr> |
|
| 74 |
+ <tr><td><code>stoneOColor</code></td> |
|
| 75 |
+ <td></td> |
|
| 76 |
+ <td>stones of type "O" (falling and fixed)</td></tr> |
|
| 77 |
+ <tr><td><code>stoneSColor</code></td> |
|
| 78 |
+ <td></td> |
|
| 79 |
+ <td>stones of type "S" (falling and fixed)</td></tr> |
|
| 80 |
+ <tr><td><code>stoneTColor</code></td> |
|
| 81 |
+ <td></td> |
|
| 82 |
+ <td>stones of type "T" (falling and fixed)</td></tr> |
|
| 83 |
+ <tr><td><code>stoneZColor</code></td> |
|
| 84 |
+ <td></td> |
|
| 85 |
+ <td>stones of type "Z" (falling and fixed)</td></tr> |
|
| 68 | 86 |
</table> |
| 69 | 87 |
</p> |
| 70 | 88 |
<h3>Delays</h3> |
| ... | ... |
@@ -1 +0,0 @@ |
| 1 |
-FFFFFF |
| ... | ... |
@@ -0,0 +1 @@ |
| 1 |
+FF0000 |
| ... | ... |
@@ -0,0 +1 @@ |
| 1 |
+FFFF00 |
| ... | ... |
@@ -0,0 +1 @@ |
| 1 |
+FF00FF |
| ... | ... |
@@ -0,0 +1 @@ |
| 1 |
+0000FF |
| ... | ... |
@@ -0,0 +1 @@ |
| 1 |
+00FFFF |
| ... | ... |
@@ -0,0 +1 @@ |
| 1 |
+00FF00 |
| ... | ... |
@@ -0,0 +1 @@ |
| 1 |
+FF8000 |
| ... | ... |
@@ -36,7 +36,13 @@ namespace Blinker {
|
| 36 | 36 |
*/ |
| 37 | 37 |
Tetris::Tetris(const std::string &name, Mgrs &mgrs, const Directory &dirBase): |
| 38 | 38 |
Game(name, mgrs, dirBase), |
| 39 |
- m_fileStoneColor(dirBase.getFile("stoneColor")),
|
|
| 39 |
+ m_fileStoneIColor(dirBase.getFile("stoneIColor")),
|
|
| 40 |
+ m_fileStoneLColor(dirBase.getFile("stoneLColor")),
|
|
| 41 |
+ m_fileStoneJColor(dirBase.getFile("stoneJColor")),
|
|
| 42 |
+ m_fileStoneTColor(dirBase.getFile("stoneTColor")),
|
|
| 43 |
+ m_fileStoneOColor(dirBase.getFile("stoneOColor")),
|
|
| 44 |
+ m_fileStoneZColor(dirBase.getFile("stoneZColor")),
|
|
| 45 |
+ m_fileStoneSColor(dirBase.getFile("stoneSColor")),
|
|
| 40 | 46 |
m_fileDelay(dirBase.getFile("delay")),
|
| 41 | 47 |
m_fileDropDelay(dirBase.getFile("dropDelay")),
|
| 42 | 48 |
m_fileBlinkDelay(dirBase.getFile("blinkDelay")),
|
| ... | ... |
@@ -44,7 +50,6 @@ Tetris::Tetris(const std::string &name, Mgrs &mgrs, const Directory &dirBase): |
| 44 | 50 |
m_fileStartSound(dirBase.getFile("startSound")),
|
| 45 | 51 |
m_fileRowCompleteSound(dirBase.getFile("rowCompleteSound")),
|
| 46 | 52 |
m_fileGameOverSound(dirBase.getFile("gameOverSound")),
|
| 47 |
- m_stoneColor(), |
|
| 48 | 53 |
m_delay(c_delayDescr.default_), |
| 49 | 54 |
m_dropDelay(c_dropDelayDescr.default_), |
| 50 | 55 |
m_blinkDelay(c_blinkDelayDescr.default_), |
| ... | ... |
@@ -81,7 +86,13 @@ void Tetris::updateConfigGame(bool &doReinit, bool &doRedraw) |
| 81 | 86 |
(void)doReinit; |
| 82 | 87 |
|
| 83 | 88 |
// color file was modified -> convert color, ask for redraw |
| 84 |
- if (colorUpdate(m_fileStoneColor, m_stoneColor)) { doRedraw = true; }
|
|
| 89 |
+ if (colorUpdate(m_fileStoneIColor, m_stoneColors[StoneI])) { doRedraw = true; }
|
|
| 90 |
+ if (colorUpdate(m_fileStoneLColor, m_stoneColors[StoneL])) { doRedraw = true; }
|
|
| 91 |
+ if (colorUpdate(m_fileStoneJColor, m_stoneColors[StoneJ])) { doRedraw = true; }
|
|
| 92 |
+ if (colorUpdate(m_fileStoneTColor, m_stoneColors[StoneT])) { doRedraw = true; }
|
|
| 93 |
+ if (colorUpdate(m_fileStoneOColor, m_stoneColors[StoneO])) { doRedraw = true; }
|
|
| 94 |
+ if (colorUpdate(m_fileStoneZColor, m_stoneColors[StoneZ])) { doRedraw = true; }
|
|
| 95 |
+ if (colorUpdate(m_fileStoneSColor, m_stoneColors[StoneS])) { doRedraw = true; }
|
|
| 85 | 96 |
|
| 86 | 97 |
// delay cfg value file was updated -> read new delay cfg value, no re-* |
| 87 | 98 |
valueUpdate(m_fileDelay, c_delayDescr, m_delay); |
| ... | ... |
@@ -254,7 +265,14 @@ void Tetris::opConnClose(OpConn *pConn) |
| 254 | 265 |
void Tetris::reinitialize() |
| 255 | 266 |
{
|
| 256 | 267 |
// convert colors |
| 257 |
- color2data(m_fileStoneColor, m_stoneColor); |
|
| 268 |
+ color2data(m_fileStoneIColor, m_stoneColors[StoneI]); |
|
| 269 |
+ color2data(m_fileStoneLColor, m_stoneColors[StoneL]); |
|
| 270 |
+ color2data(m_fileStoneJColor, m_stoneColors[StoneJ]); |
|
| 271 |
+ color2data(m_fileStoneTColor, m_stoneColors[StoneT]); |
|
| 272 |
+ color2data(m_fileStoneOColor, m_stoneColors[StoneO]); |
|
| 273 |
+ color2data(m_fileStoneZColor, m_stoneColors[StoneZ]); |
|
| 274 |
+ color2data(m_fileStoneSColor, m_stoneColors[StoneS]); |
|
| 275 |
+ |
|
| 258 | 276 |
// get values |
| 259 | 277 |
valueFromFile(m_fileDelay, c_delayDescr, m_delay); |
| 260 | 278 |
valueFromFile(m_fileDropDelay, c_dropDelayDescr, m_dropDelay); |
| ... | ... |
@@ -295,7 +313,7 @@ void Tetris::redraw() |
| 295 | 313 |
if (! (m_blinking & 1) || ! m_rowsBlink.at(y)) {
|
| 296 | 314 |
for (int x = 0; x < m_width; ++x, ++i) {
|
| 297 | 315 |
if (m_field.at(i) >= 0) {
|
| 298 |
- pixel(y, x, m_stoneColor); |
|
| 316 |
+ pixel(y, x, m_stoneColors[m_field.at(i)]); |
|
| 299 | 317 |
} |
| 300 | 318 |
} |
| 301 | 319 |
} |
| ... | ... |
@@ -573,7 +591,7 @@ void Tetris::freezeStone(int stone, int rot, int y, int x) |
| 573 | 591 |
/// draw a stone to image buffer |
| 574 | 592 |
void Tetris::drawStone(int stone, int rot, int y, int x) |
| 575 | 593 |
{
|
| 576 |
- colorStone(stone, rot, y, x, m_stoneColor); |
|
| 594 |
+ colorStone(stone, rot, y, x, m_stoneColors[stone]); |
|
| 577 | 595 |
} |
| 578 | 596 |
|
| 579 | 597 |
/// wipe a stone from image buffer (i.e. replace it with background color) |
| ... | ... |
@@ -598,8 +616,8 @@ void Tetris::colorStone(int stone, int rot, int y, int x, |
| 598 | 616 |
} |
| 599 | 617 |
} |
| 600 | 618 |
|
| 601 |
-/// stone data |
|
| 602 |
-Tetris::Stone const Tetris::c_stones[7] = {
|
|
| 619 |
+/// stone data (make sure it matches the StoneIndex enum) |
|
| 620 |
+Tetris::Stone const Tetris::c_stones[Tetris::StoneCnt] = {
|
|
| 603 | 621 |
// the I |
| 604 | 622 |
{ {
|
| 605 | 623 |
{ { { -2, 0 }, { -1, 0 }, { 0, 0 }, { 1, 0 } } },
|
| ... | ... |
@@ -34,6 +34,18 @@ namespace Blinker {
|
| 34 | 34 |
class Tetris: public Game, public OpReqIf |
| 35 | 35 |
{
|
| 36 | 36 |
protected: |
| 37 |
+ /// indices of the stones |
|
| 38 |
+ enum StoneIndex {
|
|
| 39 |
+ StoneI, |
|
| 40 |
+ StoneL, |
|
| 41 |
+ StoneJ, |
|
| 42 |
+ StoneT, |
|
| 43 |
+ StoneO, |
|
| 44 |
+ StoneZ, |
|
| 45 |
+ StoneS, |
|
| 46 |
+ StoneCnt // not an index, but number of stones |
|
| 47 |
+ }; |
|
| 48 |
+ |
|
| 37 | 49 |
/// coordinates of a pixel part of a stone |
| 38 | 50 |
struct Coord {
|
| 39 | 51 |
int x; |
| ... | ... |
@@ -165,8 +177,8 @@ protected: |
| 165 | 177 |
void colorStone(int stone, int rot, int y, int x, ColorData const &color); |
| 166 | 178 |
|
| 167 | 179 |
protected: |
| 168 |
- /// stone data |
|
| 169 |
- static Stone const c_stones[7]; |
|
| 180 |
+ /// stone data (make sure it matches the StoneIndex enum) |
|
| 181 |
+ static Stone const c_stones[StoneCnt]; |
|
| 170 | 182 |
|
| 171 | 183 |
static int const c_stoneCnt; ///< number of stones |
| 172 | 184 |
static int const c_rotCnt; ///< number of rotations per stone |
| ... | ... |
@@ -184,7 +196,13 @@ protected: |
| 184 | 196 |
/// descriptor for delay value at end of game |
| 185 | 197 |
static ValueDescr const c_gameOverDelayDescr; |
| 186 | 198 |
|
| 187 |
- ColorFile m_fileStoneColor; ///< color file for stone color |
|
| 199 |
+ ColorFile m_fileStoneIColor; ///< color file for I stone color |
|
| 200 |
+ ColorFile m_fileStoneLColor; ///< color file for L stone color |
|
| 201 |
+ ColorFile m_fileStoneJColor; ///< color file for J stone color |
|
| 202 |
+ ColorFile m_fileStoneTColor; ///< color file for T stone color |
|
| 203 |
+ ColorFile m_fileStoneOColor; ///< color file for O stone color |
|
| 204 |
+ ColorFile m_fileStoneZColor; ///< color file for Z stone color |
|
| 205 |
+ ColorFile m_fileStoneSColor; ///< color file for S stone color |
|
| 188 | 206 |
UIntFile m_fileDelay; ///< file for initial delay in ms per frame |
| 189 | 207 |
UIntFile m_fileDropDelay; ///< file for delay while dropping (ms/frame) |
| 190 | 208 |
UIntFile m_fileBlinkDelay; ///< file for delay while blinking (ms/frame) |
| ... | ... |
@@ -194,7 +212,8 @@ protected: |
| 194 | 212 |
NameFile m_fileRowCompleteSound; ///< "row complete" sound name file |
| 195 | 213 |
NameFile m_fileGameOverSound; ///< "game over" sound name file |
| 196 | 214 |
|
| 197 |
- ColorData m_stoneColor; ///< stone color |
|
| 215 |
+ ColorData m_stoneColors[StoneCnt]; ///< stone colors |
|
| 216 |
+ |
|
| 198 | 217 |
unsigned int m_delay; ///< initial delay in ms per frame |
| 199 | 218 |
unsigned int m_dropDelay; ///< delay while dropping in ms per frame |
| 200 | 219 |
unsigned int m_blinkDelay; ///< delay while rows blinking in ms per frame |
| 201 | 220 |