diff --git a/OOP/main.py b/OOP/main.py index c5a158e..4fac018 100644 --- a/OOP/main.py +++ b/OOP/main.py @@ -1,16 +1,81 @@ -class SuperClass1: +from random import choice, randint +from time import sleep +from os import system + +class Color: + red = "\033[91m" + green = "\033[92m" + yellow = "\033[93m" + blue = "\033[94m" + purple = "\033[95m" + cyan = "\033[96m" + norm = "\033[0m" + + +class Knight: + FIRST = ["Lancelot", "Charles", "Henry", "William"] + NICK = ["Brave", "Horrific", "Courageous", "Terrific"] + ACTION = ["ATTACK", "DEFEND", "REST"] + def __init__(self): - self.foo = "bar" + for i in range(3): + self.ACTION.append("ATTACK") + self.name = f"{choice(Knight.FIRST)} The {choice(Knight.NICK)}" + self.state = "" + self.health = 100 -class SuperClass2: + def action(self, player): + action = choice(Knight.ACTION) + self.state = action + + + def update_health(self, player): + if player == Game.PLAYERS[0]: + if player.state in ["ATTACK", "REST"] and Game.PLAYERS[1].state == "ATTACK": + player.health -= 5 + else: + if player.state in ["ATTACK", "REST"] and Game.PLAYERS[0].state == "ATTACK": + player.health -= 5 + + + +class Game: + PLAYERS = [] def __init__(self): - self.bar = "foo" + for i in range(2): + self.PLAYERS.append(Knight()) -class DerivedClass(SuperClass1, SuperClass2): - def __init__(self): + def gameloop(self): + while self.PLAYERS[0].health > 0 and self.PLAYERS[1].health > 0: - SuperClass2.__init__(self) + system("clear") -myDerived = DerivedClass() -print(myDerived.bar) -print(myDerived.foo) + print(f"{Color.cyan}-----------------------------------------------{Color.norm}") + for player in self.PLAYERS: + print(f"{Color.green}{player.name}{Color.norm}: {player.health}") + print(f"{Color.cyan}-----------------------------------------------{Color.norm}") + + sleep(1) + + for player in self.PLAYERS: + player.action(player) + match player.state: + case "ATTACK": + print(f"{player.name} attacks!") + case "DEFEND": + print(f"{player.name} defends from any attacks.") + case "REST": + print(f"{player.name} is tired and will not do anything this round") + sleep(2) + + for player in self.PLAYERS: + player.update_health(player) + sleep(2) + self.end_game() + + def end_game(self): + print("Game End") + +if __name__ == "__main__": + game = Game() + game.gameloop()