Inital commit
This commit is contained in:
commit
32fb46db9f
3
.idea/.gitignore
vendored
Normal file
3
.idea/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
6
.idea/inspectionProfiles/profiles_settings.xml
Normal file
6
.idea/inspectionProfiles/profiles_settings.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<settings>
|
||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||
<version value="1.0" />
|
||||
</settings>
|
||||
</component>
|
8
.idea/modules.xml
Normal file
8
.idea/modules.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/projekt_gra_turowa.iml" filepath="$PROJECT_DIR$/.idea/projekt_gra_turowa.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
10
.idea/projekt_gra_turowa.iml
Normal file
10
.idea/projekt_gra_turowa.iml
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/.venv" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="Python 3.12 (projekt_gra_turowa)" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
18
jednostka.py
Normal file
18
jednostka.py
Normal file
@ -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
|
9
kusznik.py
Normal file
9
kusznik.py
Normal file
@ -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'
|
9
lucznik.py
Normal file
9
lucznik.py
Normal file
@ -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'
|
16
main.py
Normal file
16
main.py
Normal file
@ -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)
|
9
piechur.py
Normal file
9
piechur.py
Normal file
@ -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'
|
43
plansza.py
Normal file
43
plansza.py
Normal file
@ -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()
|
Loading…
Reference in New Issue
Block a user