-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayer.py
More file actions
166 lines (133 loc) · 4.99 KB
/
Copy pathplayer.py
File metadata and controls
166 lines (133 loc) · 4.99 KB
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
"""Billy in the Fat Lane - A Lame Life Simulation Game
Copyright (C) 2013 Chris Parlette, Matt Parlette
This file is part of Billy in the Fat Lane.
Billy in the Fat Lane is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Billy in the Fat Lane is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Billy in the Fat Lane. If not, see http://www.gnu.org/licenses/."""
from uuid import uuid4
class Player:
def __init__(self,name = "Player"):
self.name = name
self.id = uuid4()
self.location = None
self.job = None
self.turns = 0
self.completed_education = []
self.items = []
#Major Attributes
self.attributes = {"health": Health(10),
"knowledge": Knowledge(),
"happiness": Happiness(),
"money": Money(),
"time": Time(10)}
def __repr__(self):
return str(self.name)
def __eq__(self,other):
return self.id == other.id if hasattr(other,"id") else False
def move(self,new_location):
"""Change the player's location variable.
The validity of this move should be done before this function is called."""
self.location = new_location
return True
def info_display(self):
"""Return a string with an information display for this player"""
s = "%s\n%s\nLocation:\t%s\n" % (self.name,"=" * len(self.name),self.location.name)
if self.job:
s += "Job:\t\t%s at %s ($%s pay per unit)\n" % (str(self.job),str(self.job.location.name),str(self.job.pay))
else:
s += "Job:\t\tNone\n"
for attribute in self.attributes:
s += "%s:\t%s\n" % (str(self.attributes[attribute]),self.attributes[attribute].get())
s += "Current money:\t$%s\n" % (str(self.attributes['money'].get()))
s += "Classes:\n\t%s\n" % ("\n\t".join(self.completed_education) if self.completed_education else "None")
s += "Items:\n\t%s\n" % ("\n\t".join(str(x) for x in self.items) if self.items else "None")
return s
def get_happiness(self):
"""Set the happiness instance variable calculated by the player's attributes and return it.
WARNING: This method is deprecated. Use Player.happiness.get() instead."""
return self.happiness.get()
def add_item(self,new_item):
if new_item:
self.items.append(new_item)
def use_item(self,item):
"""
Use the item, applying its effects on this player instance.
If the item is consumable, then using the item removes it from the player's inventory.
"""
if item in self.items:
for attribute in item.effects:
if attribute in self.attributes:
self.attributes[attribute].set(delta=item.effects[attribute])
if item.consumable:
self.items.remove(item)
class Attribute(object):
def __init__(self,name="Attribute",value=0):
self.name = name
self.id = uuid4()
self.value = value
self.minor_attributes = None
def __repr__(self):
return str(self.name)
def __cmp__(self,other):
a = self.get()
b = other.get()
if a < b:
return -1
elif a > b:
return 1
else:
return 0
def set(self,value = 0, delta = 0):
"""Change the value of this attribute.
If value is provided, then the attriute value is set to this number.
Otherwise, if delta is provided, the attribute value will add this to its current value.
If neither is provided, then this method does nothing."""
if value:
self.value = value
elif delta:
self.value += delta
else:
return
def get(self):
"""Return the calculated value for this attribute."""
self.calculate()
return self.value
def calculate(self):
"""Override this method to define how this attribute's value is calculated.'"""
pass
class Happiness(Attribute):
def __init__(self,value=0):
super(Happiness,self).__init__("Happiness",value)
#Attribute.__init__(self,"Happiness",value)
def calculate(self):
pass
class Health(Attribute):
def __init__(self,value=0):
super(Health,self).__init__("Health",value)
#Attribute.__init__(self,"Health",value)
def calculate(self):
pass
class Knowledge(Attribute):
def __init__(self,value=0):
super(Knowledge,self).__init__("Knowledge",value)
#Attribute.__init__(self,"Knowledge",value)
def calculate(self):
pass
class Money(Attribute):
def __init__(self,value=0):
super(Money,self).__init__("Money",value)
#Attribute.__init__(self,"Money",value)
def calculate(self):
pass
class Time(Attribute):
def __init__(self,value=0):
super(Time,self).__init__("Time",value)
def calculate(self):
pass