Changeset 10:f25c0439251f
- Timestamp:
- 12/12/10 21:02:27 (5 years ago)
- Branch:
- default
- Children:
- 11:0ece930a4d1b, 12:a1a766440639
- Parents:
- 8:1b6cfae2315b (diff), 9:2c9ca13b4413 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
engine.py
r8 r10 ˆà 1 1 directions = [(0,1), (1,0), (0,-1), (-1,0)]ˆà ˆà 2 rtm = [[0, -1], [1, 0]]ˆà 2 3 ˆà 3 4 class Cell(object):ˆà òÀæ òÀæ ˆà 29 30 self.h = min(canvas.height, canvas.width)ˆà 30 31 self.snakes = []ˆà 31 ˆà self.field = []ˆà ˆà 32 self.init_field()ˆà ˆà 33 returnˆà ˆà 34 def init_field (self):ˆà ˆà 35 self.field = {}ˆà ˆà 36 for x in range(21):ˆà ˆà 37 for y in range(21):ˆà ˆà 38 self.field[x, y] = Cell(x, y, self.canvas)ˆà ˆà 39 passˆà ˆà 40 passˆà ˆà 41 for y in range(21):ˆà ˆà 42 self.field[0, y].type = 'wall'ˆà ˆà 43 self.field[20, y].type = 'wall'ˆà ˆà 44 passˆà ˆà 45 for x in range(1,20):ˆà ˆà 46 self.field[x, 0].type = 'wall'ˆà ˆà 47 self.field[x, 20].type = 'wall'ˆà ˆà 48 passˆà 32 49 returnˆà 33 50 def step(self):ˆà 34 ˆà passˆà 35 ˆà def move_snake(self):ˆà ˆà 51 for snake in self.snakes:ˆà ˆà 52 self.legal_moves()ˆà ˆà 53 self.move_snake(snake)ˆà ˆà 54 self.refill()ˆà ˆà 55 self.redraw() ˆà ˆà 56 returnˆà ˆà 57 def move_snake(self, snake):ˆà 36 58 passˆà 37 59 def create_snake(self, snake_number):ˆà òÀæ òÀæ ˆà 39 61 def refill(self):ˆà 40 62 passˆà 41 ˆà def redraw(self , w, h):ˆàˆà 63 def redraw(self):ˆà 42 64 passˆà 43 65 def legal_moves(self, snake):ˆà -
engine.py
r9 r10 ˆà 66 66 snake.legal_dir = []ˆà 67 67 for direction in directions:ˆà 68 ˆà dir_ sell = field[snake.sells[0].y + direction[0], snake.sells[0].x + direction[1]]ˆàˆà 68 dir_cell = field[snake.cells[0].y + direction[0], snake.cells[0].x + direction[1]]ˆà 69 69 if (dir_cell.type == 'empty' or (dir_cell.type == 'tail' and dir_cell.snake == 'enemy')):ˆà 70 70 snake.legal_dir.append(direction)ˆà
Note: See TracChangeset
for help on using the changeset viewer.