-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
183 lines (154 loc) · 5.57 KB
/
main.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
from random import randrange, random
# HP, Atk, Def, Spe, Agi, Int
classes = {
"warrior": [8, 8, 6, 1, 3, 2, 4],
"mage": [8, 2, 3, 6, 3, 6, 5],
"archer": [6, 5, 2, 2, 7, 4, 6],
"thief": [6, 6, 2, 2, 7, 6, 8]}
mobs = {
"Neville": [4, 4, 2, 4, 4, 4, 4],
"Creeper (aw man)": [1, 7, 2, 2, 2, 2, 2],
"James": [4, 2, 6, 2, 6, 4, 6],
"Ghoul": [3, 5, 6, 2, 2, 2, 1],
"Barry (63)": [3, 3, 3, 2, 2, 2, 10],
"Boris": [2, 2, 2, 2, 2, 2, 1],
"Juan": [10, 2, 2, 2, 2, 2, 1],
"Asoka": [6, 6, 4, 4, 3, 6, 8]}
global position
position = 1
global player_alive
player_alive = True
def chooseClass():
classname = input("please enter the name of the class you wish to select")
try:
return classes[classname]
except:
print("not a valid class")
chooseClass()
def selection():
name = input("Please enter your character name")
stats = chooseClass()
if input("confirm choice y/n") != "y":
return selection()
return {
"Name": name,
"HP": stats[0],
"Attack": stats[1],
"Defence": stats[2],
"Special": stats[3],
"Agility": stats[4],
"Intelligence": stats[5],
"Luck": stats[6]
}
def menu():
print("**********DND*********")
print(classes)
player = selection()
print(player)
return player
def combat_loop(player_stat_input): # pass monster info and player info?
player_stats = {
"Name": player_stat_input["Name"],
"HP": player_stat_input["HP"],
"Attack": player_stat_input["Attack"],
"Defence": player_stat_input["Defence"],
"Special": player_stat_input["Special"],
"Agility": player_stat_input["Agility"],
"Intelligence": player_stat_input["Intelligence"],
"Luck": player_stat_input["Luck"],
}
# for stat in player_stat_input:
# player_stats[stat] = player_stat_input[stat]
mob_choice = random.choice(list(mobs.items()))
print(mob_choice)
mob_stats = {
"Name": name,
"HP": mobs[mob_choice][0],
"Attack": mobs[mob_choice][1],
"Defence": mobs[mob_choice][2],
"Special": mobs[mob_choice][3],
"Agility": mobs[mob_choice][4],
"Intelligence": mobs[mob_choice][5],
"Luck": mobs[mob_choice][6]
}
is_over = False
while ~is_over:
playerIn = int(input("Select action:\n1: Attack 2: Special attack 3: Run "))
if player_stats["Agility"] >= mob_stats["Agility"]:
print(player_stats["Name"], "'s turn!")
is_over = perform_action(player_stats, mob_stats, playerIn)
if is_over:
break
print(mob_stats["Name"], "'s turn!")
is_over = perform_action(mob_stats, player_stats, playerIn)
else:
print(mob_stats["Name"], "'s turn!")
is_over = perform_action(mob_stats, player_stats, playerIn)
if is_over:
break
print(player_stats["Name"], "'s turn!")
is_over = perform_action(player_stats, mob_stats, playerIn)
print(is_over)
if is_over:
break
print(player_stats, "\n", mob_stats)
if player_stats["HP"] == 0:
print(player_stats["Name"], " was defeated by", mob_stats["Name"], " (oh no!)")
global player_alive
player_alive = False
elif mob_stats["HP"] == 0:
print("Enemy ", mob_stats["name"], " was defeated!")
def perform_action(entity_acting, entity_passive, ch):
if ch == 1: # Regular attack logic
print(entity_acting["Name"], " is attacking ", entity_passive["Name"], "!")
damage = entity_acting["Attack"] // (entity_passive["Defence"] / 2)
entity_passive["HP"] = entity_passive["HP"] - damage
elif ch == 2: # Special attack logic
print(entity_acting["Name"], " is attacking with magic!")
damage = entity_acting["Special"] // (entity_passive["Defence"] / 2)
entity_passive["HP"] = entity_passive["HP"] - damage
elif ch == 3: # Run away logic
print(entity_acting["Name"], " is trying to run away!")
chance = randrange(0, 20)
if chance <= 10 - entity_acting["Luck"] // 4:
print(entity_acting["Name"], " has escaped!")
position -= 1
return
else:
print(entity_acting["Name"], " has failed to escape!")
else:
print("Unknown choice")
if entity_passive["HP"] <= 0: # If HP reaches 0, then they have been defeated
# print(entity_passive["Name"], " was defeated!")
return True
else:
return False
def enemyortreasure(currPlayerStats):
chance = randrange(0, 20)
if chance <= 10 - currPlayerStats.get("Luck") // 2:
print("You have encountered an enemy")
combat_loop(currPlayerStats)
return
else:
print("You have found treasure")
for x in currPlayerStats.values():
if type(x) == int:
x += 1
return
if __name__ == '__main__':
currPlayerStats= menu()
print(player_alive)
while player_alive:
direction = input("Would you like to move forwards or backwards? ")
if direction == 'forwards':
position += 1
enemyortreasure(currPlayerStats)
if direction == 'backwards':
if position == 1:
print("You cannot move backwards any further")
else:
position -= 1
# movement()
else:
print("That is not a valid choice.")
print(" Game over! Thanks for playing! You died in room number " + str(position) + "!")