-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game.py
47 lines (40 loc) · 1.44 KB
/
Game.py
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
47
import Board, Player, Dice
class Game():
def __init__(self):
self.Board = Board.Board()
self.Dice = Dice.Dice()
self.Players = []
def addPlayers(self):
numPlayers = int(input('How many players?'))
for i in range(0, numPlayers):
tempname = input('Enter player name:')
self.Players.append(Player.Player(tempname))
def play(self):
winner = False
while winner == False:
for player in self.Players:
winner = self.__makeMove(player)
if winner:
break
def __makeMove(self, player):
#get current position
oldPosition = player.getPosition()
print('It is your turn ' + player.getName())
print('Press any key to roll')
roll = self.Dice.roll()
print('You rolled a {}'.format(roll))
print('You were at position {}'.format(oldPosition))
initialPosition = roll + oldPosition
if self.hasWon(initialPosition):
return True
newPosition = self.Board.getFinalPosition(initialPosition)
print('You are now at position {}'.format(newPosition))
player.setPosition(newPosition)
return self.hasWon(newPosition)
def hasWon(self, position):
if self.Board.getSize() <= position:
print('You have won!')
return True
else:
return False
# TODO - Game reset() method