Äîêóìåíò âçÿò èç êýøà ïîèñêîâîé ìàøèíû. Àäðåñ îðèãèíàëüíîãî äîêóìåíòà : http://kodomo.fbb.msu.ru/trac/snake/changeset/111%3A9486211ec334
Äàòà èçìåíåíèÿ: Unknown
Äàòà èíäåêñèðîâàíèÿ: Sun Apr 10 09:29:36 2016
Êîäèðîâêà: IBM-866
Changeset 111:9486211ec334 òÀÓ Python Battle

Changeset 111:9486211ec334


Ignore:
Timestamp:
12/20/10 12:58:35 (5 years ago)
Author:
Alex Martynov <martiran@òÀæ>
Branch:
default
Message:

damn

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • engine.py

    r108 r111 ˆà
    55directions = [(0,1), (1,0), (0,-1), (-1,0)]ˆà
    66tm = [[0, -1], [1, 0]]ˆà
    ˆà7ˆà
    ˆà8class Dict(dict):ˆà
    ˆà9    passˆà
    710ˆà
    811class Cell(object):ˆà
    òÀæ òÀæ ˆà
    1518        returnˆà
    1619    def redraw(self):ˆà
    17ˆà        field_size = min(self.canvas.winfo_height(), self.canvas.winfo_width())ˆà
    18ˆà        offset = ((self.canvas.winfo_width() - field_size)/2.0, (self.canvas.winfo_height() - field_size)/2.0)ˆà
    19ˆà        x0=offset[0] + self.x*field_size/21.0ˆà
    20ˆà        y0=offset[1] + self.y*field_size/21.0ˆà
    21ˆà        x1=offset[0] + (self.x+1)*field_size/21.0ˆà
    22ˆà        y1=offset[1] + (self.y+1)*field_size/21.0ˆà
    23ˆà        x2=offset[0] + (self.x+1/2.0)*field_size/21.0ˆà
    ˆà20        field_geometry = min(self.canvas.winfo_height(), self.canvas.winfo_width())ˆà
    ˆà21        f_s = float(self.field.size)ˆà
    ˆà22        offset = ((self.canvas.winfo_width() - field_geometry)/2.0, (self.canvas.winfo_height() - field_geometry)/2.0)ˆà
    ˆà23        x0=offset[0] + self.x*field_geometry/f_sˆà
    ˆà24        y0=offset[1] + self.y*field_geometry/f_sˆà
    ˆà25        x1=offset[0] + (self.x+1)*field_geometry/f_sˆà
    ˆà26        y1=offset[1] + (self.y+1)*field_geometry/f_sˆà
    ˆà27        x2=offset[0] + (self.x+1/2.0)*field_geometry/f_sˆà
    2428        if self.type == 'wall':ˆà
    2529            self.canvas.create_rectangle(x0, y0, x1, y1, fill="grey")ˆà
    òÀæ òÀæ ˆà
    6165        self.snakes = [None, None, None, None]ˆà
    6266        self.init_field()ˆà
    ˆà67        self.start_snake_length = 10ˆà
    6368        returnˆà
    6469    def init_field (self):ˆà
    65ˆà        self.field = {}ˆà
    66ˆà        for x in range(21):ˆà
    67ˆà            for y in range(21):ˆà
    ˆà70        self.field = Dict()ˆà
    ˆà71        self.field.size = 27ˆà
    ˆà72        f_s = self.field.sizeˆà
    ˆà73        for x in range(f_s):ˆà
    ˆà74            for y in range(f_s):ˆà
    6875                self.field[x, y] = Cell(x, y, self.canvas)ˆà
    69ˆà        for y in range(21):ˆà
    ˆà76        for y in range(f_s):ˆà
    7077            self.field[0, y].type = 'wall'ˆà
    71ˆà            self.field[20, y].type = 'wall'ˆà
    72ˆà        for x in range(1,20):ˆà
    ˆà78            self.field[f_s-1, y].type = 'wall'ˆà
    ˆà79        for x in range(1,f_s-1):ˆà
    7380            self.field[x, 0].type = 'wall'ˆà
    74ˆà            self.field[x, 20].type = 'wall'ˆà
    ˆà81            self.field[x, f_s-1].type = 'wall'ˆà
    7582        self.refill()ˆà
    7683        self.redraw()ˆà
    òÀæ òÀæ ˆà
    113120    def create_snake(self, snake_number):ˆà
    114121        cells_id = []ˆà
    115ˆà        for y in range(10):ˆà
    116ˆà            cells_id.append((10, y+1))ˆà
    ˆà122        f_s = self.field.sizeˆà
    ˆà123        for y in range(self.start_snake_length):ˆà
    ˆà124            cells_id.append(((f_s+1)/2, y+1))ˆà
    117125        for rot_num in range(snake_number - 1):ˆà
    118126            for i, cell in enumerate(cells_id):ˆà
    òÀæ òÀæ ˆà
    129137        return self.snakes[snake_number-1]ˆà
    130138    def refill(self):ˆà
    131ˆà        for x in range(1,20):ˆà
    132ˆà            for y in range(1,20):ˆà
    ˆà139        f_s = self.field.sizeˆà
    ˆà140        for x in range(1,f_s-1):ˆà
    ˆà141            for y in range(1,f_s-1):ˆà
    133142                self.field[x, y].type = 'empty'ˆà
    134143                self.field[x, y].snake = Noneˆà
  • main.py

    r107 r111 ˆà
    5151        self.step_id = self.step_id+1ˆà
    5252        self.engine.step()ˆà
    53ˆà        self.after_id = self.canvas.after(300, self.run())ˆà
    ˆà53        self.after_id = self.canvas.after(300, self.run)ˆà
    5454        if self.step_id == 200:ˆà
    5555            self.end()ˆà
  • snake.py

    • Property exe set to *
    r104 r111 ˆà
    4747        for cell in self.cells:ˆà
    4848            cell.snake = selfˆà
    ˆà49        for cell in self.cells:ˆà
    ˆà50            cell.type = 'body'ˆà
    4951        self.cells[0].type = 'head'ˆà
    50ˆà        for cell in self.cells[1:-1]:ˆà
    51ˆà            cell.type = 'body'ˆà
    5252        self.cells[-1].type = 'tail'ˆà
    5353        returnˆà
Note: See TracChangeset for help on using the changeset viewer.