3
3
4
4
class Game (object ):
5
5
6
+ rawFile = ("savefile.txt" )
7
+
6
8
def __init__ (self ):
7
9
self .currentLocation = "home"
8
10
self .times = {0 : "12:00 AM" ,
@@ -42,6 +44,35 @@ def __init__(self):
42
44
43
45
self .divider = "-" * 60
44
46
47
+ def play (self ):
48
+ print self .divider + "\n "
49
+ print "Welcome to FishE!\n "
50
+ print "[1] NEW GAME"
51
+ print "[2] LOAD GAME"
52
+ print "\n " + self .divider
53
+
54
+ self .beginningOption = raw_input ("\n > " )
55
+
56
+ if self .beginningOption == "1" :
57
+ self .dealWithInput ()
58
+
59
+ elif self .beginningOption == "2" :
60
+
61
+ with open (self .rawFile ) as f : # opens the file and puts its contents into a list
62
+ self .content = f .readlines ()
63
+
64
+ self .content = [line .strip () for line in self .content ] # strips lists of any whitespace
65
+
66
+ self .day = int (self .content [0 ])
67
+ self .money = int (self .content [1 ])
68
+ self .fish = int (self .content [2 ])
69
+
70
+ self .dealWithInput ()
71
+
72
+ else :
73
+ print "\n That isn't an option!"
74
+ self .play ()
75
+
45
76
def increaseTime (self ):
46
77
47
78
self .currentTime = self .currentTime + 1
@@ -123,13 +154,17 @@ def getInput(self):
123
154
124
155
if decision == '1' :
125
156
return "fish"
157
+
126
158
elif decision == '2' :
127
159
return "store"
160
+
128
161
elif decision == '3' :
129
162
return "home"
163
+
164
+ # for some reason this else statement breaks the program. Will figure out later.
130
165
else :
131
166
raw_input ("That wasn't an option! [ENTER TO CONTINUE]" )
132
- self .getInput ()
167
+ self .dealWithInput ()
133
168
134
169
if self .currentLocation == "store" :
135
170
@@ -187,6 +222,13 @@ def dealWithInput(self):
187
222
188
223
self .day = self .day + 1
189
224
225
+ # save important bits to savefile
226
+ self .theFile = open (self .rawFile , 'w' )
227
+
228
+ self .theFile .write ("%d" % self .day )
229
+ self .theFile .write ("\n %d" % self .money )
230
+ self .theFile .write ("\n %d" % self .fish )
231
+
190
232
raw_input ("\n \n [CONTINUE]" )
191
233
192
234
self .dealWithInput ()
@@ -209,7 +251,7 @@ def dealWithInput(self):
209
251
elif self .playerInput == "browse" :
210
252
print "\n "
211
253
print self .divider
212
- print "\n Unfortunately, they're out of fishing poles! "
254
+ print "\n Unfortunately, there is nothing for sale here. "
213
255
print "\n You sell %d fish for $%d" % (self .fish , self .fish * 2 )
214
256
215
257
self .money = self .money + (self .fish * 2 )
@@ -260,4 +302,4 @@ def dealWithInput(self):
260
302
if __name__ == "__main__" :
261
303
262
304
myGame = Game ()
263
- myGame .dealWithInput ()
305
+ myGame .play ()
0 commit comments