-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBox.py
More file actions
50 lines (39 loc) · 1.42 KB
/
Box.py
File metadata and controls
50 lines (39 loc) · 1.42 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
47
48
49
50
from Line import *
class Box:
def __init__(self,x,y,board):
self.top = Line(self,Position.TOP)
self.right = Line(self,Position.RIGHT)
self.bottom = Line(self,Position.BOTTOM)
self.left = Line(self,Position.LEFT)
self.x = x
self.y = y
self.__owner = Player.NONE
self.__board = board
def isFilled(self):
return self.top.isPainted() and self.right.isPainted() and self.bottom.isPainted() and self.left.isPainted()
def setFilledBy(self,player):
self.__owner = player
def tryToFillBy(self,player):
if self.isFilled() and self.getOwner() == Player.NONE:
#Le joueur vient de remplir un carré
self.setFilledBy(player)
self.getBoard().setPlayAgain(True)
self.getBoard().incrementScore(player)
def getOwner(self):
return self.__owner
def getBoard(self):
return self.__board
def hasTopBox(self):
if self.getBoard().getBox(self.x,self.y-1) != False:
return True
return False
def hasLeftBox(self):
if self.getBoard().getBox(self.x-1,self.y) != False:
return True
return False
def getTopBox(self):
return self.getBoard().getBox(self.x,self.y-1)
def getLeftBox(self):
return self.getBoard().getBox(self.x-1,self.y)
def __repr__(self):
return "Box({}, {})".format(self.x,self.y)