add code
This commit is contained in:
commit
cb83f35112
106
main.py
Normal file
106
main.py
Normal file
@ -0,0 +1,106 @@
|
||||
# -----------------------------------------------------------
|
||||
# Würfel
|
||||
# -----------------------------------------------------------
|
||||
|
||||
from random import randint
|
||||
|
||||
|
||||
class Wuerfel(object):
|
||||
|
||||
def __init__(self):
|
||||
self.augen = randint(1, 6)
|
||||
|
||||
def werfen(self):
|
||||
self.augen = randint(1, 6)
|
||||
# print(self.augen)
|
||||
|
||||
def getAugen(self):
|
||||
return self.augen
|
||||
|
||||
|
||||
# -----------------------------------------------------------
|
||||
# Kasse
|
||||
# -----------------------------------------------------------
|
||||
|
||||
class Kasse(object):
|
||||
|
||||
def __init__(self):
|
||||
self.stand = 0
|
||||
|
||||
def auszahlen(self, pBetrag):
|
||||
self.stand = self.stand - pBetrag
|
||||
|
||||
def einzahlen(self, pBetrag):
|
||||
self.stand = self.stand + pBetrag
|
||||
|
||||
def getStand(self):
|
||||
return self.stand
|
||||
|
||||
|
||||
# -----------------------------------------------------------
|
||||
# Spieler
|
||||
# -----------------------------------------------------------
|
||||
|
||||
class Spieler(object):
|
||||
|
||||
def __init__(self, pName, pMarken, pWuerfel1, pWuerfel2, pKasse):
|
||||
self.name = pName
|
||||
self.marken = pMarken
|
||||
self.rWuerfel1 = pWuerfel1
|
||||
self.rWuerfel2 = pWuerfel2
|
||||
self.rKasse = pKasse
|
||||
|
||||
def spielen(self):
|
||||
self.rWuerfel1.werfen()
|
||||
self.rWuerfel2.werfen()
|
||||
augenGesamt = self.rWuerfel1.getAugen() + self.rWuerfel2.getAugen()
|
||||
if augenGesamt == 12:
|
||||
self.marken = self.marken - 12
|
||||
self.rKasse.einzahlen(12)
|
||||
elif augenGesamt == 11:
|
||||
anzahlMarken = self.rKasse.getStand()
|
||||
self.rKasse.auszahlen(anzahlMarken)
|
||||
self.marken = self.marken + anzahlMarken
|
||||
else:
|
||||
differenzBetrag = 11 - augenGesamt
|
||||
self.marken = self.marken - differenzBetrag
|
||||
self.rKasse.einzahlen(differenzBetrag)
|
||||
|
||||
def getName(self):
|
||||
return self.name
|
||||
|
||||
def getMarken(self):
|
||||
return self.marken
|
||||
|
||||
|
||||
# -----------------------------------------------------------
|
||||
# Spielmanager
|
||||
# -----------------------------------------------------------
|
||||
|
||||
class Spielmanager(object):
|
||||
|
||||
def __init__(self, pSpieler1, pSpieler2, pSpieler3):
|
||||
self.rSpieler1 = pSpieler1
|
||||
self.rSpieler2 = pSpieler2
|
||||
self.rSpieler3 = pSpieler3
|
||||
|
||||
def spielrundeDurchfuehren(self):
|
||||
self.rSpieler1.spielen()
|
||||
self.rSpieler2.spielen()
|
||||
self.rSpieler3.spielen()
|
||||
|
||||
|
||||
# -----------------------------------------------------------
|
||||
# Test
|
||||
# -----------------------------------------------------------
|
||||
|
||||
w1 = Wuerfel()
|
||||
w2 = Wuerfel()
|
||||
k = Kasse()
|
||||
sp1 = Spieler('Winner', 100, w1, w2, k)
|
||||
sp2 = Spieler('Looser', 100, w1, w2, k)
|
||||
sp3 = Spieler('Zitterhand', 100, w1, w2, k)
|
||||
m = Spielmanager(sp1, sp2, sp3)
|
||||
|
||||
m.spielrundeDurchfuehren()
|
||||
print(sp1.getMarken(), sp2.getMarken(), sp3.getMarken())
|
Loading…
Reference in New Issue
Block a user