author | zecke <zecke> | 2003-05-14 08:33:57 (UTC) |
---|---|---|
committer | zecke <zecke> | 2003-05-14 08:33:57 (UTC) |
commit | 79e34e9dc4870885c58f80c29a723d0227f7b788 (patch) (unidiff) | |
tree | 1e91a0e6d698c782ef975e023288d4b9817e82c6 | |
parent | 81a58bae78d693b67679d94d2f7fcdb300e12d4f (diff) | |
download | opie-79e34e9dc4870885c58f80c29a723d0227f7b788.zip opie-79e34e9dc4870885c58f80c29a723d0227f7b788.tar.gz opie-79e34e9dc4870885c58f80c29a723d0227f7b788.tar.bz2 |
patch by Scott Bronson.
Add a little game description in the about messagebox
-rw-r--r-- | noncore/games/bounce/kbounce.cpp | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/noncore/games/bounce/kbounce.cpp b/noncore/games/bounce/kbounce.cpp index f703f74..5d8aba3 100644 --- a/noncore/games/bounce/kbounce.cpp +++ b/noncore/games/bounce/kbounce.cpp | |||
@@ -1,302 +1,311 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (C) 2000 Stefan Schimanski <1Stein@gmx.de> | 2 | * Copyright (C) 2000 Stefan Schimanski <1Stein@gmx.de> |
3 | * | 3 | * |
4 | * This program is free software; you can redistribute it and/or | 4 | * This program is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU Library General Public | 5 | * modify it under the terms of the GNU Library General Public |
6 | * License as published by the Free Software Foundation; either | 6 | * License as published by the Free Software Foundation; either |
7 | * version 2 of the License,Life or (at your option) any later version. | 7 | * version 2 of the License,Life or (at your option) any later version. |
8 | * | 8 | * |
9 | * This program is distributed in the hope that it will be useful, | 9 | * This program is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | * Library General Public License for more details. | 12 | * Library General Public License for more details. |
13 | * | 13 | * |
14 | * You should have received a copy of the GNU Library General Public | 14 | * You should have received a copy of the GNU Library General Public |
15 | * License along with this program; if not, write to the Free | 15 | * License along with this program; if not, write to the Free |
16 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 16 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
17 | */ | 17 | */ |
18 | 18 | ||
19 | #include <qlayout.h> | 19 | #include <qlayout.h> |
20 | #include <qtimer.h> | 20 | #include <qtimer.h> |
21 | #include <qlcdnumber.h> | 21 | #include <qlcdnumber.h> |
22 | #include <qmessagebox.h> | 22 | #include <qmessagebox.h> |
23 | #include <qmainwindow.h> | 23 | #include <qmainwindow.h> |
24 | #include <qpe/qpeapplication.h> | 24 | #include <qpe/qpeapplication.h> |
25 | 25 | ||
26 | #include "kbounce.h" | 26 | #include "kbounce.h" |
27 | #include "game.h" | 27 | #include "game.h" |
28 | #include <qlabel.h> | 28 | #include <qlabel.h> |
29 | 29 | ||
30 | KJezzball::KJezzball() : QMainWindow(0), m_gameWidget( 0 ) | 30 | KJezzball::KJezzball() : QMainWindow(0), m_gameWidget( 0 ) |
31 | { | 31 | { |
32 | setCaption(tr("Bounce")); | 32 | setCaption(tr("Bounce")); |
33 | // setup variables | 33 | // setup variables |
34 | m_game.level = 1; | 34 | m_game.level = 1; |
35 | m_game.score = 0; | 35 | m_game.score = 0; |
36 | m_state = Idle; | 36 | m_state = Idle; |
37 | 37 | ||
38 | 38 | ||
39 | menu = menuBar(); | 39 | menu = menuBar(); |
40 | game = new QPopupMenu; | 40 | game = new QPopupMenu; |
41 | game->insertItem(tr("&New game"), this, SLOT(newGame()), Key_N ); | 41 | game->insertItem(tr("&New game"), this, SLOT(newGame()), Key_N ); |
42 | game->insertItem(tr("&Pause game"), this, SLOT(pauseGame()), Key_P ); | 42 | game->insertItem(tr("&Pause game"), this, SLOT(pauseGame()), Key_P ); |
43 | game->insertSeparator(); | 43 | game->insertSeparator(); |
44 | game->insertItem(tr("&About"), this, SLOT(about())); | 44 | game->insertItem(tr("&About"), this, SLOT(about())); |
45 | menu->insertItem( tr("&Game"), game ); | 45 | menu->insertItem( tr("&Game"), game ); |
46 | 46 | ||
47 | // create widgets | 47 | // create widgets |
48 | m_view = new QWidget( this, "m_view" ); | 48 | m_view = new QWidget( this, "m_view" ); |
49 | setCentralWidget( m_view ); | 49 | setCentralWidget( m_view ); |
50 | 50 | ||
51 | m_layout = new QGridLayout( m_view ); | 51 | m_layout = new QGridLayout( m_view ); |
52 | m_layout->setSpacing( 0 ); | 52 | m_layout->setSpacing( 0 ); |
53 | m_layout->setMargin( 0 ); | 53 | m_layout->setMargin( 0 ); |
54 | 54 | ||
55 | ScoreLabel = new QLabel( m_view, "ScoreLabel" ); | 55 | ScoreLabel = new QLabel( m_view, "ScoreLabel" ); |
56 | ScoreLabel->setText( tr( "Score: 00" ) ); | 56 | ScoreLabel->setText( tr( "Score: 00" ) ); |
57 | ScoreLabel->setAlignment( int( QLabel::AlignCenter ) ); | 57 | ScoreLabel->setAlignment( int( QLabel::AlignCenter ) ); |
58 | 58 | ||
59 | m_layout->addWidget( ScoreLabel, 1, 0 ); | 59 | m_layout->addWidget( ScoreLabel, 1, 0 ); |
60 | 60 | ||
61 | LivesLabel = new QLabel( m_view, "LivesLabel" ); | 61 | LivesLabel = new QLabel( m_view, "LivesLabel" ); |
62 | LivesLabel->setText( tr( "Lives: 0%" ) ); | 62 | LivesLabel->setText( tr( "Lives: 0%" ) ); |
63 | LivesLabel->setAlignment( int( QLabel::AlignCenter ) ); | 63 | LivesLabel->setAlignment( int( QLabel::AlignCenter ) ); |
64 | 64 | ||
65 | m_layout->addWidget( LivesLabel, 1, 2 ); | 65 | m_layout->addWidget( LivesLabel, 1, 2 ); |
66 | 66 | ||
67 | FilledLabel = new QLabel( m_view, "FilledLabel" ); | 67 | FilledLabel = new QLabel( m_view, "FilledLabel" ); |
68 | FilledLabel->setText( tr( "Filled: 00%" ) ); | 68 | FilledLabel->setText( tr( "Filled: 00%" ) ); |
69 | FilledLabel->setAlignment( int( QLabel::AlignCenter ) ); | 69 | FilledLabel->setAlignment( int( QLabel::AlignCenter ) ); |
70 | 70 | ||
71 | m_layout->addWidget( FilledLabel, 1, 1 ); | 71 | m_layout->addWidget( FilledLabel, 1, 1 ); |
72 | 72 | ||
73 | TimeLabel = new QLabel( m_view, "TimeLabel" ); | 73 | TimeLabel = new QLabel( m_view, "TimeLabel" ); |
74 | TimeLabel->setText( tr( "Time: 00" ) ); | 74 | TimeLabel->setText( tr( "Time: 00" ) ); |
75 | TimeLabel->setAlignment( int( QLabel::AlignCenter ) ); | 75 | TimeLabel->setAlignment( int( QLabel::AlignCenter ) ); |
76 | 76 | ||
77 | m_layout->addWidget( TimeLabel, 1, 3 ); | 77 | m_layout->addWidget( TimeLabel, 1, 3 ); |
78 | 78 | ||
79 | // create timers | 79 | // create timers |
80 | m_nextLevelTimer = new QTimer( this, "m_nextLevelTimer" ); | 80 | m_nextLevelTimer = new QTimer( this, "m_nextLevelTimer" ); |
81 | connect( m_nextLevelTimer, SIGNAL(timeout()), this, SLOT(switchLevel()) ); | 81 | connect( m_nextLevelTimer, SIGNAL(timeout()), this, SLOT(switchLevel()) ); |
82 | 82 | ||
83 | m_gameOverTimer = new QTimer( this, "m_gameOverTimer" ); | 83 | m_gameOverTimer = new QTimer( this, "m_gameOverTimer" ); |
84 | connect( m_gameOverTimer, SIGNAL(timeout()), this, SLOT(gameOverNow()) ); | 84 | connect( m_gameOverTimer, SIGNAL(timeout()), this, SLOT(gameOverNow()) ); |
85 | 85 | ||
86 | m_timer = new QTimer( this, "m_timer" ); | 86 | m_timer = new QTimer( this, "m_timer" ); |
87 | connect( m_timer, SIGNAL(timeout()), this, SLOT(second()) ); | 87 | connect( m_timer, SIGNAL(timeout()), this, SLOT(second()) ); |
88 | 88 | ||
89 | // create demo game | 89 | // create demo game |
90 | createLevel( 1 ); | 90 | createLevel( 1 ); |
91 | } | 91 | } |
92 | 92 | ||
93 | void KJezzball::newGame() | 93 | void KJezzball::newGame() |
94 | { | 94 | { |
95 | // Check for running game | 95 | // Check for running game |
96 | closeGame(); | 96 | closeGame(); |
97 | if ( m_state==Idle ) | 97 | if ( m_state==Idle ) |
98 | { | 98 | { |
99 | // update displays | 99 | // update displays |
100 | m_game.level = 1; | 100 | m_game.level = 1; |
101 | m_game.score = 0; | 101 | m_game.score = 0; |
102 | 102 | ||
103 | setCaption(tr("Bounce Level %1").arg(m_game.level)); | 103 | setCaption(tr("Bounce Level %1").arg(m_game.level)); |
104 | ScoreLabel->setText( tr( "Score: %1" ).arg(m_game.score) ); | 104 | ScoreLabel->setText( tr( "Score: %1" ).arg(m_game.score) ); |
105 | 105 | ||
106 | // start new game | 106 | // start new game |
107 | m_state = Running; | 107 | m_state = Running; |
108 | 108 | ||
109 | createLevel( m_game.level ); | 109 | createLevel( m_game.level ); |
110 | startLevel(); | 110 | startLevel(); |
111 | } | 111 | } |
112 | } | 112 | } |
113 | 113 | ||
114 | void KJezzball::about() | 114 | void KJezzball::about() |
115 | { | 115 | { |
116 | QMessageBox::information( this, "About", "Written by: Stefan Schimanski\nPorted by: Martin Imobersteg\n\nThis program is distributed under\nthe terms of the GPL v2." ); | 116 | QMessageBox::information( this, "About", |
117 | "Written by: Stefan Schimanski\n" | ||
118 | "Ported by: Martin Imobersteg\n" | ||
119 | "\n" | ||
120 | "Click to form walls.\n" | ||
121 | "Hit space to switch wall direction.\n" | ||
122 | "Try to reduce total space by 75%.\n" | ||
123 | "\n" | ||
124 | "This program is distributed under\n" | ||
125 | "the terms of the GPL v2." ); | ||
117 | } | 126 | } |
118 | 127 | ||
119 | void KJezzball::closeGame() | 128 | void KJezzball::closeGame() |
120 | { | 129 | { |
121 | if ( m_state!=Idle ) | 130 | if ( m_state!=Idle ) |
122 | { | 131 | { |
123 | stopLevel(); | 132 | stopLevel(); |
124 | m_state = Idle; | 133 | m_state = Idle; |
125 | } | 134 | } |
126 | } | 135 | } |
127 | 136 | ||
128 | void KJezzball::pauseGame() | 137 | void KJezzball::pauseGame() |
129 | { | 138 | { |
130 | switch ( m_state ) | 139 | switch ( m_state ) |
131 | { | 140 | { |
132 | case Running: | 141 | case Running: |
133 | m_state = Paused; | 142 | m_state = Paused; |
134 | m_gameWidget->display( tr("Game paused.\nPress P to continue!") ); | 143 | m_gameWidget->display( tr("Game paused.\nPress P to continue!") ); |
135 | stopLevel(); | 144 | stopLevel(); |
136 | break; | 145 | break; |
137 | 146 | ||
138 | case Paused: | 147 | case Paused: |
139 | case Suspend: | 148 | case Suspend: |
140 | m_state = Running; | 149 | m_state = Running; |
141 | m_gameWidget->display( QString::null ); | 150 | m_gameWidget->display( QString::null ); |
142 | startLevel(); | 151 | startLevel(); |
143 | break; | 152 | break; |
144 | 153 | ||
145 | case Idle: | 154 | case Idle: |
146 | break; | 155 | break; |
147 | } | 156 | } |
148 | } | 157 | } |
149 | 158 | ||
150 | void KJezzball::gameOver() | 159 | void KJezzball::gameOver() |
151 | { | 160 | { |
152 | stopLevel(); | 161 | stopLevel(); |
153 | m_gameOverTimer->start( 100, TRUE ); | 162 | m_gameOverTimer->start( 100, TRUE ); |
154 | } | 163 | } |
155 | 164 | ||
156 | 165 | ||
157 | void KJezzball::gameOverNow() | 166 | void KJezzball::gameOverNow() |
158 | { | 167 | { |
159 | m_state = Idle; | 168 | m_state = Idle; |
160 | 169 | ||
161 | QString score; | 170 | QString score; |
162 | score.setNum( m_game.score ); | 171 | score.setNum( m_game.score ); |
163 | QMessageBox::information( this, "Game Over", tr("Game Over!\nScore: %1").arg(score) ); | 172 | QMessageBox::information( this, "Game Over", tr("Game Over!\nScore: %1").arg(score) ); |
164 | } | 173 | } |
165 | 174 | ||
166 | void KJezzball::focusOutEvent( QFocusEvent *ev ) | 175 | void KJezzball::focusOutEvent( QFocusEvent *ev ) |
167 | { | 176 | { |
168 | if ( m_state==Running ) | 177 | if ( m_state==Running ) |
169 | { | 178 | { |
170 | stopLevel(); | 179 | stopLevel(); |
171 | m_state = Suspend; | 180 | m_state = Suspend; |
172 | } | 181 | } |
173 | 182 | ||
174 | QMainWindow::focusOutEvent( ev ); | 183 | QMainWindow::focusOutEvent( ev ); |
175 | } | 184 | } |
176 | 185 | ||
177 | void KJezzball::focusInEvent ( QFocusEvent *ev ) | 186 | void KJezzball::focusInEvent ( QFocusEvent *ev ) |
178 | { | 187 | { |
179 | if ( m_state==Suspend ) | 188 | if ( m_state==Suspend ) |
180 | { | 189 | { |
181 | startLevel(); | 190 | startLevel(); |
182 | m_state = Running; | 191 | m_state = Running; |
183 | } | 192 | } |
184 | 193 | ||
185 | QMainWindow::focusInEvent( ev ); | 194 | QMainWindow::focusInEvent( ev ); |
186 | } | 195 | } |
187 | 196 | ||
188 | void KJezzball::second() | 197 | void KJezzball::second() |
189 | { | 198 | { |
190 | m_level.time--; | 199 | m_level.time--; |
191 | TimeLabel->setText( tr( "Time: %1" ).arg(m_level.time) ); | 200 | TimeLabel->setText( tr( "Time: %1" ).arg(m_level.time) ); |
192 | if ( m_level.time<=0 ) | 201 | if ( m_level.time<=0 ) |
193 | { | 202 | { |
194 | gameOver(); | 203 | gameOver(); |
195 | } | 204 | } |
196 | } | 205 | } |
197 | 206 | ||
198 | void KJezzball::died() | 207 | void KJezzball::died() |
199 | { | 208 | { |
200 | m_level.lifes--; | 209 | m_level.lifes--; |
201 | LivesLabel->setText( tr( "Lives: %1" ).arg(m_level.lifes) ); | 210 | LivesLabel->setText( tr( "Lives: %1" ).arg(m_level.lifes) ); |
202 | if ( m_level.lifes==0 ) gameOver(); | 211 | if ( m_level.lifes==0 ) gameOver(); |
203 | } | 212 | } |
204 | 213 | ||
205 | void KJezzball::newPercent( int percent ) | 214 | void KJezzball::newPercent( int percent ) |
206 | { | 215 | { |
207 | FilledLabel->setText( tr( "Filled: %1%" ).arg(percent) ); | 216 | FilledLabel->setText( tr( "Filled: %1%" ).arg(percent) ); |
208 | if ( percent>=75 ) | 217 | if ( percent>=75 ) |
209 | { | 218 | { |
210 | m_level.score = m_level.lifes*15 + (percent-75)*2*(m_game.level+5); | 219 | m_level.score = m_level.lifes*15 + (percent-75)*2*(m_game.level+5); |
211 | nextLevel(); | 220 | nextLevel(); |
212 | } | 221 | } |
213 | } | 222 | } |
214 | 223 | ||
215 | void KJezzball::createLevel( int level ) | 224 | void KJezzball::createLevel( int level ) |
216 | { | 225 | { |
217 | // destroy old game | 226 | // destroy old game |
218 | if ( m_gameWidget ) delete m_gameWidget; | 227 | if ( m_gameWidget ) delete m_gameWidget; |
219 | 228 | ||
220 | m_gameWidget = new JezzGame( level+1, m_view, "m_gameWidget" ); | 229 | m_gameWidget = new JezzGame( level+1, m_view, "m_gameWidget" ); |
221 | 230 | ||
222 | m_gameWidget->show(); | 231 | m_gameWidget->show(); |
223 | m_layout->addMultiCellWidget( m_gameWidget, 0, 0, 0, 3 ); | 232 | m_layout->addMultiCellWidget( m_gameWidget, 0, 0, 0, 3 ); |
224 | connect( m_gameWidget, SIGNAL(died()), this, SLOT(died()) ); | 233 | connect( m_gameWidget, SIGNAL(died()), this, SLOT(died()) ); |
225 | connect( m_gameWidget, SIGNAL(newPercent(int)), this, SLOT(newPercent(int)) ); | 234 | connect( m_gameWidget, SIGNAL(newPercent(int)), this, SLOT(newPercent(int)) ); |
226 | 235 | ||
227 | // update displays | 236 | // update displays |
228 | m_level.lifes = level+1; | 237 | m_level.lifes = level+1; |
229 | LivesLabel->setText( tr( "Lives: %1" ).arg(m_level.lifes) ); | 238 | LivesLabel->setText( tr( "Lives: %1" ).arg(m_level.lifes) ); |
230 | FilledLabel->setText( tr( "Filled: 0%" ) ); | 239 | FilledLabel->setText( tr( "Filled: 0%" ) ); |
231 | 240 | ||
232 | m_level.time = (level+2)*30; | 241 | m_level.time = (level+2)*30; |
233 | TimeLabel->setText( tr( "Time: %1" ).arg(m_level.time) ); | 242 | TimeLabel->setText( tr( "Time: %1" ).arg(m_level.time) ); |
234 | 243 | ||
235 | m_level.score = 0; | 244 | m_level.score = 0; |
236 | } | 245 | } |
237 | 246 | ||
238 | void KJezzball::startLevel() | 247 | void KJezzball::startLevel() |
239 | { | 248 | { |
240 | if ( m_gameWidget ) | 249 | if ( m_gameWidget ) |
241 | { | 250 | { |
242 | m_timer->start( 1000 ); | 251 | m_timer->start( 1000 ); |
243 | m_gameWidget->start(); | 252 | m_gameWidget->start(); |
244 | } | 253 | } |
245 | } | 254 | } |
246 | 255 | ||
247 | void KJezzball::stopLevel() | 256 | void KJezzball::stopLevel() |
248 | { | 257 | { |
249 | if ( m_gameWidget ) | 258 | if ( m_gameWidget ) |
250 | { | 259 | { |
251 | m_gameWidget->stop(); | 260 | m_gameWidget->stop(); |
252 | m_timer->stop(); | 261 | m_timer->stop(); |
253 | } | 262 | } |
254 | } | 263 | } |
255 | 264 | ||
256 | void KJezzball::nextLevel() | 265 | void KJezzball::nextLevel() |
257 | { | 266 | { |
258 | stopLevel(); | 267 | stopLevel(); |
259 | m_nextLevelTimer->start( 100, TRUE ); | 268 | m_nextLevelTimer->start( 100, TRUE ); |
260 | } | 269 | } |
261 | 270 | ||
262 | void KJezzball::switchLevel() | 271 | void KJezzball::switchLevel() |
263 | { | 272 | { |
264 | m_game.score += m_level.score; | 273 | m_game.score += m_level.score; |
265 | ScoreLabel->setText( tr( "Score: %1" ).arg(m_game.score) ); | 274 | ScoreLabel->setText( tr( "Score: %1" ).arg(m_game.score) ); |
266 | 275 | ||
267 | QString score; | 276 | QString score; |
268 | score.setNum( m_level.score ); | 277 | score.setNum( m_level.score ); |
269 | 278 | ||
270 | QString level; | 279 | QString level; |
271 | level.setNum( m_game.level ); | 280 | level.setNum( m_game.level ); |
272 | 281 | ||
273 | QString foo = QString( | 282 | QString foo = QString( |
274 | tr("Successfully cleared more than 75%.\n") + | 283 | tr("Successfully cleared more than 75%.\n") + |
275 | tr("%1 points: 15 points per life\n").arg(m_level.lifes*15) + | 284 | tr("%1 points: 15 points per life\n").arg(m_level.lifes*15) + |
276 | tr("%1 points: Bonus\n").arg((m_gameWidget->percent()-75)*2*(m_game.level+5)) + | 285 | tr("%1 points: Bonus\n").arg((m_gameWidget->percent()-75)*2*(m_game.level+5)) + |
277 | tr("%1 points: Total score\n").arg(score) + | 286 | tr("%1 points: Total score\n").arg(score) + |
278 | tr("On to level %1.\nYou get %2 lives this time!")).arg(m_game.level+1).arg(m_game.level+2); | 287 | tr("On to level %1.\nYou get %2 lives this time!")).arg(m_game.level+1).arg(m_game.level+2); |
279 | 288 | ||
280 | QMessageBox::information( this, "Success", foo ); | 289 | QMessageBox::information( this, "Success", foo ); |
281 | 290 | ||
282 | m_game.level++; | 291 | m_game.level++; |
283 | 292 | ||
284 | createLevel( m_game.level ); | 293 | createLevel( m_game.level ); |
285 | startLevel(); | 294 | startLevel(); |
286 | } | 295 | } |
287 | 296 | ||
288 | void KJezzball::keyPressEvent( QKeyEvent *ev ) | 297 | void KJezzball::keyPressEvent( QKeyEvent *ev ) |
289 | { | 298 | { |
290 | if ( ev->key() == Key_Space || | 299 | if ( ev->key() == Key_Space || |
291 | ev->key() == Key_Up || | 300 | ev->key() == Key_Up || |
292 | ev->key() == Key_Down || | 301 | ev->key() == Key_Down || |
293 | ev->key() == Key_Right || | 302 | ev->key() == Key_Right || |
294 | ev->key() == Key_Left ) | 303 | ev->key() == Key_Left ) |
295 | { | 304 | { |
296 | m_gameWidget->changeCursor(); | 305 | m_gameWidget->changeCursor(); |
297 | } | 306 | } |
298 | else | 307 | else |
299 | { | 308 | { |
300 | ev->ignore(); | 309 | ev->ignore(); |
301 | } | 310 | } |
302 | } | 311 | } |