-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame.py
More file actions
213 lines (195 loc) · 9.31 KB
/
Copy pathGame.py
File metadata and controls
213 lines (195 loc) · 9.31 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
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
import random
#start
armors = {"none":0, "leather":5, "bronze":10, "iron":15, "titanium":20}
swords = {"none":0, "wood":-10, "bronze":-20, "iron":-40, "titanium":-60}
#enemy values
enemyDamage = {"slime": -15, "goblin": -25, "orc": -35}
enemyHealth = {"slime":20, "goblin": 40, "orc": 50}
#keeps track of game progress, and affects difficulty
cavelayer = 10
#player class to manage player state and calculate the players actions
class player:
def __init__(self):
#base stats
self.health = 100
self.armor = "none"
self.sword = "none"
self.dps = -5
def turn(self,listOfEnemies):
#turn code is inside a loop to ensure the user input is viable
while True:
try:
#simple code for "you are being attacked, what do you do?"
for i in range(0,len(listOfEnemies),1):
print("there is a " + listOfEnemies[i].type + " in position " + str(i+1))
target = input("Which position do you want to attack?")
target = int(target)
if(target <= len(listOfEnemies)):
break
except:
print("intput not recognized, try again")
#returns values that the controller class takes as a argument to calculate what happens in a turn
self.dps = -5 + swords[self.sword]
return (self.dps, target)
#if the game is replayed, we need to reset all the things
def reset(self):
self.health = 100
self.armor = "none"
self.sword = "none"
self.dps = -5
class enemy:
def __init__(self, type):
self.health = enemyHealth[type]
self.damage = enemyDamage[type]
self.type = type
#handles turns and interactions
class controller:
def __init__(self):
self.turns = 1
def turn(self, playerDPS, playerTarget, playerResist):
#takes the players actions and makes the game happen
if(mPlayer.health > 0):
#logic to make wording better
if((enemyList[playerTarget-1].health + playerDPS) > 0):
print("you attacked a " + str(enemyList[playerTarget-1].type) + " for " + str(-playerDPS) + " damage, it has ", (enemyList[playerTarget-1].health + playerDPS), " HP left!")
else:
print("you attacked a " + str(enemyList[playerTarget-1].type) + " for " + str(-playerDPS) + " damage")
#where the enemies take damage
enemyList[playerTarget-1].health += playerDPS
if(enemyList[playerTarget-1].health <= 0):
print("you have slain the ", enemyList[playerTarget-1].type)
#where you take damage
for i in enemyList:
if(i.health > 0):
mPlayer.health += (i.damage + playerResist)
print("you were hit by a " + str(i.type) + " for " + str(-(i.damage)) + " damage!" + " you are now at " + str(mPlayer.health) + " HP")
else:
enemyList.remove(i)
#turns varible that we display at the end
self.turns += 1
#game instance setup
enemyList = []
mPlayer = player()
mController = controller()
#game loop
while True:
start = input("start game? [Y or N]")
if(start == "N" or start == "n"):
exit()
elif(start == "Y" or start == "y"):
print("You wake up in a cave, and you decide the only reasonable course of action is to indulge your sense of adventrue and escape this cave! \n")
break
else:
print("input not recognized: try again \n")
while True:
#keeps track of game progress, and affects difficulty
cavelayer = 10
#where the magic happens
while cavelayer != 0:
#encounter setup:
difficulty = random.randint(1,10)
if(difficulty > cavelayer):
numOfEnemy = 3
elif(difficulty > cavelayer+2):
numOfEnemy = 2
else:
numOfEnemy = 1
for i in range(numOfEnemy):
enemyDifficulty = random.randint(1,10)
if(enemyDifficulty > cavelayer+5):
enemyList.append(enemy("orc"))
elif(enemyDifficulty > cavelayer):
enemyList.append(enemy("goblin"))
else:
enemyList.append(enemy("slime"))
if(numOfEnemy == 3):
print("you are on floor: " + str(cavelayer) + " and you are confronted by three enemies, a " + enemyList[0].type + ", a " + enemyList[1].type + ", and a " + enemyList[2].type)
elif(numOfEnemy == 2):
print("you are on floor: " + str(cavelayer) + " and you are confronted by two enemies, a " + enemyList[0].type + ", and a " + enemyList[1].type)
else:
print("you are on floor: " + str(cavelayer) + " and you are confronted by a enemy, a " + enemyList[0].type)
#encounter gameplay:
while(len(enemyList) != 0):
#while there are enemies to fight, fight!
playerMove = mPlayer.turn(enemyList)
mController.turn(playerMove[0],playerMove[1], armors[mPlayer.armor])
#we need two breaks for both loops in the event of a game over.
if(mPlayer.health <=0):
break
if(mPlayer.health <=0):
break
#the battle is over, take a rest
#funny messages
floorMessage = random.randint(1,5)
if(floorMessage == 1):
print("floor complete! you might make it out of this alive")
elif(floorMessage == 2):
print("floor complete! you start to feel like a true hero")
elif(floorMessage == 3):
print("floor complete! if you knew magic this would be a lot easier")
elif(floorMessage == 4):
print("floor complete! you are suprised at your own capability")
elif(floorMessage == 5):
print("floor complete! if you make it out of here, you wonder who you will tell about this")
#loot time, drop rarity is calculated by cave layer, similar to enemy difficulty
#this if is to make the ending of the game smoother, we don't need loot if we beat the game
if(cavelayer != 1):
print("you rest for a bit and scavange the battlefield")
#health reset
mPlayer.health = 100
#sword drops
lootSword = random.randint(1,10)
if(lootSword > cavelayer+5 and mPlayer.sword != "titanium"):
print("You find a titanium sword! it's heavy but you can deal")
mPlayer.sword = "titanium"
elif(lootSword > cavelayer+2 and mPlayer.dps > -40):
print("You find a iron sword! it's lighter than you expect but the handle has seen better days")
mPlayer.sword = "iron"
elif(lootSword > cavelayer and mPlayer.dps > -20):
print("You find a bronze sword! part of the blade is chiped but it cuts fine")
mPlayer.sword = "bronze"
elif(mPlayer.dps > -10):
print("You find a wood sword! it isn't great but it better than nothing")
mPlayer.sword = "wood"
else:
print("You couldn't find a better weapon")
#armor drops
lootArmor = random.randint(1,10)
if(lootArmor > cavelayer+5 and mPlayer.armor != "titanium"):
print("You find titanium armor! you might as well be a real knight at this point")
mPlayer.armor = "titanium"
elif(lootArmor > cavelayer+2 and armors[mPlayer.armor] < 15):
print("You find iron armor! you pretend you are a knight to feel better about the situation")
mPlayer.armor = "iron"
elif(lootArmor > cavelayer and armors[mPlayer.armor] < 10):
print("You find bronze armor! you wonder if the Ancient Greeks were the last ones here")
mPlayer.armor = "bronze"
elif(mPlayer.dps > -10):
print("You find leather armor! you don't know what animal's leather but that doesn't matter now")
mPlayer.armor = "leather"
else:
print("You couldn't find any better protection")
print("you move to the next level with ", mPlayer.armor, " armor, and a ", mPlayer.sword, " sword, you now have ", str(armors[mPlayer.armor]), " armor points, and ", str(swords[mPlayer.sword]), " damage!")
#we're moving up in the world
cavelayer -= 1
#if we got to this part, you either beat the game or died trying
if(mPlayer.health <=0):
print("not everyone makes it out alive...")
print("GAME OVER, You survived " , str(mController.turns), " turns.")
else:
print("you have escaped the cave, congratulations!")
print("GAME WIN, You made it out in ", str(mController.turns), " turns.")
#play again?
replay = input("play again? [Y or N]")
if(replay == "N" or replay == "n"):
print("breaking")
break
elif(replay == "Y" or replay == "y"):
print("resetting world\n")
mPlayer.reset()
enemyList.clear()
else:
print("Ill take that as a no\n")
break
print("end of loop")
print("thank you for playing")