forked from dcbriccetti/python-lessons
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathship_game.py
57 lines (43 loc) · 2.18 KB
/
ship_game.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from engine.game import Game
from engine.inventory_item import InventoryItem
from engine.place import Place
from engine.event import Event
from engine.transition import Transition as T
class ShipGame(Game):
def __init__(self):
super(ShipGame, self).__init__()
self.introduction = 'Welcome to Ship Adventure. You are the captain of a star ship.'
bridge = Place('Bridge',
"You are on the bridge of a spaceship, sitting in the captain's chair.", (
Event(0.01, 'An intruder beams onto the bridge and shoots you.', -50, max_occurrences=1),
Event(0.1, "The ship's doctor gives you a health boost.", 30),
))
ready_room = Place('Ready Room', "You are in the captain's ready room.", (
Event(.5, 'The fish in the aquarium turn to watch you', 0, max_occurrences=1),
))
lift = Place('Lift', 'You have entered the turbolift.', (
Event(.1, "The ship's android says hello to you.", 1),
))
lounge = Place('Lounge', 'Welcome to the lounge.', (
Event(1, 'Relaxing in the lounge improves your health.', 10),
))
space_suit = InventoryItem('Spacesuit')
storage_room = Place('Storage Room', 'You enter the storage room',
inventory_items=[space_suit])
transporter_room = Place('Transporter Room',
'The transporter room looks cool with all its blinking lights and sliders.')
planet = Place('Planet', 'You have beamed down to the planet.', (
Event(.3, 'You found the experience relaxing', +10),
))
def mt(places): # Make Transitions
return [T(place) for place in places]
bridge .transitions = mt((ready_room, lift))
ready_room .transitions = mt((bridge,))
lift .transitions = mt((bridge, lounge, storage_room, transporter_room))
lounge .transitions = mt((lift,))
storage_room .transitions = mt((lift,))
transporter_room.transitions = (T(planet, (space_suit,)), T(lift))
planet .transitions = mt((transporter_room,))
self.location = bridge
game = ShipGame()
game.play()