From 3aca56bd555099a185212733849b30783f531124 Mon Sep 17 00:00:00 2001 From: Dmytro Date: Mon, 23 Dec 2024 07:41:25 +0200 Subject: [PATCH] 'Solution' --- app/main.py | 21 ++++++++++++++++++++- app/players/__init__.py | 0 app/players/dwarves/__init__.py | 0 app/players/dwarves/dwarf.py | 15 +++++++++++++++ app/players/dwarves/dwarf_blacksmith.py | 22 ++++++++++++++++++++++ app/players/dwarves/dwarf_warrior.py | 22 ++++++++++++++++++++++ app/players/elves/__init__.py | 0 app/players/elves/druid.py | 22 ++++++++++++++++++++++ app/players/elves/elf.py | 16 ++++++++++++++++ app/players/elves/elf_ranger.py | 22 ++++++++++++++++++++++ app/players/player.py | 18 ++++++++++++++++++ 11 files changed, 157 insertions(+), 1 deletion(-) create mode 100644 app/players/__init__.py create mode 100644 app/players/dwarves/__init__.py create mode 100644 app/players/dwarves/dwarf.py create mode 100644 app/players/dwarves/dwarf_blacksmith.py create mode 100644 app/players/dwarves/dwarf_warrior.py create mode 100644 app/players/elves/__init__.py create mode 100644 app/players/elves/druid.py create mode 100644 app/players/elves/elf.py create mode 100644 app/players/elves/elf_ranger.py create mode 100644 app/players/player.py diff --git a/app/main.py b/app/main.py index fa56336e1..c9d74a2e0 100644 --- a/app/main.py +++ b/app/main.py @@ -1 +1,20 @@ -# write your code here +from __future__ import annotations +from app.players.elves.elf import Elf +from app.players.dwarves.dwarf import Dwarf + + +def calculate_team_total_rating(our_team: list) -> int: + their_rating = 0 + for team in our_team: + their_rating += team.get_rating() + return their_rating + + +def elves_concert(our_elfs: list[Elf]) -> None: + for elf in our_elfs: + elf.play_elf_song() + + +def feast_of_the_dwarves(our_dwarves: list[Dwarf]) -> None: + for dwarf in our_dwarves: + dwarf.eat_favourite_dish() diff --git a/app/players/__init__.py b/app/players/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/app/players/dwarves/__init__.py b/app/players/dwarves/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/app/players/dwarves/dwarf.py b/app/players/dwarves/dwarf.py new file mode 100644 index 000000000..a81ce65e9 --- /dev/null +++ b/app/players/dwarves/dwarf.py @@ -0,0 +1,15 @@ +from abc import abstractmethod +from app.players.player import Player + + +class Dwarf(Player): + def __init__(self, nickname: str, favourite_dish: str) -> None: + super().__init__(nickname) + self._favourite_dish = favourite_dish + + def eat_favourite_dish(self) -> None: + print(f"{self.nickname} is eating {self._favourite_dish}") + + @abstractmethod + def get_name(self) -> str: + pass diff --git a/app/players/dwarves/dwarf_blacksmith.py b/app/players/dwarves/dwarf_blacksmith.py new file mode 100644 index 000000000..8fa54bc37 --- /dev/null +++ b/app/players/dwarves/dwarf_blacksmith.py @@ -0,0 +1,22 @@ +from app.players.dwarves.dwarf import Dwarf + + +class DwarfBlacksmith(Dwarf): + def __init__( + self, + nickname: str, + favourite_dish: str, + skill_level: int + ) -> None: + super().__init__(nickname, favourite_dish) + self._skill_level = skill_level + + def get_name(self) -> str: + return self.nickname + + def player_info(self) -> str: + return (f"Dwarf blacksmith {self.get_name()}" + f" with skill of the {self._skill_level} level") + + def get_rating(self) -> int: + return self._skill_level diff --git a/app/players/dwarves/dwarf_warrior.py b/app/players/dwarves/dwarf_warrior.py new file mode 100644 index 000000000..3562edba3 --- /dev/null +++ b/app/players/dwarves/dwarf_warrior.py @@ -0,0 +1,22 @@ +from app.players.dwarves.dwarf import Dwarf + + +class DwarfWarrior(Dwarf): + def __init__( + self, + nickname: str, + favourite_dish: str, + hummer_level: int + ) -> None: + super().__init__(nickname, favourite_dish) + self._hummer_level = hummer_level + + def get_name(self) -> str: + return self.nickname + + def player_info(self) -> str: + return (f"Dwarf warrior {self.get_name()}. {self.get_name()}" + f" has a hummer of the {self._hummer_level} level") + + def get_rating(self) -> int: + return self._hummer_level + 4 diff --git a/app/players/elves/__init__.py b/app/players/elves/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/app/players/elves/druid.py b/app/players/elves/druid.py new file mode 100644 index 000000000..d479a9631 --- /dev/null +++ b/app/players/elves/druid.py @@ -0,0 +1,22 @@ +from app.players.elves.elf import Elf + + +class Druid(Elf): + def __init__( + self, + nickname: str, + musical_instrument: str, + favourite_spell: str + ) -> None: + super().__init__(nickname, musical_instrument) + self._favourite_spell = favourite_spell + + def get_name(self) -> str: + return self.nickname + + def player_info(self) -> str: + return (f"Druid {self.get_name()}. {self.get_name()}" + f" has a favourite spell: {self._favourite_spell}") + + def get_rating(self) -> int: + return len(self._favourite_spell) diff --git a/app/players/elves/elf.py b/app/players/elves/elf.py new file mode 100644 index 000000000..df99a83bc --- /dev/null +++ b/app/players/elves/elf.py @@ -0,0 +1,16 @@ +from abc import abstractmethod +from app.players.player import Player + + +class Elf(Player): + def __init__(self, nickname: str, musical_instrument: str) -> None: + super().__init__(nickname) + self._musical_instrument = musical_instrument + + def play_elf_song(self) -> None: + print(f"{self.nickname} is playing a" + f" song on the {self._musical_instrument}") + + @abstractmethod + def get_name(self) -> str: + pass diff --git a/app/players/elves/elf_ranger.py b/app/players/elves/elf_ranger.py new file mode 100644 index 000000000..9e3f7bd38 --- /dev/null +++ b/app/players/elves/elf_ranger.py @@ -0,0 +1,22 @@ +from app.players.elves.elf import Elf + + +class ElfRanger(Elf): + def __init__( + self, + nickname: str, + musical_instrument: str, + bow_level: int + ) -> None: + super().__init__(nickname, musical_instrument) + self._bow_level = bow_level + + def get_name(self) -> str: + return self.nickname + + def player_info(self) -> str: + return (f"Elf ranger {self.get_name()}. {self.get_name()}" + f" has bow of the {self._bow_level} level") + + def get_rating(self) -> int: + return 3 * self._bow_level diff --git a/app/players/player.py b/app/players/player.py new file mode 100644 index 000000000..0f96a07ec --- /dev/null +++ b/app/players/player.py @@ -0,0 +1,18 @@ +from abc import ABC, abstractmethod + + +class Player(ABC): + def __init__(self, nickname: str) -> None: + self.nickname = nickname + + @abstractmethod + def get_name(self) -> str: + pass + + @abstractmethod + def player_info(self) -> str: + pass + + @abstractmethod + def get_rating(self) -> int: + pass