import random class nmy(): def __init__(self,name,hp,attack): self.name = name self.HP = hp self.attack = attack def target(self,mon): self.enemy = mon def Attack(self): self.enemy.HP = self.enemy.HP - self.attack * random.uniform(0.8,1.2) if self.enemy.HP < 0: self.enemy.HP = 0 print(f"{self.enemy.name} has {round(self.enemy.HP,3)} left and was attacked with {self.attack} attack power and you have {round(self.HP,3)} of health left") def Defense(self): correct = random.randint(1,5) choice = int(input(self.name + " pick a number from 1 to 5 to defend with your shield!")) if correct == choice: print(self.name + " defended the attack fast enough!") else: dodge = random.randint(0,4) if dodge == 0: print(self.name + " dodged the attack!") else: print(self.name + " was to slow and was hit!") self.enemy.Attack() def battle(enemy, player): player.target(enemy) enemy.target(player) while player.HP > 0 and enemy.HP > 0: enemy.Defense() if enemy.HP > 0: print(enemy.name + " attacks " + player.name) player.Defense() if player.HP > 0: print("------------NEW-ROUND!------------") print(player.name + " attacks " + enemy.name) if player.HP == 0: print(enemy.name + " Won") if enemy.HP == 0: print(player.name + " Won") player1 = nmy("arthur99999999",200,50) player2 = nmy("Mr. Fan",200,50) var = random.randint(0,1) if var == 0: battle(player1, player2) else: battle(player2, player1) #3 is the most powerful number if doesnt work use 5
this is python code that makes a basic text engine game with a class and a few functions for the basic abilities attacking defending and some other things