Skip to content
Snippets Groups Projects
Commit 2d593fd1 authored by Markus Opolka's avatar Markus Opolka
Browse files

Add afugabe9

parent e80f3293
No related branches found
No related tags found
No related merge requests found
#!/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()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment