-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.py
More file actions
46 lines (36 loc) · 1.59 KB
/
Copy pathgame.py
File metadata and controls
46 lines (36 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from player import Player
from board import Board
class Game:
def __init__(self, board: Board, player1: Player, player2: Player):
self._actualplayer = 1
self._gameTurn = 1
self._Player1 = player1
self._Player2 = player2
self._board = board
def switchActualplayer(self):
self._actualplayer = 2 if self._actualplayer == 1 else 1
def resetGameTurn(self):
self._gameTurn = 1
def maxGameTurnReached(self):
if self._gameTurn >= self._board.rows * self._board.columns:
print("------------------------------------------------")
print("Maximale Spielzüge erreicht, unentschieden")
return True
return False
def doGameTurn(self):
columinput = int(input(f"Gib die gewünschte Spalte ein (1-{self._board.columns}): "))
while not (1 <= columinput <= self._board.columns):
print("Ungültige Eingabe. Bitte erneut versuchen.")
columinput = int(input(f"Gib die gewünschte Spalte ein (1-{self._board.columns}): "))
success = self._board.setChip(columinput - 1, self._actualplayer)
while not success:
print("Spalte voll! Bitte wähle eine andere.")
columinput = int(input(f"Gib die gewünschte Spalte ein (1-{self._board.columns}): "))
success = self._board.setChip(columinput, self._actualplayer)
self._gameTurn += 1
self._board.printBroad()
if self._board.finishGame():
return True
if self.maxGameTurnReached():
return True
return False