From 32fb46db9f7df4f10a14d44c5029c725bc90c305 Mon Sep 17 00:00:00 2001 From: s500512 Date: Mon, 9 Dec 2024 19:29:11 +0100 Subject: [PATCH] Inital commit --- .idea/.gitignore | 3 ++ .../inspectionProfiles/profiles_settings.xml | 6 +++ .idea/modules.xml | 8 ++++ .idea/projekt_gra_turowa.iml | 10 +++++ .idea/vcs.xml | 6 +++ jednostka.py | 18 ++++++++ kusznik.py | 9 ++++ lucznik.py | 9 ++++ main.py | 16 +++++++ piechur.py | 9 ++++ plansza.py | 43 +++++++++++++++++++ rycerz.py | 9 ++++ 12 files changed, 146 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/projekt_gra_turowa.iml create mode 100644 .idea/vcs.xml create mode 100644 jednostka.py create mode 100644 kusznik.py create mode 100644 lucznik.py create mode 100644 main.py create mode 100644 piechur.py create mode 100644 plansza.py create mode 100644 rycerz.py diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..b931d19 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/projekt_gra_turowa.iml b/.idea/projekt_gra_turowa.iml new file mode 100644 index 0000000..4e4e387 --- /dev/null +++ b/.idea/projekt_gra_turowa.iml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/jednostka.py b/jednostka.py new file mode 100644 index 0000000..88f10c8 --- /dev/null +++ b/jednostka.py @@ -0,0 +1,18 @@ +from abc import ABC + + +class Jednostka(ABC): + def __init__(self, zdrowie, sila_ataku, zasieg_ataku, szybkosc_ruchu): + self.zdrowie = zdrowie + self.sila_ataku = sila_ataku + self.zasieg_ataku = zasieg_ataku + self.szybkosc_ruchu = szybkosc_ruchu + + def otrzymaj_obrazenia(self, obrazenia): + print(f'Zadano {obrazenia} obrażeń') + self.zdrowie -= obrazenia + + def czy_zyje(self): + if self.zdrowie > 0: + return True + return False diff --git a/kusznik.py b/kusznik.py new file mode 100644 index 0000000..cc0f877 --- /dev/null +++ b/kusznik.py @@ -0,0 +1,9 @@ +from jednostka import Jednostka + + +class Kusznik(Jednostka): + def __init__(self): + super().__init__(80, 15, 2, 5) + + def __str__(self): + return 'K' diff --git a/lucznik.py b/lucznik.py new file mode 100644 index 0000000..7a9e07e --- /dev/null +++ b/lucznik.py @@ -0,0 +1,9 @@ +from jednostka import Jednostka + + +class Lucznik(Jednostka): + def __init__(self): + super().__init__( 60, 10, 3, 9) + + def __str__(self): + return 'L' diff --git a/main.py b/main.py new file mode 100644 index 0000000..64b8d0e --- /dev/null +++ b/main.py @@ -0,0 +1,16 @@ +from plansza import Plansza +from rycerz import Rycerz +from lucznik import Lucznik +from kusznik import Kusznik +from piechur import Piechur + +if __name__ == '__main__': + plansza = Plansza() + + plansza.dodaj_jednostke(Rycerz(), 1, 1) + plansza.dodaj_jednostke(Lucznik(), 2, 1) + + plansza = Plansza() + + plansza.dodaj_jednostke(Kusznik(), 5, 5) + plansza.dodaj_jednostke(Piechur(), 3, 5) diff --git a/piechur.py b/piechur.py new file mode 100644 index 0000000..52c0b56 --- /dev/null +++ b/piechur.py @@ -0,0 +1,9 @@ +from jednostka import Jednostka + + +class Piechur(Jednostka): + def __init__(self): + super().__init__(80, 15, 1, 7) + + def __str__(self): + return 'P' diff --git a/plansza.py b/plansza.py new file mode 100644 index 0000000..f2b5d05 --- /dev/null +++ b/plansza.py @@ -0,0 +1,43 @@ +class Plansza: + _instance = None + + def __new__(cls, *args, **kwargs): + if not cls._instance: + cls._instance = super().__new__(cls) + return cls._instance + + def __init__(self): + if not hasattr(self, '_initialized'): + self.pole = [['O' for x in range(5)] for y in range(5)] + self._initialized = True + + def dodaj_jednostke(self, jednostka, x, y): + x -= 1 + y -= 1 + if self.czy_zajete(x, y): + print('Nie mozna dodać jednostki na tym polu') + else: + self.pole[x][y] = jednostka + self.wyswietl() + + def usun_jednostke(self, x, y): + x -= 1 + y -= 1 + if self.czy_zajete(x, y): + self.pole[x][y] = 'O' + else: + print('To pole juz jest puste') + self.wyswietl() + + def czy_zajete(self, x, y): + if self.pole[x][y] == 'O': + return False + return True + + def wyswietl(self): + print() + for y in range(5): + for x in range(5): + print(self.pole[x][y], end=' ') + print() + print() diff --git a/rycerz.py b/rycerz.py new file mode 100644 index 0000000..d3e3373 --- /dev/null +++ b/rycerz.py @@ -0,0 +1,9 @@ +from jednostka import Jednostka + + +class Rycerz(Jednostka): + def __init__(self): + super().__init__(100, 20, 1, 5) + + def __str__(self): + return 'R'