-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpdxgame.py
124 lines (99 loc) · 3.33 KB
/
pdxgame.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import random
# Basic class for user-created player.
class Player():
def __init__(self, name):
self.hp = 90
self.name = name
def increase_hp(self, hp):
self.hp += hp
def decrease_hp(self, hp):
self.hp -= hp
# Different types of players user can choose.
class Hipster(Player):
def __init__(self, name):
Player.__init__(self, name)
self.hp += random.randint(20, 50)
class Panhandler(Player):
def __init__(self, name):
Player.__init__(self, name)
self.hp += random.randint(5, 15)
class Vegan(Player):
def __init__(self, name):
Player.__init__(self, name)
self.hp += random.randint(15, 30)
class BeardedTechie(Player):
def __init__(self, name):
Player.__init__(self, name)
self.hp += random.randint(5, 50)
# Tiles for the player's location.
class Tile():
def __init__(self, exits):
self.exits = exits
# Method to move to different tiles in the game.
def tile_change(tile):
tiles = ''
for x in tile.exits.keys():
tiles += x + ' '
try:
tile_choice = raw_input("Where do you want to go? %s > " % tiles)
move(tile.exits[tile_choice], player)
except KeyError:
print "I do not understand that."
tile_change(tile)
# Creates random outcomes for the player in a new tile.
def randomizer(player):
response = [ "Rain", "a Canvasser", "the Naked Bike Ride", "Bike Messengers", "Rush Hour",
"a Free Box", "Freak Sunshine", "Coffee and Donuts", "a Thrift Store Find",
"Free Hugs" ]
response_num = random.randint(0,9)
if response_num > 4:
player.increase_hp(10)
else:
player.decrease_hp(10)
print "You have %s hipster points." % player.hp
return response[response_num]
def choose_player():
player_type = raw_input(""" What type of Portlander are you? Choose:
0 for hipster
1 for vegan
2 for panhandler
3 for bearded techie """)
player_name = raw_input("And what do you like to be called? ")
return player_type, player_name
def move(tile, player):
obstacle = randomizer(player)
print "Guess what? You ran into " + obstacle + ". How Portland!"
tile_change(tile)
player_type, player_name = choose_player()
if player_type == "0":
player = Hipster(player_name)
chosen_type = "Hipster"
elif player_type == "1":
player = Vegan(player_name)
chosen_type = "Vegan"
elif player_type == "2":
player = Panhandler(player_name)
chosen_type = "Panhandler"
elif player_type == "3":
player = BeardedTechie(player_name)
chosen_type = "Bearded Techie"
else:
print "Sorry, there are no other options."
print "Hi, %s. Isn't it great to be a %s?" % (player_name, chosen_type) + " You are starting with " + str(player.hp) + " hipster points."
tile1 = Tile( {} )
tile2 = Tile( {} )
tile3 = Tile( {} )
tile4 = Tile( {} )
tile5 = Tile( {} )
tile1.exits = {"NE": tile5}
tile2.exits = {"N": tile1}
tile3.exits = {"SE": tile2}
tile4.exits = {"SW": tile3}
tile5.exits = {"NW": tile4}
move(tile1, player)
if player.hp == 150:
print "You are the ultimate Portlander and YOU WIN!"
quit()
elif player.hp == 80:
print "Sorry, you lose. Go back to California."
quit()