Add tiles to the board. Skip draw for other game scene widgets for now
authorNeil <neil@dip.sun.ac.za>
Sun, 11 May 2014 17:02:46 +0000 (19:02 +0200)
committerNeil <neil@dip.sun.ac.za>
Sun, 11 May 2014 17:03:14 +0000 (19:03 +0200)
naja/constants.py
naja/widgets/board.py
naja/widgets/game_bits.py
naja/widgets/info_area.py
naja/widgets/player_bits.py
naja/widgets/tile.py

index d8087d617fb2168a1e3385d4e41e3546d55b26ac..d7e023a557700404c32bd63fa156bd6e75afac69 100644 (file)
@@ -36,4 +36,8 @@ BITS = AttrDict({
 DIRECTION_BITS = AttrDict((k, v) for k, v in BITS.items() if v < 4)
 CONDITION_BITS = AttrDict((k, v) for k, v in BITS.items() if v >= 4)
 
+# Game size constants
 TILE_SIZE = (96, 96)
+BOARD_SIZE = (5 * TILE_SIZE[0], 5 * TILE_SIZE[1])
+BIT_SIZE = (5 * TILE_SIZE[0], (SCREEN[1] - 5 * TILE_SIZE[1]) // 2)
+INFO_SIZE = (SCREEN[0] - 5 * TILE_SIZE[0], SCREEN[1])
index c791a57610231ccd477e14e30ebf6b4d993f2ba9..1f59f015f1cb1eacd5bb68de952986942c160b3c 100644 (file)
@@ -2,18 +2,31 @@
 Widget that holds the game tiles.
 """
 
+from naja.constants import BOARD_SIZE, TILE_SIZE
+
 from .base import Widget
+from .tile import TileWidget
 
 
 class BoardWidget(Widget):
     """
     Widget which holds all the tiles that make up the gameboard.
     """
-    def __init__(self, pos, image=None):
-        super(BoardWidget, self).__init__(pos, (96, 96))
+    def __init__(self, pos, tiles=None):
+        super(BoardWidget, self).__init__(pos, BOARD_SIZE)
+        # FIXME: Placeholder logic
+        self._tiles = []
+        for y in range(0, 5):
+            for x in range(0, 5):
+                tile_pos = (pos[0] + x * TILE_SIZE[0],
+                            pos[1] + y * TILE_SIZE[1])
+                self._tiles.append(TileWidget(tile_pos, None))
 
     def prepare(self):
-        pass
+        for tile in self._tiles:
+            tile.prepare()
+        self.size = BOARD_SIZE
 
     def draw(self, surface):
-        surface.blit(self.surface, self.rect)
+        for tile in self._tiles:
+            tile.draw(surface)
index 54fa6834623e36e6367a2054ea8db7f7d2471416..875558cd76b068ffcf448cc2a7bb2c6bdbb6da74 100644 (file)
@@ -2,6 +2,8 @@
 Widget that holds the games's bits.
 """
 
+from naja.constants import BIT_SIZE
+
 from .base import Widget
 
 
@@ -10,10 +12,11 @@ class GameBitsWidget(Widget):
     Widget which holds the game's bits.
     """
     def __init__(self, pos, image=None):
-        super(GameBitsWidget, self).__init__(pos, (96, 96))
+        super(GameBitsWidget, self).__init__(pos, BIT_SIZE)
 
     def prepare(self):
         pass
 
     def draw(self, surface):
-        surface.blit(self.surface, self.rect)
+        pass
+        #surface.blit(self.surface, self.rect)
index 2f9331169284415cb2875de7c43c829d1ca971f7..2a9b50f78ea4a612ddb269f9eb330e9e0c0be7d6 100644 (file)
@@ -2,6 +2,8 @@
 Widget for the game board information area.
 """
 
+from naja.constants import INFO_SIZE
+
 from .base import Widget
 
 
@@ -10,10 +12,11 @@ class InfoAreaWidget(Widget):
     Widget for the game board information area.
     """
     def __init__(self, pos, image=None):
-        super(InfoAreaWidget, self).__init__(pos, (96, 96))
+        super(InfoAreaWidget, self).__init__(pos, INFO_SIZE)
 
     def prepare(self):
         pass
 
     def draw(self, surface):
-        surface.blit(self.surface, self.rect)
+        pass
+        #surface.blit(self.surface, self.rect)
index e82f173df4cb0d0e5a84c1c6b2ee0132d5f63bc7..0214bda757639235fd601605632ddd1821235e57 100644 (file)
@@ -3,6 +3,7 @@ Widget that holds the player's bits.
 """
 
 from .base import Widget
+from naja.constants import BIT_SIZE
 
 
 class PlayerBitsWidget(Widget):
@@ -10,10 +11,11 @@ class PlayerBitsWidget(Widget):
     Widget which holds the player's bits.
     """
     def __init__(self, pos, image=None):
-        super(PlayerBitsWidget, self).__init__(pos, (96, 96))
+        super(PlayerBitsWidget, self).__init__(pos, BIT_SIZE)
 
     def prepare(self):
         pass
 
     def draw(self, surface):
-        surface.blit(self.surface, self.rect)
+        pass
+        #surface.blit(self.surface, self.rect)
index db20cda7a597c9eec410967381e586cf85ef315a..1950996aea0dd70391e6986d26d5cd242781fa2b 100644 (file)
@@ -1,7 +1,8 @@
 from naja.constants import TILE_SIZE
-from naja.widgets.base import Widget
 from naja.resources import resources
 
+from .base import Widget
+
 # These will probably need to go away when we have images
 import pygame
 import pygame.locals as pgl
@@ -15,7 +16,7 @@ class TileWidget(Widget):
 
     def prepare(self):
         # Placeholder logic - just draw the outline of a square
-        self.surface = pygame.surface.Surface(self.size)
+        self.surface = pygame.surface.Surface(TILE_SIZE)
         pygame.draw.lines(self.surface, pgl.color.THECOLORS['yellow'],
                           True, [(1, 1), (1, 95), (95, 95), (95, 1)], 2)
         self.surface.convert_alpha(pygame.display.get_surface())