-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.py
112 lines (87 loc) · 2.96 KB
/
game.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
from random import randint
game_running = True
game_results = []
def calculate_monster_attack(attack_min, attack_max):
return randint(attack_min, attack_max)
def game_ends(winner_name):
print(f'{winner_name} has won the game')
while game_running == True:
counter = 0
new_round = True
player = {
'name': 'Gabby',
'attack': 13,
'heal': 16,
'health': 100
}
monster = {
'name': 'MadMax',
'attack_min': 10,
'attack_max': 20,
'health': 100
}
print('---' * 7)
print('Enter Player Name')
player['name'] = input()
print('---' * 7)
print(player['name'] + ' has ' + str(player['health']) + ' health')
print(monster['name'] + ' has ' + str(monster['health']) + ' health')
while new_round == True:
counter = counter + 1
player_won = False
monster_won = False
print('---' * 7)
print('Please select an action:')
print('1) Attack')
print('2) Heal')
print('3) Exit Game')
print('4) Show Results')
player_choice = input()
if player_choice == '1':
monster['health'] = monster['health'] - player['attack']
if monster['health'] <= 0:
player_won = True
else:
player['health'] = player['health'] - \
calculate_monster_attack(
monster['attack_min'], monster['attack_max'])
if player['health'] <= 0:
monster_won = True
elif player_choice == '2':
player['health'] = player['health'] + player['heal']
player['health'] = player['health'] - \
calculate_monster_attack(
monster['attack_min'], monster['attack_max'])
if player['health'] <= 0:
monster_won = True
elif player_choice == '3':
new_round = False
game_running = False
elif player_choice == '4':
for item in game_results:
print(item)
else:
print('Invalid Input')
if player_won == False and monster_won == False:
print(player['name'] + ' has ' +
str(player['health']) + ' health left')
print(monster['name'] + ' has ' +
str(monster['health']) + ' health left')
elif player_won:
game_ends(player['name'])
round_result = {
'name': player['name'],
'health': player['health'],
'rounds': counter
}
game_results.append(round_result)
new_round = False
elif monster_won:
game_ends(monster['name'])
round_result = {
'name': player['name'],
'health': player['health'],
'rounds': counter
}
game_results.append(round_result)
new_round = False