Using the robot class - implement robot battles - Python OOP - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: Using the robot class - implement robot battles - Python OOP (/thread-33685.html) |
Using the robot class - implement robot battles - Python OOP - krnkrnkrn - May-16-2021 In today task I have pretty fun thing to implement, but I have some problems. Using the robot class - implement robot battles. Each player has 5 robots. People move the robots alternately, if the robots meet in one field, one takes part of the energy of the other (or all). When the robot's power runs out, a second robot automatically appears. or implement a fully random battle What i have so far: from typing import List, Tuple class Robot: def __init__(self, name: str, place : List[int], start: Tuple[int, int] = (0,0), power: int = 9): self._name = name self._place = place self._start = start self._power = power # further assignments @property def name(self): return self._name @name.setter def name(self, value): if isinstance(value, str): self._name = value else: raise TypeError("must be a string") @property def place(self): return self._place @place.setter def place(self, value): if isinstance(value, list): self._start = value else: raise TypeErorr("must be a list") @property def start(self): return self._start @start.setter def start(self, value): if isinstance(value, tuple): self._start = value else: raise TypeErorr("must be a tuple") @property def power(self): return self._power @power.setter def power(self, value): if isinstance(value, int): self._start = value else: raise TypeErorr("must be a int") @property def check_power(self): if self._power <= 0: raise ValueError("No power") def up(self, value): #def left(self, value): #def right(self, value): #def down(self, value): def __str__(self): return "{} {} {}".format(self._name, self._place, self._power)Logic Quote:You should also take a look at your setters for place and start. You only check the type of the passed argument value, but do not verify if the elements in the list or tuple are of type int.I don't really know how to implement it, any help? RE: Using the robot class - implement robot battles - Python OOP - deanhystad - May-17-2021 What is your question? |