import random class Move: def __init__(self, name:str,dmg:range): self.name = name, self.dmg = dmg class Character: def __init__(self, name:str,max_hp:float,hp:float,atk_bonus:float,defense:float,moves:dict): print(type(moves)) self.name = name self.max_hp = max_hp self.hp = hp self.atk_bonus = atk_bonus self.defense = defense self.moves = moves self.chosen_input = None self.chosen_input_args = None self.defending = False def damage(self, amt:float): self.hp -= amt if self.hp <= 0: print(self.name, "is dead!") def attack(self, char,move:str,chars,index): if not char.defending: dmg_amt = random.choice(self.moves[move].dmg) char.damage(dmg_amt) print("\n"+self.name,"attacked",char.name,"and dealed",dmg_amt,"damage!") else: print(char.name,"blocked",self.name+"'s attack!") char.defending = False if char.hp > 0: print("\n"+char.name,"is now", str(char.hp)+"/"+str(char.max_hp),"HP") else: chars.pop(index) def heal(self, amt): print(self.name,"healed",amt,"HP!") self.hp += amt print("\n"+self.name,"is now",str(self.hp)+"/"+str(self.max_hp),"HP") class Enemy(Character): def make_choice(self, plrs): choice = random.randint(1,7) if choice > 0 and choice < 5: rand_index = 0 if len(players) != 0: rand_index = random.randint(0,len(players)-1) print(rand_index) self.chosen_input = self.attack self.chosen_input_args = [plrs[rand_index],random.choice(list(self.moves.keys())),plrs,rand_index] if choice > 4 and choice < 7: self.defending = True if choice == 7: self.chosen_input = self.heal self.chosen_input_args = [10] players = [ ] players.append(Character("sdfghfha",100,100,1,4,{"hit" : Move("hit",range(10,20)), "spell 1" : Move("spell 1",range(20,40))})) enemies = [ ] enemies.append(Enemy("cull obsidian",100,100,1,4,{"hit" : Move("hit",range(5,10))})) def ask_choice(char : Character): print("\n --------------------------- \n") print("Current Player:",char.name,str(char.hp)+"/"+str(char.max_hp),"HP") print( "\nActions:","\n", "[a] Attack","\n", "[d] Defend","\n", "[h] Heal","\n", "[x] Quit","\n", ) char_input = input("Your choice?: ") match char_input: case "a": for i in range(len(enemies)): print(" ["+str(i)+"]",enemies[i].name,str(enemies[i].hp)+"/"+str(enemies[i].max_hp),"HP") print(" [x] Cancel\n") chosen_enemy = input("Who do you want to attack?: ") if chosen_enemy.isnumeric(): if int(chosen_enemy) >= 0 and int(chosen_enemy) < len(enemies): for move in char.moves.keys(): print("\n["+str(move)+"]","Damage:",str(char.moves[move].dmg.start)+"-"+str(char.moves[move].dmg.stop)) print("[x] Cancel\n") chosen_move = input("What move do you want to use?: ") if chosen_move == "x": ask_choice(char) elif chosen_move in char.moves: char.chosen_input = char.attack char.chosen_input_args = [enemies[int(chosen_enemy)],chosen_move,enemies,int(chosen_enemy)] else: print("Invalid move") ask_choice(char) else: print("Invalid choice") ask_choice(char) elif chosen_enemy == "x": print("Cancelling...") ask_choice(char) else: print("Invalid input") case "d": char.defending = True case "h": char.chosen_input = char.heal char.chosen_input_args = [10] case "x": return True case _: print("Invalid input") ask_choice(char) def execute_choices(): for plr in players: if plr.chosen_input_args != None: plr.chosen_input(*plr.chosen_input_args) for enemy in enemies: if enemy.chosen_input_args != None: enemy.chosen_input(*enemy.chosen_input_args) def make_choices(): if len(enemies) < 1: print("\n --------------------------- ") print("You won!") print(" --------------------------- ") quit() for plr in players: end_game = ask_choice(plr) if end_game: print("Thanks for playing!") quit() for enemy in enemies: enemy.make_choice(players) execute_choices() make_choices() make_choices()