Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGonzalo Odiard <godiard@gmail.com>2014-08-08 20:12:29 (GMT)
committer Gonzalo Odiard <godiard@gmail.com>2014-08-08 20:12:29 (GMT)
commitb2c63c761539aaea6c2c914d71ac09d5de5ca93a (patch)
tree5f4aae8544f6ec820f3013f700b624baba4245bf
parentee6f36ad4adf6a30ba2ddf03b78fb999fea8d6bb (diff)
Show pieces from both players
-rw-r--r--dominoactivity.py24
-rw-r--r--dominogame.py2
-rw-r--r--dominoplayer.py9
-rw-r--r--dominoview.py58
4 files changed, 53 insertions, 40 deletions
diff --git a/dominoactivity.py b/dominoactivity.py
index 70361af..28f5978 100644
--- a/dominoactivity.py
+++ b/dominoactivity.py
@@ -250,23 +250,22 @@ class Domino(activity.Activity):
# para que se encimen bien cuando se dibujan
self.game.placed_pieces.sort(
lambda pieceA,
- pieceB: pieceA.x - pieceB.x + pieceA.y * 100 - pieceB.y * 100)
+ pieceB: int(pieceA.x - pieceB.x + pieceA.y * 100 - pieceB.y * 100))
for piece in self.game.placed_pieces:
if piece.visible:
piece.draw(surf_ctx, False)
- # for n in range(0,len(self.game.players)):
- # dibujo las piezas del jugador
- player = self.game.ui_player
- pieces = player.get_pieces()
- # TODO: replace for m (m is needed below)
- for m in range(0, len(pieces)):
- piece = pieces[m]
- if piece.visible:
- if self.game.game_state != DominoGame.GAME_STATE_LOCATE_PIECE \
- or (m != self.game.ui_player.order_piece_selected):
- piece.draw(surf_ctx, False)
+ for player in self.game.players:
+ pieces = player.get_pieces()
+ # TODO: replace for m (m is needed below)
+ for m in range(0, len(pieces)):
+ piece = pieces[m]
+ if piece.visible:
+ if self.game.game_state != \
+ DominoGame.GAME_STATE_LOCATE_PIECE \
+ or (m != self.game.ui_player.order_piece_selected):
+ piece.draw(surf_ctx, False)
# to debug
self.game.table.show_values(surf_ctx, self.game.values)
@@ -377,7 +376,6 @@ class Domino(activity.Activity):
piece = player.get_pieces()[player.order_piece_selected]
if player.place_piece(piece):
- self.game.show_pieces_player(player)
player.end_play()
self.draw_pieces()
diff --git a/dominogame.py b/dominogame.py
index c8c5003..7de697d 100644
--- a/dominogame.py
+++ b/dominogame.py
@@ -151,7 +151,7 @@ class DominoGame:
separacion_x = int((dominoview.SCREEN_WIDTH - dominoview.SIZE *
len(pieces)) / len(pieces))
x = separacion_x / 2
- y = self.table.limitTable + dominoview.SIZE / 2
+ y = player.pieces_y_position
for piece in pieces:
piece.x = x
diff --git a/dominoplayer.py b/dominoplayer.py
index 25a8ee8..9d05c64 100644
--- a/dominoplayer.py
+++ b/dominoplayer.py
@@ -21,6 +21,8 @@ class DominoPlayer:
self.color = None
# se usa para saber si este usuario paso la ultima vuelta
self.has_passed = False
+ # where are displayed the pieces for this player
+ self.pieces_y_position = self.game.table.bottom_limit
def set_pieces(self, pieces):
self._pieces = pieces
@@ -55,6 +57,7 @@ class DominoPlayer:
self.game.btnNew.props.sensitive = False
# "End player",self.number
self.playing = False
+
self.game.next_player(self.number).play()
def remove_piece(self, piece):
@@ -154,6 +157,7 @@ class DominoPlayer:
else:
return False
+ self.game.show_pieces_player(self)
return True
@@ -166,6 +170,10 @@ class SimpleAutoPlayer(DominoPlayer):
NO TIENE NINGUNA ESTRATEGIA
"""
+ def __init__(self, game, number):
+ DominoPlayer.__init__(self, game, number)
+ self.pieces_y_position = 0
+
def play(self):
# "Jugando automatico"
if self.game.start is None:
@@ -184,6 +192,7 @@ class SimpleAutoPlayer(DominoPlayer):
endTile.value = piece.b
endTile.direction = Tile.RIGHT
self.game.end = endTile
+ self.game.show_pieces_player(self)
else:
# "automatica siguiente"
diff --git a/dominoview.py b/dominoview.py
index 3987bb4..2317ece 100644
--- a/dominoview.py
+++ b/dominoview.py
@@ -59,36 +59,40 @@ class DominoTableView():
def __init__(self, **kwargs):
self.cantX = int(SCREEN_WIDTH / SIZE) - 1
- self.cantY = int((SCREEN_HEIGHT - SIZE * 3) / SIZE)
- self.margenX = int((SCREEN_WIDTH - SIZE * self.cantX) / 2)
- self.limitTable = SIZE * self.cantY
+ self.cantY = int((SCREEN_HEIGHT - SIZE * 4) / SIZE)
+ self._margin_x = int((SCREEN_WIDTH - SIZE * self.cantX) / 2)
+ self._margin_y = SIZE * 2
+
+ self.bottom_limit = self._margin_y + SIZE * self.cantY
print "Table cantX", self.cantX, "cantY", self.cantY
def paint(self, ctx):
- # agrego 2,2 para que la grilla quede en la base de las piezas
+ # agrego 5,5 para que la grilla quede en la base de las piezas
# (por la perspectiva)
alto = 5
- ctx.move_to(alto, alto)
- ctx.rectangle(self.margenX + alto, 0 + alto, SIZE * self.cantX + alto,
- SIZE * (self.cantY) + alto)
+ ctx.rectangle(self._margin_x + alto, self._margin_y + alto,
+ SIZE * self.cantX + alto,
+ SIZE * self.cantY + alto)
ctx.set_source_rgb(204.0/255.0, 204.0/255.0, 204.0/255.0)
ctx.fill()
ctx.set_line_width(1)
ctx.set_source_rgb(1, 1, 0)
- for n in range(0, self.cantY + 1):
- ctx.move_to(self.margenX + alto, n * SIZE + alto)
- ctx.line_to(SCREEN_WIDTH - self.margenX + alto, n * SIZE + alto)
+ for n in range(0, self.cantY):
+ ctx.move_to(self._margin_x + alto,
+ self._margin_y + alto + n * SIZE)
+ ctx.line_to(self._margin_x + alto + SIZE * self.cantX,
+ self._margin_y + alto + n * SIZE)
ctx.stroke()
- ctx.move_to(0, 0)
- for n in range(0, self.cantX + 1):
- ctx.move_to(self.margenX + n * SIZE + alto, 0 + alto)
- ctx.line_to(self.margenX + n * SIZE + alto,
- self.limitTable + alto)
+ for n in range(0, self.cantX):
+ ctx.move_to(self._margin_x + n * SIZE + alto,
+ self._margin_y + alto)
+ ctx.line_to(self._margin_x + n * SIZE + alto,
+ self.bottom_limit + alto)
ctx.stroke()
def show_values(self, ctx, tiles):
@@ -97,7 +101,8 @@ class DominoTableView():
"""
for n in range(0, self.cantX):
for p in range(0, self.cantY):
- ctx.move_to(self.margenX + n * SIZE + SIZE / 4, p * SIZE)
+ ctx.move_to(self._margin_x + n * SIZE + SIZE / 4,
+ self._margin_y + (p + 1) * SIZE)
ctx.set_source_rgb(1, 0, 0)
ctx.show_text(str(tiles[n][p].value))
@@ -107,15 +112,16 @@ class DominoTableView():
"""
ctx.set_source_rgb(0, 1, 0)
ctx.set_line_width(3)
- ctx.rectangle(self.margenX + tile.n * SIZE, (tile.p - 1) * SIZE,
+ ctx.rectangle(self._margin_x + tile.n * SIZE,
+ self._margin_y + tile.p * SIZE,
SIZE, SIZE)
ctx.stroke()
def get_tile_position(self, n, p):
- return self.margenX + n * SIZE, (p - 1) * SIZE
+ return self._margin_x + n * SIZE, self._margin_y + p * SIZE
def get_tile_coord(self, x, y):
- return (x - self.margenX) / SIZE, (y / SIZE) + 1
+ return (x - self._margin_x) / SIZE, (y / SIZE) + 1
def show_status(self, ctx, text):
xIni = 10
@@ -144,15 +150,15 @@ class DominoTableView():
alto = 5
ctx.move_to(alto, alto)
- ctx.rectangle(self.margenX + alto, 0 + alto, SIZE * self.cantX + alto,
- SIZE * (self.cantY) + alto)
+ ctx.rectangle(self._margin_x + alto, 0 + alto,
+ SIZE * self.cantX + alto, SIZE * (self.cantY) + alto)
ctx.set_source_rgb(204.0 / 255.0, 204.0 / 255.0, 204.0 / 255.0)
ctx.fill()
ctx.set_line_width(1)
ctx.set_source_rgb(1, 1, 0)
- ctx.rectangle(self.margenX + alto, 0 + alto, SIZE * self.cantX + alto,
- SIZE * (self.cantY) + alto)
+ ctx.rectangle(self._margin_x + alto, 0 + alto,
+ SIZE * self.cantX + alto, SIZE * (self.cantY) + alto)
ctx.stroke()
altoRenglon = 40
@@ -164,7 +170,7 @@ class DominoTableView():
cairo.FONT_WEIGHT_NORMAL)
ctx.set_font_size(30)
- x = self.margenX + 200
+ x = self._margin_x + 200
y = altoRenglon * 2
ctx.move_to(x, y)
@@ -190,11 +196,11 @@ class DominoTableView():
def help(self, ctx):
altoRenglon = 45
- x = self.margenX + 20
+ x = self._margin_x + 20
y = altoRenglon * 4
ctx.set_line_width(1)
ctx.set_source_rgb(1, 1, 0)
- ctx.rectangle(self.margenX + 10, altoRenglon * 3,
+ ctx.rectangle(self._margin_x + 10, altoRenglon * 3,
SIZE * self.cantX - 10, y + altoRenglon * 4)
ctx.stroke()