Diffstat (limited to 'noncore/games/snake/interface.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/games/snake/interface.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/noncore/games/snake/interface.cpp b/noncore/games/snake/interface.cpp index 0f312ac..68e0f14 100644 --- a/noncore/games/snake/interface.cpp +++ b/noncore/games/snake/interface.cpp | |||
@@ -79,49 +79,49 @@ void SnakeGame::resizeEvent(QResizeEvent *) | |||
79 | int fw = style().defaultFrameWidth(); | 79 | int fw = style().defaultFrameWidth(); |
80 | canvas.resize( s.width() - fw - 2, s.height() - fw - 2); | 80 | canvas.resize( s.width() - fw - 2, s.height() - fw - 2); |
81 | } | 81 | } |
82 | 82 | ||
83 | void SnakeGame::welcomescreen() | 83 | void SnakeGame::welcomescreen() |
84 | { | 84 | { |
85 | QCanvasText* title = new QCanvasText(tr("SNAKE!"), &canvas); | 85 | QCanvasText* title = new QCanvasText(tr("SNAKE!"), &canvas); |
86 | title->setColor(yellow); | 86 | title->setColor(yellow); |
87 | title->setFont( QFont("times", 18, QFont::Bold) ); | 87 | title->setFont( QFont("times", 18, QFont::Bold) ); |
88 | int w = title->boundingRect().width(); | 88 | int w = title->boundingRect().width(); |
89 | title->move(canvas.width()/2 -w/2, canvas.height()/2-110); | 89 | title->move(canvas.width()/2 -w/2, canvas.height()/2-110); |
90 | title->show(); | 90 | title->show(); |
91 | QCanvasPixmapArray* titlearray = new QCanvasPixmapArray(Resource::findPixmap("snake/title")); | 91 | QCanvasPixmapArray* titlearray = new QCanvasPixmapArray(Resource::findPixmap("snake/title")); |
92 | QCanvasSprite* titlepic = new QCanvasSprite(titlearray, &canvas); | 92 | QCanvasSprite* titlepic = new QCanvasSprite(titlearray, &canvas); |
93 | titlepic->move(canvas.width()/2 - 33, canvas.height()/2-85); | 93 | titlepic->move(canvas.width()/2 - 33, canvas.height()/2-85); |
94 | titlepic->show(); | 94 | titlepic->show(); |
95 | QCanvasText* instr = new QCanvasText(tr("Use the arrow keys to guide the\n" | 95 | QCanvasText* instr = new QCanvasText(tr("Use the arrow keys to guide the\n" |
96 | "snake to eat the mouse. You must not\n" | 96 | "snake to eat the mouse. You must not\n" |
97 | "crash into the walls, edges or its tail."), | 97 | "crash into the walls, edges or its tail."), |
98 | &canvas); | 98 | &canvas); |
99 | w = instr->boundingRect().width(); | 99 | w = instr->boundingRect().width(); |
100 | instr->move(canvas.width()/2-w/2, canvas.height()/2-20); | 100 | instr->move(canvas.width()/2-w/2, canvas.height()/2-20); |
101 | instr->setColor(white); | 101 | instr->setColor(white); |
102 | instr->show(); | 102 | instr->show(); |
103 | QCanvasText* cont = new QCanvasText(tr("Press Any Key To Start"), &canvas); | 103 | QCanvasText* cont = new QCanvasText(tr("Press any key to start"), &canvas); |
104 | w = cont->boundingRect().width(); | 104 | w = cont->boundingRect().width(); |
105 | cont->move(canvas.width()/2-w/2, canvas.height()-20); | 105 | cont->move(canvas.width()/2-w/2, canvas.height()-20); |
106 | cont->setColor(yellow); | 106 | cont->setColor(yellow); |
107 | cont->show(); | 107 | cont->show(); |
108 | 108 | ||
109 | } | 109 | } |
110 | 110 | ||
111 | void SnakeGame::newGame() | 111 | void SnakeGame::newGame() |
112 | { | 112 | { |
113 | clear(); | 113 | clear(); |
114 | snake = new Snake(&canvas); | 114 | snake = new Snake(&canvas); |
115 | connect(snake, SIGNAL(dead()), this, SLOT(gameOver()) ); | 115 | connect(snake, SIGNAL(dead()), this, SLOT(gameOver()) ); |
116 | connect(snake, SIGNAL(targethit()), this, SLOT(levelUp()) ); | 116 | connect(snake, SIGNAL(targethit()), this, SLOT(levelUp()) ); |
117 | connect(snake, SIGNAL(scorechanged()), this, SLOT(scoreInc()) ); | 117 | connect(snake, SIGNAL(scorechanged()), this, SLOT(scoreInc()) ); |
118 | connect(this, SIGNAL(moveFaster()), snake, SLOT(increaseSpeed()) ); | 118 | connect(this, SIGNAL(moveFaster()), snake, SLOT(increaseSpeed()) ); |
119 | last = 0; | 119 | last = 0; |
120 | targetamount = 1; | 120 | targetamount = 1; |
121 | notargets = 1; | 121 | notargets = 1; |
122 | level = 1; | 122 | level = 1; |
123 | stage = 1; | 123 | stage = 1; |
124 | showScore(0); | 124 | showScore(0); |
125 | gamestopped = false; | 125 | gamestopped = false; |
126 | waitover = true; | 126 | waitover = true; |
127 | int y = canvas.height()-50; | 127 | int y = canvas.height()-50; |
@@ -175,47 +175,47 @@ void SnakeGame::clear() | |||
175 | } | 175 | } |
176 | 176 | ||
177 | void SnakeGame::gameOver() | 177 | void SnakeGame::gameOver() |
178 | { | 178 | { |
179 | int score = snake->getScore(); | 179 | int score = snake->getScore(); |
180 | QString scoreoutput=""; | 180 | QString scoreoutput=""; |
181 | scoreoutput.setNum(score); | 181 | scoreoutput.setNum(score); |
182 | QCanvasText* gameover = new QCanvasText(tr("GAME OVER!\n Your Score: %1").arg( scoreoutput), &canvas); | 182 | QCanvasText* gameover = new QCanvasText(tr("GAME OVER!\n Your Score: %1").arg( scoreoutput), &canvas); |
183 | 183 | ||
184 | gameover->setZ(100); | 184 | gameover->setZ(100); |
185 | gameover->setColor(yellow); | 185 | gameover->setColor(yellow); |
186 | gameover->setFont( QFont("times", 18, QFont::Bold) ); | 186 | gameover->setFont( QFont("times", 18, QFont::Bold) ); |
187 | int w = gameover->boundingRect().width(); | 187 | int w = gameover->boundingRect().width(); |
188 | gameover->move(canvas.width()/2 -w/2, canvas.height()/2 -50); | 188 | gameover->move(canvas.width()/2 -w/2, canvas.height()/2 -50); |
189 | gameover->show(); | 189 | gameover->show(); |
190 | gamestopped = true; | 190 | gamestopped = true; |
191 | waitover = false; | 191 | waitover = false; |
192 | pauseTimer->start(1500); | 192 | pauseTimer->start(1500); |
193 | } | 193 | } |
194 | 194 | ||
195 | void SnakeGame::wait() | 195 | void SnakeGame::wait() |
196 | { | 196 | { |
197 | waitover = true; | 197 | waitover = true; |
198 | pauseTimer->stop(); | 198 | pauseTimer->stop(); |
199 | QCanvasText* cont = new QCanvasText(tr("Press Any Key to Begin a New Game."), | 199 | QCanvasText* cont = new QCanvasText(tr("Press any key to begin a new game."), |
200 | &canvas); | 200 | &canvas); |
201 | cont->setZ(100); | 201 | cont->setZ(100); |
202 | cont->setColor(white); | 202 | cont->setColor(white); |
203 | int w = cont->boundingRect().width(); | 203 | int w = cont->boundingRect().width(); |
204 | cont->move(canvas.width()/2 -w/2, canvas.height()/2); | 204 | cont->move(canvas.width()/2 -w/2, canvas.height()/2); |
205 | cont->show(); | 205 | cont->show(); |
206 | } | 206 | } |
207 | 207 | ||
208 | void SnakeGame::keyPressEvent(QKeyEvent* event) | 208 | void SnakeGame::keyPressEvent(QKeyEvent* event) |
209 | { | 209 | { |
210 | if (gamestopped) { | 210 | if (gamestopped) { |
211 | if (waitover) | 211 | if (waitover) |
212 | newGame(); | 212 | newGame(); |
213 | else | 213 | else |
214 | return; | 214 | return; |
215 | } | 215 | } |
216 | else { | 216 | else { |
217 | int newkey = event->key(); | 217 | int newkey = event->key(); |
218 | snake->go(newkey); | 218 | snake->go(newkey); |
219 | } | 219 | } |
220 | } | 220 | } |
221 | 221 | ||