Newer
Older
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
#!/usr/bin/env python3
import random
class Colors:
GREEN = '\033[92m'
BLUE = '\033[94m'
RED = '\033[91m'
RESET = '\033[0m'
class Player:
def __init__(self, name, hp, strength):
self.name = name
self.hp = hp
self.strength = strength,
self.moves = {"tackle": int(strength),
"fireball": 8,
"heal": 3}
def attack(self, target):
choice = str.lower(input("Your move (Tackle, Fireball, or Heal):"))
print("{0} uses {1}{2}{3}".format(self.name, Colors.RED, choice.title(), Colors.RESET))
if choice == 'tackle':
target.hp -= self.moves['tackle']
if choice == 'fireball':
target.hp -= self.moves['fireball']
if choice == 'heal':
self.hp += self.moves['heal']
class Enemy:
def __init__(self, name, hp, strength):
self.name = name
self.hp = hp
self.strength = strength,
self.moves = {"tackle": int(strength),
"blizzard": 8,
"heal": 3}
def attack(self, target):
choice = random.choice(list(self.moves.keys()))
print("{0} uses {1}{2}{3}".format(self.name, Colors.RED, choice.title(), Colors.RESET))
if choice == 'tackle':
target.hp -= self.moves['tackle']
if choice == 'blizzard':
target.hp -= self.moves['blizzard']
if choice == 'heal':
self.hp += self.moves['heal']
def battle(player, cpu):
while player.hp > 0 and cpu.hp > 0:
player.attack(cpu)
if cpu.hp <= 0:
print("Player wins")
break
cpu.attack(player)
if player.hp <= 0:
print("CPU wins")
break
print()
print("{0}'s HP at {1}{2}{3}".format(cpu.name, Colors.GREEN, cpu.hp, Colors.RESET))
print("{0}'s HP at {1}{2}{3}".format(player.name, Colors.GREEN, player.hp, Colors.RESET))
print()
def main():
player_name = str(input("Enter your Name: "))
player = Player(name=player_name, hp=20, strength=6)
cpu = Enemy(name="CPU", hp=20, strength=7)
battle(player, cpu)
if __name__ == "__main__":
main()