-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTetrisStats.cpp
More file actions
79 lines (67 loc) · 1.88 KB
/
TetrisStats.cpp
File metadata and controls
79 lines (67 loc) · 1.88 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
/**
* TetrisStats.cpp
*
* $Revision$
* $Id$
*
* @see TetrisStats.h
*
*/
#include "TetrisStats.h"
CTetrisStats::CTetrisStats() {
settings = &SConfig::getInstance();
m_tetrominoCounter = 0;
m_score = 0;
m_level = settings->getValueAsInt("level");
m_removedLines = 0;
m_removedLinesLast = 0;
m_dropDelay = settings->getValueAsInt("delay");
}
CTetrisStats::~CTetrisStats() {
}
void CTetrisStats::linesRemoved(const int lines) {
m_removedLinesLast = lines;
m_removedLines += lines;
switch(lines) {
case 1: m_score += settings->getValueAsInt("score 1 line")*m_level;break;
case 2: m_score += settings->getValueAsInt("score 2 lines")*m_level;break;
case 3: m_score += settings->getValueAsInt("score 3 lines")*m_level;break;
case 4: m_score += settings->getValueAsInt("score 4 lines")*m_level;break;
default: break;
}
notifyChangeInStats();
update();
}
void CTetrisStats::tetrominoAdded() {
m_tetrominoCounter++;
m_score += m_level;
notifyChangeInStats();
update();
}
int CTetrisStats::getLevel() {
return m_level;
}
int CTetrisStats::getScore() {
return m_score;
}
int CTetrisStats::getRemovedLines() {
return m_removedLines;
}
int CTetrisStats::getRemovedLinesLast() {
return m_removedLinesLast;
}
int CTetrisStats::getDropDelay() {
// TODO: oikea delay-logiikka
int delay = m_dropDelay / m_level;
return delay;
}
void CTetrisStats::update() {
// TODO: oikeaoppinen levelin laskeminen. lasketaanko räjäytetyistä riveistä vai palikoiden määrästä?
int level = (int)(m_tetrominoCounter / settings->getValueAsInt("level increase")) + 1;
if(m_level <= LEVEL_MAX)
m_level = level;
}
void CTetrisStats::notifyChangeInStats() {
for(int i=0; i<m_listenerCount; i++)
listeners[i]->handleChangeInStats(m_score, m_level, m_removedLines, m_removedLinesLast);
}