-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpythonshineFriday.py
405 lines (355 loc) · 14.1 KB
/
pythonshineFriday.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
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
# PYTHON LOL (Name a Work in Progess)
# Created by Evan Chisholm and Alex Land
import random
import turtle as t
# VARIABLES
godMode = ""
playerPos = -1
biomeData = []
biomeDiamonds = []
biomeSwords = []
biomeEnemies = []
localList = []
fillColor = "tan"
catastropheNumber = 0
pythonShine = ""
playerName = ""
startGame = ""
playerHealth = 0
catastrophe = ""
maximumTurns = 0
turnNumber = 0
playerSword = 0
playerDiamonds = 0
roundOn = False
playerPosInput = ""
gameOn = True
gameOnInput = ""
catastrophePos = ""
biomeList = []
t.speed(0)
# FUNCTIONS
def gameStart():
global startGame
counter = 0
while startGame != "y":
startGame = raw_input("Would you like to play a game (y/n)? ")
if startGame != "y":
print "Please enter y to play."
counter += 1
if counter >= 5:
print "Think you're funny? You're not."
global godMode
while godMode == "":
godModeInput = raw_input("Would you like to manually choose biomes (y/n)? ")
if godModeInput == "y" or godModeInput == "yes":
godMode = True
elif godModeInput == "n" or godModeInput == "no":
godMode = False
else:
print "Please enter y for yes or n for no."
def enterInfo():
global playerHealth
while playerHealth < 10 or playerHealth > 50:
if godMode == True:
playerHealth = input("What is your initial health? (Pick a number between 10 and 50) ")
if playerHealth < 10 or playerHealth > 50:
print "Please pick a value between 10 and 50."
if godMode == False:
playerHealth = 10* (random.randint(1,5))
global playerName
while playerName == "":
playerName = raw_input("What is the name of your character? ")
global maximumTurns
while maximumTurns <= 0:
maximumTurns = input("How many turns do you want to play (maximum)? ")
if maximumTurns <= 0:
print "Please input a value greater than 0."
global playerPos
playerPos = 0
global roundOn
roundOn = True
def turnGenerator():
global playerPos
global turnNumber
global playerPosInput
if turnNumber >= 0:
if godMode == True:
playerPos = input("Which biome would you like to go to (Pick a number between 1 and 7)? ")
while playerPos <= 0 or playerPos > 7:
print "Please input a value between 1 and 7."
playerPos = input("Which biome would you like to go to (Pick a number between 1 and 7)? ")
if godMode == False:
playerPosInput = raw_input("Are you ready for the next turn? (y/n) ")
if playerPosInput == "y":
playerPos = ((playerPos + random.randint(1,6)) % (len(biomeList)))
elif playerPosInput != "y":
print "Tricked you, there was never a choice."
playerPos = ((playerPos + random.randint(1,6)) % (len(biomeList)))
turnNumber += 1
print "Starting turn number", turnNumber
print playerName, "has travelled to position", playerPos
def biomeDraw(fillColor):
t.fillcolor(fillColor)
t.begin_fill()
t.forward(50)
t.left(90)
t.forward(100)
t.left(90)
t.forward(50)
t.left(90)
t.forward(100)
t.left(90)
t.end_fill()
t.forward(70)
def playerDraw():
t.fillcolor("red")
t.begin_fill()
t.circle(10)
t.end_fill()
def drawBoard():
global catastropheNumber
t.penup()
t.forward(-300)
t.pendown()
for i in range((8 - catastropheNumber)):
if i == pythonShine and godMode == True:
biomeDraw("green")
else:
biomeDraw("tan")
t.home()
def drawPlayer():
global playerPos
t.penup()
t.forward(-275)
t.right(90)
t.forward(50)
t.left(90)
if playerPos >= 0:
t.forward((playerPos) * 70)
playerDraw()
def readFile(the_file):
'''
CODE PROVIDED TO INCORPORATE
<file-name including extension .txt>(String) --> List of strings
Assumptions:
1) the_file is in the same directory as this program
2) the_file contains one biome data per line
3) after each biome in the file there is a return (
so that the next biome is in the next line), and also
there is (one single) return after the last biome
in the_file
to call or invoke this function:
listStrings = read_string_list_from_file(<file-name.txt in quotes>)
'''
fileRef = open(the_file,"r") # opening file to be read
global localList
localList=[]
for line in fileRef:
string = line[0:len(line)-1] # eliminates trailing '\n'
# of each line
localList.append(string) # adds string to list
fileRef.close()
#........
#print "\n JUST TO TRACE, the local list of strings is:\n"
#for element in localList:
# print element
#print
#........
return localList
def biomeDataParser(localList):
global biomeData
global biomeDiamonds
global biomeSwords
global biomeEnemies
global biomeList
for i in range(len(localList)): #wow, much comments
biomeData.append(localList[i].split("-")) # many biome lists, wow.
for j in range(len(biomeData)):
for k in range(1):
biomeDiamonds.append(int(biomeData[j][k]))
biomeSwords.append(int(biomeData[j][k+1]))
biomeEnemies.append(int(biomeData[j][k+2]))
biomeList.append(j)
def biomeTable():
print "The current board state is as follows:"
print "Biome Diamd Sword Enemy"
for i in range(len(biomeList)):
if godMode == True:
if pythonShine == i:
print biomeList[i] , " " * (5-(len(str(i)))), biomeDiamonds[i], " " * (5-(len(str(biomeDiamonds[i])))), \
biomeSwords[i], " " * (5-(len(str(biomeSwords[i])))), biomeEnemies[i], " <=== PythonShine"
elif playerPos == i and turnNumber >= 0:
print biomeList[i] , " " * (5-(len(str(i)))), biomeDiamonds[i], " " * (5-(len(str(biomeDiamonds[i])))), \
biomeSwords[i], " " * (5-(len(str(biomeSwords[i])))), biomeEnemies[i], " <===", playerName
elif playerPos == i and turnNumber < 0:
print biomeList[i] , " " * (5-(len(str(i)))), biomeDiamonds[i], " " * (5-(len(str(biomeDiamonds[i])))), \
biomeSwords[i], " " * (5-(len(str(biomeSwords[i])))), biomeEnemies[i]
elif pythonShine == playerPos:
print biomeList[i] , " " * (5-(len(str(i)))), biomeDiamonds[i], " " * (5-(len(str(biomeDiamonds[i])))), \
biomeSwords[i], " " * (5-(len(str(biomeSwords[i])))), biomeEnemies[i], " <=== PythonShine", " <===", playerName
else:
print biomeList[i] , " " * (5-(len(str(i)))), biomeDiamonds[i], " " * (5-(len(str(biomeDiamonds[i])))), \
biomeSwords[i], " " * (5-(len(str(biomeSwords[i])))), biomeEnemies[i]
if godMode == False:
if pythonShine == i:
print biomeList[i] , " " * (5-(len(str(i)))), biomeDiamonds[i], " " * (5-(len(str(biomeDiamonds[i])))), \
biomeSwords[i], " " * (5-(len(str(biomeSwords[i])))), biomeEnemies[i]
elif playerPos == i and turnNumber >= 0:
print biomeList[i] , " " * (5-(len(str(i)))), biomeDiamonds[i], " " * (5-(len(str(biomeDiamonds[i])))), \
biomeSwords[i], " " * (5-(len(str(biomeSwords[i])))), biomeEnemies[i], " <===", playerName
elif playerPos == i and turnNumber < 0:
print biomeList[i] , " " * (5-(len(str(i)))), biomeDiamonds[i], " " * (5-(len(str(biomeDiamonds[i])))), \
biomeSwords[i], " " * (5-(len(str(biomeSwords[i])))), biomeEnemies[i]
elif pythonShine == playerPos:
print biomeList[i] , " " * (5-(len(str(i)))), biomeDiamonds[i], " " * (5-(len(str(biomeDiamonds[i])))), \
biomeSwords[i], " " * (5-(len(str(biomeSwords[i])))), biomeEnemies[i], " <=== PythonShine", " <===", playerName
else:
print biomeList[i] , " " * (5-(len(str(i)))), biomeDiamonds[i], " " * (5-(len(str(biomeDiamonds[i])))), \
biomeSwords[i], " " * (5-(len(str(biomeSwords[i])))), biomeEnemies[i]
def pythonShineGenerator():
global pythonShine
if godMode == True:
while pythonShine < 1 or pythonShine > 7:
pythonShine = input("Where do you want to place PythonShine? (Pick a number from 1 to 7) ")
if pythonShine < 1 or pythonShine > 7:
print "Please input a value between 1 and 7."
elif godMode == False:
pythonShine = random.randint(1, 7)
def combatCalculator():
global playerSword
global playerHealth
if biomeSwords[playerPos] > playerSword:
tempSword = playerSword
playerSword = biomeSwords[playerPos]
biomeSwords[playerPos] = tempSword
print playerName, "has picked up a level", playerSword, "sword!"
if playerSword > biomeEnemies[playerPos]:
healthGain = random.randint(1, playerHealth)
playerHealth += healthGain
print playerName, "won the fight and gained", healthGain, "health!"
if biomeEnemies[playerPos] > playerSword:
if playerHealth > 1:
healthLost = random.randint(1, playerHealth)
if playerHealth == 1:
healthLost = random.randint(0,1)
playerHealth -= healthLost
print playerName, "lost the fight and lost", healthLost, "health."
if playerSword == biomeEnemies[playerPos]:
healthLost = random.randint(1, (playerHealth / 2))
playerHealth -= healthLost
print playerName, "tied the fight, but lost", healthLost, "health."
def diamondCalculator():
global playerDiamonds
if playerPos == pythonShine:
playerDiamonds = 9999
else:
playerDiamonds += (biomeDiamonds[playerPos])/3
print playerName, "has collected", (biomeDiamonds[playerPos]/3), "diamonds!"
def playerInfo():
global playerSword
global gameOn
global gameOnInput
global roundOn
if roundOn == True:
print playerName + " currently has:"
print playerHealth, "health."
print playerDiamonds, "diamonds."
if playerSword == 0:
print "No sword."
else:
"A level", playerSword, "sword."
if playerPos == -1:
print "And is about to spawn."
else:
print "And is in position", playerPos
print "=========================================================="
elif roundOn == False:
print "Game Over!"
if playerHealth <= 0:
print playerName + " has died."
elif playerDiamonds == 9999:
print playerName + "has won!"
elif turnNumber == maximumTurns:
print "The maximum number of turns has been reached."
print playerName + " ended the game with:"
print playerHealth, "health."
print playerDiamonds, "diamonds."
if playerSword == 0:
print "No sword."
else:
"A level", playerSword, "sword."
print "=========================================================="
if gameOn == True and roundOn == False:
while gameOnInput == "" and gameOn == True:
gameOnInput = raw_input("Would you like to play another game? (y/n) ")
if gameOnInput == "y":
gameOn = True
roundOn = True
elif gameOnInput == "n":
gameOn = False
print "Thanks for nothing."
else:
print "Please input y for yes or n for no."
gameOnInput = ""
def gameCheck():
global roundOn
if playerPos == pythonShine:
roundOn = False
if playerHealth <= 0:
roundOn = False
if turnNumber == maximumTurns:
roundOn = False
def catastropheGenerator():
global catastrophePos
global catastropheNumber
catastrophePos = (7 / 5) * (random.randint(1,7))
for i in range(catastrophePos):
if catastrophePos == biomeList[i]:
catastropheNumber += 1
print "A catastrophe has occured in biome", catastrophePos
print "Biome", catastrophePos, "has been destroyed!"
biomeList.remove(catastrophePos)
catastropheNumber += 1
if playerPos == catastrophePos:
playerHealth == 0
print playerName, "has been caught in the catastrophe!"
def endGameCalculations():
print "wow, you win"
# EXECUTION TOP LEVEL
gameStart()
readFile("biomesData2.txt")
biomeDataParser(localList)
pythonShineGenerator()
print
biomeTable()
print
enterInfo()
# WHILE LOOP
while gameOn == True:
while roundOn == True:
t.speed(0)
print
biomeTable()
print
playerInfo()
drawBoard()
drawPlayer()
print
turnGenerator()
diamondCalculator()
combatCalculator()
print
catastropheGenerator()
gameCheck()
t.clearscreen()
print
playerInfo()
### BUG LIST###
#Playing no godMode, found pythonShine, but there is no message saying that I found PythonShine.
#Playing godMode on, got error when entering 'e' for # of turns, make some real verification.
#Same error occurs when "efklfn" is used as initial health
#Also with manual biome selection
# was able to use 12.5 as a turn maximum value, allows infinite play
#if the file stated is not in the directory, great error
#will accept an empty file, and then great dismay occurs :'(