diff 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
line wrap: on
line diff
--- a/gamelib/gamegui.py	Wed May 09 21:50:29 2012 +0200
+++ b/gamelib/gamegui.py	Wed May 09 22:03:07 2012 +0200
@@ -13,11 +13,12 @@
 
 from gamelib.data import filepath
 from gamelib.game_base import get_save_filename
-from gamelib.gui_base import Window, TextLabel, font_small, font_medium
+from gamelib.gui_base import (Window, TextLabel, font_small, font_medium,
+        font_large)
 from gamelib.gui import BigButton, ImageDrawable
-from gamelib.engine import PopWindow, AddWindow
+from gamelib.engine import PopWindow, AddWindow, GameOver
 from gamelib.constants import (WIDTH, FAILURE, SUCCESS, NEW_SCIENCE,
-        NEW_SCHEMATIC)
+        NEW_SCHEMATIC, GAME_WIN)
 from gamelib.gamestate import Game
 
 
@@ -263,6 +264,7 @@
         title = TextLabel((200, 20, 400, 50), "Results for turn %d" % turn,
                 font_medium, (255, 255, 255))
         self.add_child(title)
+        self.is_game_over = False
         if not messages:
             results = TextLabel((200, 200, 400, 50),
                     "Nothing of interest happened", font_medium,
@@ -281,12 +283,32 @@
                 elif msg_type == SUCCESS:
                     text = TextLabel((50, y, 750, 25),
                             msg, font_medium, (60, 255, 60))
+                elif msg_type == GAME_WIN:
+                    self._make_win_screen(turn, msg)
+                    self.is_game_over = True
+                    break
                 else:
                     text = TextLabel((50, y, 750, 25),
                             msg, font_medium, (255, 255, 0))
                 y += 50
                 self.add_child(text)
 
+    def _make_win_screen(self, turn, msg):
+        # Clear existing widgets, and turn this into a won screen
+        for child in self.children[:]:
+            self.remove_child(child)
+        exitbut = ExitGameButton()
+        self.add_child(exitbut)
+        title = TextLabel((200, 20, 400, 50), "Results for turn %d" % turn,
+                font_medium, (255, 255, 255))
+        self.add_child(title)
+        won = TextLabel((200, 200, 400, 50), "You've succeeded in your quest",
+                font_large, (255, 255, 255))
+        self.add_child(won)
+        won = TextLabel((200, 250, 400, 50), msg, font_large,
+                (255, 255, 255))
+        self.add_child(won)
+
 
 class ActivityWindow(Window):
 
@@ -526,6 +548,10 @@
         self.game.cur_missions = self.activity.get_mission_list()
         messages = self.game.end_turn()
         results = ResultsWindow(self.screen, messages, self.game.turn)
+        if results.is_game_over:
+            PopWindow.post()
+            GameOver.post(results)
+            return
         self.game.start_turn()
         self.update_labels()
         self.update_widgets()