Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Aguiar <alanjas@hotmail.com>2013-05-08 07:57:30 (GMT)
committer Alan Aguiar <alanjas@hotmail.com>2013-05-08 07:57:30 (GMT)
commit97d50cfadd16697c442ef3a0ab89d1c6febc89f3 (patch)
treef4203270782b68320cb57a21e724fd6296984f2c
parent33bd043cde235f518fc048e9ae508c7f92754a12 (diff)
show owner
-rwxr-xr-xmain.py43
1 files changed, 41 insertions, 2 deletions
diff --git a/main.py b/main.py
index 5984c42..e001832 100755
--- a/main.py
+++ b/main.py
@@ -13,7 +13,7 @@ X_OFFSET = 200
Y_OFFSET = 200
T = 15
COLOR1 = (0, 0, 0)
-
+COLOR_OWNER = (255, 0, 0)
class box:
@@ -22,6 +22,10 @@ class box:
self.left = 0
self.right = 0
self.down = 0
+ self.owner = 0
+
+ def check(self):
+ return ((self.up + self.left + self.right + self.down) == 4)
class Game:
@@ -36,6 +40,17 @@ class Game:
self.screen = pygame.display.set_mode((900, 700))
self.screen.fill((84, 185, 72))
self.draw_grid()
+ self.fuente = pygame.font.Font(None, 50)
+
+ def showText(self, texto, p_x, p_y):
+ text = self.fuente.render(texto, 1, COLOR_OWNER)
+ textrect = text.get_rect()
+ x = p_x * BOX_SIZE[0] + X_OFFSET
+ y = p_y * BOX_SIZE[1] + Y_OFFSET
+ dx = int(BOX_SIZE[0] / 2.0)
+ dy = int(BOX_SIZE[1] / 2.0)
+ textrect.center = (x + dx, y + dy)
+ self.screen.blit(text, textrect)
def draw_grid(self):
#pygame.draw.circle(Surface, color, pos, radius, width=0): return Rect
@@ -101,10 +116,14 @@ class Game:
return
b.left = 1
print 'box', x_b, y_b, b.up, b.left, b.right, b.down
+ if b.check():
+ self.showText('A', x_b , y_b)
if x_b > 0:
b2 = self.boxes[x_b - 1][y_b]
b2.right = 1
- print 'box', x_b - 1, y_b, b2.up, b2.left, b2.right, b2.down
+ print 'box2', x_b - 1, y_b, b2.up, b2.left, b2.right, b2.down
+ if b2.check():
+ self.showText('A', x_b - 1, y_b)
pygame.draw.line(self.screen, COLOR1, (r1[0],r2[0]), (r1[0],r2[1]), 5)
return
elif x > (r1[1] - T):
@@ -117,10 +136,14 @@ class Game:
return
b.right = 1
print 'box', x_b, y_b, b.up, b.left, b.right, b.down
+ if b.check():
+ self.showText('A', x_b , y_b)
if x_b < GRID_SIZE[1]:
b2 = self.boxes[x_b + 1][y_b]
b2.left = 1
print 'box', x_b - 1, y_b, b2.up, b2.left, b2.right, b2.down
+ if b2.check():
+ self.showText('A', x_b + 1, y_b)
pygame.draw.line(self.screen, COLOR1, (r1[1],r2[0]), (r1[1],r2[1]), 5)
return
else:
@@ -134,6 +157,8 @@ class Game:
print 'hay linea'
return
b.left = 1
+ if b.check():
+ self.showText('A', x_b , y_b)
pygame.draw.line(self.screen, COLOR1, (X_OFFSET,r2[0]), (X_OFFSET,r2[1]), 5)
return
elif (x < (self.x_end + T)) and (x > self.x_end):
@@ -147,6 +172,8 @@ class Game:
return
b.right = 1
print 'box', x_b, y_b, b.up, b.left, b.right, b.down
+ if b.check():
+ self.showText('A', x_b , y_b)
pygame.draw.line(self.screen, COLOR1, (self.x_end,r2[0]), (self.x_end,r2[1]), 5)
return
@@ -162,10 +189,14 @@ class Game:
print 'hay linea'
return
b.up = 1
+ if b.check():
+ self.showText('A', x_b , y_b)
if y_b > 0:
b2 = self.boxes[x_b][y_b-1]
b2.down = 1
print 'box', x_b, y_b, b.up, b.left, b.right, b.down
+ if b2.check():
+ self.showText('A', x_b , y_b - 1)
pygame.draw.line(self.screen, COLOR1, (r1[0],r2[0]), (r1[1],r2[0]), 5)
return
elif y > (r2[1] - T):
@@ -178,10 +209,14 @@ class Game:
print 'hay linea'
return
b.down = 1
+ if b.check():
+ self.showText('A', x_b , y_b)
if y_b < GRID_SIZE[1] - 2:
b2 = self.boxes[x_b][y_b+1]
b2.up = 1
print 'box', x_b, y_b, b.up, b.left, b.right, b.down
+ if b2.check():
+ self.showText('A', x_b , y_b + 1)
pygame.draw.line(self.screen, COLOR1, (r1[0],r2[1]), (r1[1],r2[1]), 5)
return
else:
@@ -196,6 +231,8 @@ class Game:
print 'hay linea'
return
b.up = 1
+ if b.check():
+ self.showText('A', x_b , y_b)
pygame.draw.line(self.screen, COLOR1, (r1[0],Y_OFFSET), (r1[1],Y_OFFSET), 5)
return
elif (y < (self.y_end + T)) and (y > self.y_end):
@@ -209,6 +246,8 @@ class Game:
print 'hay linea'
return
b.down = 1
+ if b.check():
+ self.showText('A', x_b , y_b)
pygame.draw.line(self.screen, COLOR1, (r1[0],self.y_end), (r1[1],self.y_end), 5)
return