Skip to content

Commit 275dcbe

Browse files
Added a save/load system at the beginning, found another bug and made some other tweaks
1 parent ed7f89c commit 275dcbe

File tree

2 files changed

+48
-3
lines changed

2 files changed

+48
-3
lines changed

main.py

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
class Game(object):
55

6+
rawFile = ("savefile.txt")
7+
68
def __init__(self):
79
self.currentLocation = "home"
810
self.times = {0: "12:00 AM",
@@ -42,6 +44,35 @@ def __init__(self):
4244

4345
self.divider = "-" * 60
4446

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 "\nThat isn't an option!"
74+
self.play()
75+
4576
def increaseTime(self):
4677

4778
self.currentTime = self.currentTime + 1
@@ -123,13 +154,17 @@ def getInput(self):
123154

124155
if decision == '1':
125156
return "fish"
157+
126158
elif decision == '2':
127159
return "store"
160+
128161
elif decision == '3':
129162
return "home"
163+
164+
# for some reason this else statement breaks the program. Will figure out later.
130165
else:
131166
raw_input("That wasn't an option! [ENTER TO CONTINUE]")
132-
self.getInput()
167+
self.dealWithInput()
133168

134169
if self.currentLocation == "store":
135170

@@ -187,6 +222,13 @@ def dealWithInput(self):
187222

188223
self.day = self.day + 1
189224

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+
190232
raw_input("\n\n[CONTINUE]")
191233

192234
self.dealWithInput()
@@ -209,7 +251,7 @@ def dealWithInput(self):
209251
elif self.playerInput == "browse":
210252
print "\n"
211253
print self.divider
212-
print "\nUnfortunately, they're out of fishing poles!"
254+
print "\nUnfortunately, there is nothing for sale here."
213255
print "\nYou sell %d fish for $%d" % (self.fish, self.fish * 2)
214256

215257
self.money = self.money + (self.fish * 2)
@@ -260,4 +302,4 @@ def dealWithInput(self):
260302
if __name__ == "__main__":
261303

262304
myGame = Game()
263-
myGame.dealWithInput()
305+
myGame.play()

savefile.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
3
2+
0
3+
0

0 commit comments

Comments
 (0)