snake
diff engine.py @ 10:f25c0439251f
Automated merge with ssh://kodomo.fbb.msu.ru/snake
author | Alex Martynov <martiran@kodomo.fbb.msu.ru> |
---|---|
date | Sun, 12 Dec 2010 21:02:27 +0300 |
parents | 1b6cfae2315b 2c9ca13b4413 |
children | 0ece930a4d1b a1a766440639 |
line diff
1.1 --- a/engine.py Sat Dec 11 18:51:57 2010 +0300 1.2 +++ b/engine.py Sun Dec 12 21:02:27 2010 +0300 1.3 @@ -1,4 +1,5 @@ 1.4 directions = [(0,1), (1,0), (0,-1), (-1,0)] 1.5 +rtm = [[0, -1], [1, 0]] 1.6 1.7 class Cell(object): 1.8 def __init__(self, x, y, canvas): 1.9 @@ -28,17 +29,38 @@ 1.10 self.w = min(canvas.height, canvas.width) 1.11 self.h = min(canvas.height, canvas.width) 1.12 self.snakes = [] 1.13 - self.field = [] 1.14 + self.init_field() 1.15 + return 1.16 + def init_field (self): 1.17 + self.field = {} 1.18 + for x in range(21): 1.19 + for y in range(21): 1.20 + self.field[x, y] = Cell(x, y, self.canvas) 1.21 + pass 1.22 + pass 1.23 + for y in range(21): 1.24 + self.field[0, y].type = 'wall' 1.25 + self.field[20, y].type = 'wall' 1.26 + pass 1.27 + for x in range(1,20): 1.28 + self.field[x, 0].type = 'wall' 1.29 + self.field[x, 20].type = 'wall' 1.30 + pass 1.31 return 1.32 def step(self): 1.33 - pass 1.34 - def move_snake(self): 1.35 + for snake in self.snakes: 1.36 + self.legal_moves() 1.37 + self.move_snake(snake) 1.38 + self.refill() 1.39 + self.redraw() 1.40 + return 1.41 + def move_snake(self, snake): 1.42 pass 1.43 def create_snake(self, snake_number): 1.44 pass 1.45 def refill(self): 1.46 pass 1.47 - def redraw(self, w, h): 1.48 + def redraw(self): 1.49 pass 1.50 def legal_moves(self, snake): 1.51 snake.legal_dir = []