Skip to content
Snippets Groups Projects
Arena.py 2.19 KiB
Newer Older
Markus Opolka's avatar
Markus Opolka committed
#!/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()