changeset 242:12c4f87ea424

Unify doors a bit
author Neil Muller <neil@dip.sun.ac.za>
date Fri, 27 Aug 2010 11:32:49 +0200
parents b1451b0b906f
children 0ea4661d134c
files gamelib/scenes/bridge.py gamelib/scenes/crew_quarters.py gamelib/scenes/cryo.py gamelib/scenes/engine.py gamelib/scenes/machine.py gamelib/scenes/mess.py gamelib/scenes/scene_widgets.py
diffstat 7 files changed, 42 insertions(+), 42 deletions(-) [+]
line wrap: on
line diff
--- a/gamelib/scenes/bridge.py	Fri Aug 27 10:37:47 2010 +0200
+++ b/gamelib/scenes/bridge.py	Fri Aug 27 11:32:49 2010 +0200
@@ -4,6 +4,7 @@
 from gamelib.state import Scene, Item, Thing, Result, InteractText, \
                           InteractNoImage, InteractRectUnion
 from gamelib.statehelpers import GenericDescThing
+from gamelib.scenes.scene_widgets import Door
 
 class Bridge(Scene):
 
@@ -27,11 +28,9 @@
         return Result("The bridge is in a sorry, shabby state")
 
 
-class ToMap(Thing):
-    "Way to map."
+class ToMap(Door):
 
     NAME = "bridge.tomap"
-    DEST = "map"
 
     INTERACTS = {
         "door": InteractNoImage(707, 344, 84, 245),
@@ -39,10 +38,6 @@
 
     INITIAL = "door"
 
-    def interact_without(self):
-        """Go to map."""
-        self.state.set_current_scene("map")
-
 
 class BridgeComputer(Thing):
     """The bridge computer. Gives status updates"""
--- a/gamelib/scenes/crew_quarters.py	Fri Aug 27 10:37:47 2010 +0200
+++ b/gamelib/scenes/crew_quarters.py	Fri Aug 27 11:32:49 2010 +0200
@@ -2,6 +2,7 @@
 
 from gamelib.cursor import CursorSprite
 from gamelib.state import Scene, Item, Thing, Result, InteractText
+from gamelib.scenes.scene_widgets import Door
 
 class CrewQuarters(Scene):
 
@@ -14,16 +15,15 @@
 
     def __init__(self, state):
         super(CrewQuarters, self).__init__(state)
+        self.add_thing(ToMap())
 
     def enter(self):
         return Result("The crew were a messy bunch. Or maybe that's just the intervening centuries.")
 
 
-class ToMap(Thing):
-    "Way to map."
+class ToMap(Door):
 
     NAME = "crew.tomap"
-    DEST = "map"
 
     INTERACTS = {
         "door": InteractText(100, 200, "To Map"),
@@ -31,10 +31,6 @@
 
     INITIAL = "door"
 
-    def interact_without(self):
-        """Go to map."""
-        self.state.set_current_scene("map")
-
 
 class Safe(Thing):
     "A safe, for keeping things safe."
--- a/gamelib/scenes/cryo.py	Fri Aug 27 10:37:47 2010 +0200
+++ b/gamelib/scenes/cryo.py	Fri Aug 27 11:32:49 2010 +0200
@@ -10,6 +10,7 @@
                           InteractImage, InteractNoImage, InteractRectUnion, \
                           InteractAnimated
 from gamelib.statehelpers import GenericDescThing
+from gamelib.scenes.scene_widgets import Door
 from gamelib.constants import DEBUG
 from gamelib.scenes.game_constants import PLAYER_ID
 
@@ -268,7 +269,7 @@
                 ]), soundfile="clang2.ogg")
 
 
-class CryoRoomDoor(Thing):
+class CryoRoomDoor(Door):
     "Door to the cryo room."
 
     NAME = "cryo.door"
@@ -312,9 +313,6 @@
                     "The door resists. Try something else, perhaps?",
                     ]))
 
-    def is_interactive(self):
-        return True
-
     def half_open_door(self):
         self.set_data('door', "ajar")
         self.set_interact("ajar")
