Написал небольшой код с использованием ООП, для меня, как для новичка, оценка важна.
--------------------------------------------------------------------------------------------------------------------------------
import random
class Robot():
def __init__(self, speed, name, TotalPoints):
self..name= name
self.speed = speed
self.TotalPoints = TotalPoints
class Robot_killer(Robot):
def __init__(self, SpeedOfAttack, DamageOfAttack, speed, name, TotalPoints):
super(Robot_killer, self).__init__(speed, name, TotalPoints)
self.SpeedOfAttack = SpeedOfAttack
self.DamageOfAttack = DamageOfAttack
class Robot_Defense(Robot):
def __init__(self, hp, speed, name, TotalPoints):
super(Robot_Defense, self).__init__(speed, name, TotalPoints)
self.hp = hp
def answer(robot_killer, robot_defender, robot_killer_DamageOfAllAttack):
if robot_defender.speed > robot_killer.speed:
robot_defender.TotalPoints += 1
robot_killer_DamageOfAllAttack -= random.randint(0, 20)
else:
robot_killer.TotalPoints += 1
if robot_killer_DamageOfAllAttack > robot_defender.hp:
robot_killer.TotalPoints += 2
else:
robot_defender.TotalPoints += 2
print()
if robot_defender.TotalPoints > robot_killer.TotalPoints:
if choice == "убийца":
print("Вы проиграли!"
else:
print("Вы победили!"
else:
if choice == "убийца":
print("Вы победили!"
else:
print("Вы проиграли!"
print()
print("Данные убийцы:"
print("Скорость:", robot_killer.speed)
print("Скорость урона:", round(robot_killer.SpeedOfAttack, 2), end=""
print(", Сила урона:", robot_killer.DamageOfAttack)
print()
print("Данные жертвы:"
print("Скорость:", robot_defender.speed)
print("Здоровье:", robot_defender.hp, end=""
robot_killer = Robot_killer(random.random() + 0.25, random.randint(40, 80), random.randint(10, 50), "Убийца", 0)
robot_killer_DamageOfAllAttack = round(robot_killer.DamageOfAttack * robot_killer.SpeedOfAttack * 2)
robot_defender = Robot_Defense(random.randint(70, 110), random.randint(15, 55), "Жертва", 0)
i = True
while i:
print()
print("Выберите 2 кандидата:"
print("Жертва или Убийца"
print()
choice = input("Выбор: "
if answer.lower() == "убийца":
i = False
answer(robot_killer, robot_defender, robot_killer_DamageOfAllAttack)
elif choice.lower() == "жертва":
i = False
answer(robot_killer, robot_defender, robot_killer_DamageOfAllAttack)
else:
i = True
--------------------------------------------------------------------------------------------------------------------------------
self..name в 5 строчке с 2 точками для обхода анти-спама
--------------------------------------------------------------------------------------------------------------------------------
import random
class Robot():
def __init__(self, speed, name, TotalPoints):
self..name= name
self.speed = speed
self.TotalPoints = TotalPoints
class Robot_killer(Robot):
def __init__(self, SpeedOfAttack, DamageOfAttack, speed, name, TotalPoints):
super(Robot_killer, self).__init__(speed, name, TotalPoints)
self.SpeedOfAttack = SpeedOfAttack
self.DamageOfAttack = DamageOfAttack
class Robot_Defense(Robot):
def __init__(self, hp, speed, name, TotalPoints):
super(Robot_Defense, self).__init__(speed, name, TotalPoints)
self.hp = hp
def answer(robot_killer, robot_defender, robot_killer_DamageOfAllAttack):
if robot_defender.speed > robot_killer.speed:
robot_defender.TotalPoints += 1
robot_killer_DamageOfAllAttack -= random.randint(0, 20)
else:
robot_killer.TotalPoints += 1
if robot_killer_DamageOfAllAttack > robot_defender.hp:
robot_killer.TotalPoints += 2
else:
robot_defender.TotalPoints += 2
print()
if robot_defender.TotalPoints > robot_killer.TotalPoints:
if choice == "убийца":
print("Вы проиграли!"
else:
print("Вы победили!"
else:
if choice == "убийца":
print("Вы победили!"
else:
print("Вы проиграли!"
print()
print("Данные убийцы:"
print("Скорость:", robot_killer.speed)
print("Скорость урона:", round(robot_killer.SpeedOfAttack, 2), end=""
print(", Сила урона:", robot_killer.DamageOfAttack)
print()
print("Данные жертвы:"
print("Скорость:", robot_defender.speed)
print("Здоровье:", robot_defender.hp, end=""
robot_killer = Robot_killer(random.random() + 0.25, random.randint(40, 80), random.randint(10, 50), "Убийца", 0)
robot_killer_DamageOfAllAttack = round(robot_killer.DamageOfAttack * robot_killer.SpeedOfAttack * 2)
robot_defender = Robot_Defense(random.randint(70, 110), random.randint(15, 55), "Жертва", 0)
i = True
while i:
print()
print("Выберите 2 кандидата:"
print("Жертва или Убийца"
print()
choice = input("Выбор: "
if answer.lower() == "убийца":
i = False
answer(robot_killer, robot_defender, robot_killer_DamageOfAllAttack)
elif choice.lower() == "жертва":
i = False
answer(robot_killer, robot_defender, robot_killer_DamageOfAllAttack)
else:
i = True
--------------------------------------------------------------------------------------------------------------------------------
self..name в 5 строчке с 2 точками для обхода анти-спама