summaryrefslogtreecommitdiff
path: root/noncore/games/tetrix/qtetrixb.cpp
Unidiff
Diffstat (limited to 'noncore/games/tetrix/qtetrixb.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/tetrix/qtetrixb.cpp4
1 files changed, 4 insertions, 0 deletions
diff --git a/noncore/games/tetrix/qtetrixb.cpp b/noncore/games/tetrix/qtetrixb.cpp
index 3c179df..8c41fb2 100644
--- a/noncore/games/tetrix/qtetrixb.cpp
+++ b/noncore/games/tetrix/qtetrixb.cpp
@@ -35,48 +35,49 @@ QTetrixBoard::QTetrixBoard( QWidget *p, const char *name )
35 35
36 colors[0].setRgb(200,100,100); 36 colors[0].setRgb(200,100,100);
37 colors[1].setRgb(100,200,100); 37 colors[1].setRgb(100,200,100);
38 colors[2].setRgb(100,100,200); 38 colors[2].setRgb(100,100,200);
39 colors[3].setRgb(200,200,100); 39 colors[3].setRgb(200,200,100);
40 colors[4].setRgb(200,100,200); 40 colors[4].setRgb(200,100,200);
41 colors[5].setRgb(100,200,200); 41 colors[5].setRgb(100,200,200);
42 colors[6].setRgb(218,170, 0); 42 colors[6].setRgb(218,170, 0);
43 43
44 xOffset = -1; // -1 until a resizeEvent is received. 44 xOffset = -1; // -1 until a resizeEvent is received.
45 blockWidth = 20; 45 blockWidth = 20;
46 yOffset = 30; 46 yOffset = 30;
47 blockHeight = 20; 47 blockHeight = 20;
48 noGame = TRUE; 48 noGame = TRUE;
49 isPaused = FALSE; 49 isPaused = FALSE;
50 waitingAfterLine = FALSE; 50 waitingAfterLine = FALSE;
51 updateTimeoutTime(); // Sets timeoutTime 51 updateTimeoutTime(); // Sets timeoutTime
52} 52}
53 53
54void QTetrixBoard::startGame(int gameType,int fillRandomLines) 54void QTetrixBoard::startGame(int gameType,int fillRandomLines)
55{ 55{
56 if ( isPaused ) 56 if ( isPaused )
57 return; // ignore if game is paused 57 return; // ignore if game is paused
58 noGame = FALSE; 58 noGame = FALSE;
59
59 GenericTetrix::startGame( gameType, fillRandomLines ); 60 GenericTetrix::startGame( gameType, fillRandomLines );
60 // Note that the timer is started by updateLevel! 61 // Note that the timer is started by updateLevel!
61} 62}
62 63
63 64
64void QTetrixBoard::pause() 65void QTetrixBoard::pause()
65{ 66{
66 if ( noGame ) // game not active 67 if ( noGame ) // game not active
67 return; 68 return;
68 isPaused = !isPaused; 69 isPaused = !isPaused;
69 if ( isPaused ) { 70 if ( isPaused ) {
70 timer->stop(); 71 timer->stop();
71 hideBoard(); 72 hideBoard();
72 } 73 }
73 else 74 else
74 timer->start(timeoutTime); 75 timer->start(timeoutTime);
75 update(); 76 update();
76} 77}
77 78
78 79
79void QTetrixBoard::drawSquare(int x,int y,int value) 80void QTetrixBoard::drawSquare(int x,int y,int value)
80{ 81{
81 if (xOffset == -1) // Before first resizeEvent? 82 if (xOffset == -1) // Before first resizeEvent?
82 return; 83 return;
@@ -185,50 +186,53 @@ void QTetrixBoard::drawContents( QPainter *p )
185 x2 = 0; 186 x2 = 0;
186 if (x2 >= boardWidth()) 187 if (x2 >= boardWidth())
187 x2 = boardWidth() - 1; 188 x2 = boardWidth() - 1;
188 189
189 y1 = (r.top() - yOffset) / blockHeight; 190 y1 = (r.top() - yOffset) / blockHeight;
190 if (y1 < 0) 191 if (y1 < 0)
191 y1 = 0; 192 y1 = 0;
192 if (y1 >= boardHeight()) 193 if (y1 >= boardHeight())
193 y1 = boardHeight() - 1; 194 y1 = boardHeight() - 1;
194 195
195 y2 = (r.bottom() - yOffset) / blockHeight; 196 y2 = (r.bottom() - yOffset) / blockHeight;
196 if (y2 < 0) 197 if (y2 < 0)
197 y2 = 0; 198 y2 = 0;
198 if (y2 >= boardHeight()) 199 if (y2 >= boardHeight())
199 y2 = boardHeight() - 1; 200 y2 = boardHeight() - 1;
200 201
201 updateBoard( x1, y1, x2, y2, TRUE ); 202 updateBoard( x1, y1, x2, y2, TRUE );
202 paint = 0; // reset widget painter 203 paint = 0; // reset widget painter
203 return; 204 return;
204} 205}
205 206
206void QTetrixBoard::resizeEvent(QResizeEvent *e) 207void QTetrixBoard::resizeEvent(QResizeEvent *e)
207{ 208{
208 QSize sz = e->size(); 209 QSize sz = e->size();
210
209 blockWidth = (sz.width() - 2)/10; 211 blockWidth = (sz.width() - 2)/10;
210 blockHeight = (sz.height() - 2)/22; 212 blockHeight = (sz.height() - 2)/22;
213/* blockWidth > blockHeight ? blockWidth = blockHeight
214 : blockHeight = blockWidth;*/
211 xOffset = 1; 215 xOffset = 1;
212 //yOffset = 1; 216 //yOffset = 1;
213 yOffset = (sz.height() - 2) - (blockHeight *22); 217 yOffset = (sz.height() - 2) - (blockHeight *22);
214} 218}
215 219
216void QTetrixBoard::keyPressEvent( QKeyEvent *e ) 220void QTetrixBoard::keyPressEvent( QKeyEvent *e )
217{ 221{
218 if ( noGame || isPaused || waitingAfterLine ) 222 if ( noGame || isPaused || waitingAfterLine )
219 return; 223 return;
220 switch( e->key() ) { 224 switch( e->key() ) {
221 case Key_Left : 225 case Key_Left :
222 moveLeft(); 226 moveLeft();
223 break; 227 break;
224 case Key_Right : 228 case Key_Right :
225 moveRight(); 229 moveRight();
226 break; 230 break;
227 case Key_Down : 231 case Key_Down :
228 // rotateRight(); 232 // rotateRight();
229 dropDown(); 233 dropDown();
230 break; 234 break;
231 case Key_Up : 235 case Key_Up :
232 rotateLeft(); 236 rotateLeft();
233 break; 237 break;
234 case Key_Space : 238 case Key_Space :