summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Ward <peteraward@gmail.com>2009-09-28 09:52:03 +1000
committerPeter Ward <peteraward@gmail.com>2009-09-28 09:52:03 +1000
commit7b7cddf7389f313af4b7c348c9926729c3bfbaef (patch)
tree01a5227cd1590d2a1a7e40abca5338a4bee1a2ce
parent678f06a14ef733ce5f7265846a9fb14265a34bcd (diff)
Now drawing a nice grid.
-rw-r--r--snake.py17
1 files changed, 13 insertions, 4 deletions
diff --git a/snake.py b/snake.py
index 441e2ec..a977de0 100644
--- a/snake.py
+++ b/snake.py
@@ -8,12 +8,15 @@ pygame.init()
from pygame.locals import *
class SnakeEngine(object):
+ EDGE_COLOR = (255, 255, 255)
+ EDGE_WIDTH = 1
+
def __init__(self, rows, columns, n_apples, width=800, height=600, fullscreen=False):
super(SnakeEngine, self).__init__()
flags = 0
if fullscreen:
flags |= pygame.FULLSCREEN
- pygame.display.set_mode((width, height), flags)
+ self.screen = pygame.display.set_mode((width, height), flags)
self.width = width
self.height = height
@@ -64,16 +67,22 @@ class SnakeEngine(object):
for y, row in enumerate(self.board):
for x, cell in enumerate(row):
- r = Rect(y * yscale, x * xscale, xscale, yscale)
- print r
+ left = int(x * xscale)
+ top = int(y * yscale)
+ w = int((x + 1) * xscale) - left
+ h = int((y + 1) * yscale) - top
+ r = Rect(left, top, w, h)
+ pygame.draw.rect(self.screen, self.EDGE_COLOR, r,
+ self.EDGE_WIDTH)
def run(self):
self.draw_board()
+ pygame.display.flip()
if __name__ == '__main__':
from bots import random_bot
- game = SnakeEngine(16, 8, 10)
+ game = SnakeEngine(8, 16, 10)
game.add_bot('Bob', random_bot)
game.run()