Äîêóìåíò âçÿò èç êýøà ïîèñêîâîé ìàøèíû. Àäðåñ îðèãèíàëüíîãî äîêóìåíòà : http://kodomo.cmm.msu.ru/trac/snake/changeset/10%3Af25c0439251f
Äàòà èçìåíåíèÿ: Unknown
Äàòà èíäåêñèðîâàíèÿ: Sun Apr 10 21:42:03 2016
Êîäèðîâêà: IBM-866
Changeset 10:f25c0439251f òÀÓ Python Battle

Changeset 10:f25c0439251f


Ignore:
Timestamp:
12/12/10 21:02:27 (5 years ago)
Author:
Alex Martynov <martiran@òÀæ>
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.
Message:

Automated merge with òÀËssh://kodomo.fbb.msu.ru/snake

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • engine.py

    r8 r10 ˆà
    11directions = [(0,1), (1,0), (0,-1), (-1,0)]ˆà
    ˆà2rtm = [[0, -1], [1, 0]]ˆà
    23ˆà
    34class Cell(object):ˆà
    òÀæ òÀæ ˆà
    2930        self.h = min(canvas.height, canvas.width)ˆà
    3031        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ˆà
    3249        returnˆà
    3350    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):ˆà
    3658        passˆà
    3759    def create_snake(self, snake_number):ˆà
    òÀæ òÀæ ˆà
    3961    def refill(self):ˆà
    4062        passˆà
    41ˆà    def redraw(self, w, h):ˆà
    ˆà63    def redraw(self):ˆà
    4264        passˆà
    4365    def legal_moves(self, snake):ˆà
  • engine.py

    r9 r10 ˆà
    6666        snake.legal_dir = []ˆà
    6767        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]]ˆà
    6969            if (dir_cell.type == 'empty' or (dir_cell.type == 'tail' and dir_cell.snake == 'enemy')):ˆà
    7070                snake.legal_dir.append(direction)ˆà
Note: See TracChangeset for help on using the changeset viewer.