--- a/gamelib/scenes/engine.py	Fri Aug 27 10:37:47 2010 +0200
+++ b/gamelib/scenes/engine.py	Fri Aug 27 11:32:49 2010 +0200
@@ -1,6 +1,7 @@
 """Engine room where things need to be repaired."""
 
 from gamelib.state import Scene, Item, Thing, InteractText, Result
+from gamelib.scenes.scene_widgets import Door
 
 
 class Engine(Scene):
@@ -20,11 +21,9 @@
         return Result("Somewhere in the darkness the engine waits and bides its time.")
 
 
-class ToMap(Thing):
-    "Way to map."
+class ToMap(Door):
 
     NAME = "engine.tomap"
-    DEST = "map"
 
     INTERACTS = {
         "door": InteractText(100, 200, "To Map"),
@@ -32,9 +31,5 @@
 
     INITIAL = "door"
 
-    def interact_without(self):
-        """Go to map."""
-        self.state.set_current_scene("map")
-
 
 SCENES = [Engine]
--- a/gamelib/scenes/machine.py	Fri Aug 27 10:37:47 2010 +0200
+++ b/gamelib/scenes/machine.py	Fri Aug 27 11:32:49 2010 +0200
@@ -2,6 +2,7 @@
 
 from gamelib.state import Scene, Item, Thing, InteractText, Result
 from gamelib.cursor import CursorSprite
+from gamelib.scenes.scene_widgets import Door
 
 
 class Machine(Scene):
@@ -25,11 +26,9 @@
         return Result("The machine room is dark and forbidding.")
 
 
-class ToMap(Thing):
-    "Way to map."
+class ToMap(Door):
 
     NAME = "machine.tomap"
-    DEST = "map"
 
     INTERACTS = {
         "door": InteractText(100, 200, "To Map"),
@@ -37,10 +36,6 @@
 
     INITIAL = "door"
 
-    def interact_without(self):
-        """Go to map."""
-        self.state.set_current_scene("map")
-
 
 class LaserWelder(Thing):
 
--- a/gamelib/scenes/mess.py	Fri Aug 27 10:37:47 2010 +0200
+++ b/gamelib/scenes/mess.py	Fri Aug 27 11:32:49 2010 +0200
@@ -5,6 +5,7 @@
 from gamelib.state import Scene, Item, CloneableItem, Thing, InteractImage, InteractNoImage, Result
 from gamelib.statehelpers import GenericDescThing
 from gamelib.cursor import CursorSprite
+from gamelib.scenes.scene_widgets import Door
 
 
 class Mess(Scene):
@@ -195,11 +196,9 @@
                           " tape could actually be used to tape ducts?")
 
 
-class ToMap(Thing):
-    "Way to map."
+class ToMap(Door):
 
     NAME = "mess.tomap"
-    DEST = "map"
 
     INTERACTS = {
         "door": InteractNoImage(20, 390, 85, 150),
@@ -207,12 +206,5 @@
 
     INITIAL = "door"
 
-    def get_description(self):
-        return "A doorway leads out to the rest of the ship"
-
-    def interact_without(self):
-        """Go to map."""
-        self.state.set_current_scene("map")
-
 
 SCENES = [Mess]
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gamelib/scenes/scene_widgets.py	Fri Aug 27 11:32:49 2010 +0200
@@ -0,0 +1,29 @@
+"""Generic, game specific widgets"""
+
+import random
+
+from gamelib.state import Thing, Result
+
+
+class Door(Thing):
+    """A door somewhere"""
+
+    DEST = "map"
+
+    def is_interactive(self):
+        return True
+
+    def interact_without(self):
+        """Go to map."""
+        self.state.set_current_scene("map")
+
+    def get_description(self):
+        return 'An open doorway leads to the rest of the ship.'
+
+    def interact_default(self, item):
+        return Result(random.choice([
+            "Sadly, this isn't that sort of game.",
+            "Your valiant efforts are foiled by the Evil Game Designer.",
+            "Waving that in the doorway does nothing. Try something else, perhaps?",
+            ]))
+