-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player.py
31 lines (26 loc) · 881 Bytes
/
Player.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
from Grid import Grid
import random
class Player:
def __init__(self, name, grid):
self.name=name
self.pos=[0,0]
self.grid=grid
self.win_point=11
self.has_won=-1
def roll(self):
dice_num=random.randint(1,6)
print("Player {} game state is {}".format(self.name, self.has_won))
if self.has_won>-1:
return
if self.pos[1]+dice_num < self.win_point:
self.pos[1]+=dice_num
self.grid.move_player(self.pos)
elif self.pos[1]+dice_num==self.win_point:
self.has_won=1
self.pos[1] += dice_num
self.grid.move_player(self.pos)
else:
self.has_won=-1
self.pos[1]=0
self.grid.move_player(self.pos)
print("Player {} is at {}".format(self.name, self.pos))