This commit is contained in:
alstergym
2026-10-06 12:11:21 +02:00
parent 0c391109c8
commit c54a08ac3d
3 changed files with 61 additions and 3 deletions
+56 -2
View File
@@ -10,7 +10,7 @@ class MeinSpiel:
richtung = 0
richtung_y = 0
alter_hintergrund = 0
geschwindigkeit = 10
geschwindigkeit = 15
punkte1 = 0 # Punkte des Spieler 1
punkte2 = 0 # Punkte des Spieler 2
def __init__(self, felderX, felderY):
@@ -180,11 +180,65 @@ class MeinSpiel:
if stoppe_suche: break
return spieler_x, spieler_y
except UnboundLocalError as e:
print(e)
self.starte_spiel()
def bewegeball2(self):
if self.richtung == 0: return # Wenn Spiel nicht aktiv, dann self.richtung = 0; Also bewegt sich der Ball nicht
kontrollfeld = copy.deepcopy(self.spielfeld)
stoppe_suche = False
for x in range(len(self.spielfeld)):
for y in range(len(self.spielfeld[x])):
if self.spielfeld[x][y] == 2: # 2 = Ball
stoppe_suche = True # um den Ball nicht ein zweites mal zu finden
# setze Ballcoordinaten auf das nächste Feld
BallX = x+1 if self.richtung == 2 else x-1
BallY = y+1 if self.richtung_y == 2 else y-1
print(BallX)
print(BallY)
# gucken ob an der neuen Position ein Spieler ist
if self.spielfeld[BallX][BallY] == 1:
# Richtung des Balles ändern und danach BallX und BallY neu setzen
self.richtung = 1 if self.richtung == 2 else 1
self.richtung_y = 1 if self.richtung_y == 2 else 1
BallX = x+1 if self.richtung == 2 else x-1
BallY = y+1 if self.richtung_y == 2 else y-1
# gucken ob Ball am Rand (x-position) ist; Für Punktesystem
if BallX == -1:
self.punkte2 += 1
self.starte_spiel()
elif BallX == 15: # 15, weil mein Spiel 15 Felder (standart 14) hat und von 0 gezählt wird -> max anzahl 14; 15 würde heißen, ball aus dem Spielfeld
self.punkte1 += 1
self.starte_spiel()
# gucken ob Ball am Rand (y-position) ist; Richtung ändern
if BallY == -1:
self.richtung_y = 1 if self.richtung_y == 2 else 2
BallX = y
elif BallY == 15: # in if abfrage drüber inkludiert
self.richtung_y = 1 if self.richtung_y == 2 else 2
BallY = y
kontrollfeld[x][y] = 0
kontrollfeld[BallX][BallY] = 2
if stoppe_suche: break
if stoppe_suche: break
self.spielfeld = kontrollfeld