Mercurial > sypikslang
comparison gamelib/gamegui.py @ 98:e386ec5d179b
The game can end
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Wed, 09 May 2012 22:03:07 +0200 |
parents | 069a2d34b8b5 |
children | 5977a709f8c8 |
comparison
equal
deleted
inserted
replaced
97:069a2d34b8b5 | 98:e386ec5d179b |
---|---|
11 import json | 11 import json |
12 | 12 |
13 | 13 |
14 from gamelib.data import filepath | 14 from gamelib.data import filepath |
15 from gamelib.game_base import get_save_filename | 15 from gamelib.game_base import get_save_filename |
16 from gamelib.gui_base import Window, TextLabel, font_small, font_medium | 16 from gamelib.gui_base import (Window, TextLabel, font_small, font_medium, |
17 font_large) | |
17 from gamelib.gui import BigButton, ImageDrawable | 18 from gamelib.gui import BigButton, ImageDrawable |
18 from gamelib.engine import PopWindow, AddWindow | 19 from gamelib.engine import PopWindow, AddWindow, GameOver |
19 from gamelib.constants import (WIDTH, FAILURE, SUCCESS, NEW_SCIENCE, | 20 from gamelib.constants import (WIDTH, FAILURE, SUCCESS, NEW_SCIENCE, |
20 NEW_SCHEMATIC) | 21 NEW_SCHEMATIC, GAME_WIN) |
21 from gamelib.gamestate import Game | 22 from gamelib.gamestate import Game |
22 | 23 |
23 | 24 |
24 class ExitGameButton(BigButton): | 25 class ExitGameButton(BigButton): |
25 | 26 |
261 exitbut = ExitGameButton() | 262 exitbut = ExitGameButton() |
262 self.add_child(exitbut) | 263 self.add_child(exitbut) |
263 title = TextLabel((200, 20, 400, 50), "Results for turn %d" % turn, | 264 title = TextLabel((200, 20, 400, 50), "Results for turn %d" % turn, |
264 font_medium, (255, 255, 255)) | 265 font_medium, (255, 255, 255)) |
265 self.add_child(title) | 266 self.add_child(title) |
267 self.is_game_over = False | |
266 if not messages: | 268 if not messages: |
267 results = TextLabel((200, 200, 400, 50), | 269 results = TextLabel((200, 200, 400, 50), |
268 "Nothing of interest happened", font_medium, | 270 "Nothing of interest happened", font_medium, |
269 (255, 255, 255)) | 271 (255, 255, 255)) |
270 self.add_child(results) | 272 self.add_child(results) |
279 text = TextLabel((50, y, 750, 25), | 281 text = TextLabel((50, y, 750, 25), |
280 msg, font_medium, (255, 60, 60)) | 282 msg, font_medium, (255, 60, 60)) |
281 elif msg_type == SUCCESS: | 283 elif msg_type == SUCCESS: |
282 text = TextLabel((50, y, 750, 25), | 284 text = TextLabel((50, y, 750, 25), |
283 msg, font_medium, (60, 255, 60)) | 285 msg, font_medium, (60, 255, 60)) |
286 elif msg_type == GAME_WIN: | |
287 self._make_win_screen(turn, msg) | |
288 self.is_game_over = True | |
289 break | |
284 else: | 290 else: |
285 text = TextLabel((50, y, 750, 25), | 291 text = TextLabel((50, y, 750, 25), |
286 msg, font_medium, (255, 255, 0)) | 292 msg, font_medium, (255, 255, 0)) |
287 y += 50 | 293 y += 50 |
288 self.add_child(text) | 294 self.add_child(text) |
295 | |
296 def _make_win_screen(self, turn, msg): | |
297 # Clear existing widgets, and turn this into a won screen | |
298 for child in self.children[:]: | |
299 self.remove_child(child) | |
300 exitbut = ExitGameButton() | |
301 self.add_child(exitbut) | |
302 title = TextLabel((200, 20, 400, 50), "Results for turn %d" % turn, | |
303 font_medium, (255, 255, 255)) | |
304 self.add_child(title) | |
305 won = TextLabel((200, 200, 400, 50), "You've succeeded in your quest", | |
306 font_large, (255, 255, 255)) | |
307 self.add_child(won) | |
308 won = TextLabel((200, 250, 400, 50), msg, font_large, | |
309 (255, 255, 255)) | |
310 self.add_child(won) | |
289 | 311 |
290 | 312 |
291 class ActivityWindow(Window): | 313 class ActivityWindow(Window): |
292 | 314 |
293 def __init__(self, screen, lab, develop): | 315 def __init__(self, screen, lab, develop): |
524 | 546 |
525 def end_turn(self): | 547 def end_turn(self): |
526 self.game.cur_missions = self.activity.get_mission_list() | 548 self.game.cur_missions = self.activity.get_mission_list() |
527 messages = self.game.end_turn() | 549 messages = self.game.end_turn() |
528 results = ResultsWindow(self.screen, messages, self.game.turn) | 550 results = ResultsWindow(self.screen, messages, self.game.turn) |
551 if results.is_game_over: | |
552 PopWindow.post() | |
553 GameOver.post(results) | |
554 return | |
529 self.game.start_turn() | 555 self.game.start_turn() |
530 self.update_labels() | 556 self.update_labels() |
531 self.update_widgets() | 557 self.update_widgets() |
532 self.develop.update_widgets() | 558 self.develop.update_widgets() |
533 self.activity.update_widgets() | 559 self.activity.update_widgets() |