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

Changeset 32:b2eaeeb74d87


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

fixed lots of small errors

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • engine.py

    r31 r32 ˆà
    1414        returnˆà
    1515    def redraw(self):ˆà
    16ˆà        field_size = min(canvas.height, canvas.width)ˆà
    17ˆà        offset = (canvas.width - field_size, canvas.hieght - field_size)ˆà
    ˆà16        field_size = min(self.canvas.height, self.canvas.width)ˆà
    ˆà17        offset = (self.canvas.width - field_size, self.canvas.hieght - field_size)ˆà
    1818        if self.type == 'wall':ˆà
    1919            self.canvas.create_rectangle(offset[0], offset[1], offset[0] + self.x*field_size/21.0, offset[1] + self.y*field_size/21.0, fill="grey")ˆà
    òÀæ òÀæ ˆà
    113113        returnˆà
    114114    def create_snake(self, snake_number):ˆà
    ˆà115        ˆà
    115116        passˆà
    116117    def refill(self):ˆà
    òÀæ òÀæ ˆà
    129130    def redraw(self):ˆà
    130131        self.canvas.delete(all)ˆà
    131ˆà        for cell in self.field:ˆà
    132ˆà            cell.redraw()ˆà
    ˆà132        for cell_coord in self.field:ˆà
    ˆà133            self.field[cell_coord].redraw()ˆà
    133134        returnˆà
    134135    def legal_moves(self, snake):ˆà
  • main.py

    r29 r32 ˆà
    22import tkFileDialog as tkfdˆà
    33import engineˆà
    ˆà4import snakeˆà
    45ˆà
    56ˆà
    òÀæ òÀæ ˆà
    1617        self.step_id = 0ˆà
    1718        self.engine = engine.Engine(self.canvas)ˆà
    ˆà19        self.after_id = Noneˆà
    1820        returnˆà
    1921    def buttons_pack(self, frame):ˆà
    20ˆà        load_1 = tk.Button(frame, text="Load", command=lambda: self.load(1))ˆà
    21ˆà        load_1.pack(side="top", fill="both", expand = "yes")ˆà
    22ˆà        load_2 = tk.Button(frame, text="Load", command=lambda: self.load(2))ˆà
    23ˆà        load_2.pack(side="top", fill="both", expand = "yes")ˆà
    ˆà22        load_1 = tk.Button(frame, text="Load 1", command=lambda: self.load(1))ˆà
    ˆà23        load_1.pack(side="left", fill="both", expand = "yes")ˆà
    ˆà24        load_2 = tk.Button(frame, text="Load 2", command=lambda: self.load(2))ˆà
    ˆà25        load_2.pack(side="left", fill="both", expand = "yes")ˆà
    2426        run_b = tk.Button(frame, text="Run", command=lambda: self.run())ˆà
    25ˆà        run_b.pack(side="top", fill="both", expand = "yes")ˆà
    26ˆà        load_3 = tk.Button(frame, text="Load", command=lambda: self.load(3))ˆà
    27ˆà        load_3.pack(side="bottom", fill="both", expand = "yes")ˆà
    28ˆà        load_4 = tk.Button(frame, text="Load", command=lambda: self.load(4))ˆà
    29ˆà        load_4.pack(side="bottom", fill="both", expand = "yes")ˆà
    ˆà27        run_b.pack(side="left", fill="both", expand = "yes")ˆà
    ˆà28        load_3 = tk.Button(frame, text="Load 3", command=lambda: self.load(3))ˆà
    ˆà29        load_3.pack(side="right", fill="both", expand = "yes")ˆà
    ˆà30        load_4 = tk.Button(frame, text="Load 4", command=lambda: self.load(4))ˆà
    ˆà31        load_4.pack(side="right", fill="both", expand = "yes")ˆà
    3032        step_b = tk.Button(frame, text="Step", command=lambda: self.step())ˆà
    31ˆà        step_b.pack(side="bottom", fill="both", expand = "yes")ˆà
    ˆà33        step_b.pack(side="right", fill="both", expand = "yes")ˆà
    3234        returnˆà
    3335    ˆà
    òÀæ òÀæ ˆà
    4648ˆà
    4749    def run (self):ˆà
    48ˆà        self.step_id = self.id+1ˆà
    ˆà50        self.step_id = self.step_id+1ˆà
    4951        self.engine.step()ˆà
    5052        self.after_id = self.canvas.after(300, self.run())ˆà
    òÀæ òÀæ ˆà
    5557        returnˆà
    5658    def step (self):ˆà
    57ˆà        if self.id <= 200:ˆà
    58ˆà            self.canvas.after_cancel(self.after_id)ˆà
    59ˆà            self.id = self.id+1ˆà
    ˆà59        if self.step_id <= 200:ˆà
    ˆà60            if self.after_id != None:ˆà
    ˆà61                self.canvas.after_cancel(self.after_id)ˆà
    ˆà62                passˆà
    ˆà63            self.step_id = self.step_id+1ˆà
    6064            self.engine.step()ˆà
    6165            passˆà
    òÀæ òÀæ ˆà
    7175        root.mainloop()ˆà
    7276        passˆà
    ˆà77ˆà
    ˆà78snake_batle = UI()ˆà
    ˆà79snake_batle.root.mainloop()ˆà
    7380        ˆà
  • snake.py

    r31 r32 ˆà
    11ˆà
    22class Snake(object):ˆà
    3ˆà    def __init__ (self, cells):ˆà
    ˆà3    def __init__ (self, cells, color):ˆà
    ˆà4        self.cells = cellsˆà
    ˆà5        self.color = colorˆà
    ˆà6        self.rules = []ˆà
    47        passˆà
    58    def load (self, file):ˆà
    ˆà9        ˆà
    610        passˆà
    711    def fill (self):ˆà
    8ˆà        for sell in self.sells:ˆà
    9ˆà            sell.snake = selfˆà
    ˆà12        for cell in self.cells:ˆà
    ˆà13            cell.snake = selfˆà
    1014        snake.cells[0].type = 'head'ˆà
    1115        snake.cells[-1].type = 'tail'ˆà
    òÀæ òÀæ ˆà
    1519ˆà
    1620class Rule(object):ˆà
    17ˆà    def __init__ (self):ˆà
    ˆà21    def __init__ (self, snake):ˆà
    ˆà22        self.snake = snakeˆà
    ˆà23        self.direction = (1, -1)ˆà
    1824        passˆà
    19ˆà    def load (file):ˆà
    ˆà25    def load (self, file):ˆà
    ˆà26        ˆà
    2027        passˆà
    21ˆà    def applies (field, x, y):ˆà
    ˆà28    def applies (self, field, x, y):ˆà
    ˆà29        ˆà
    2230        passˆà
    23ˆà    def rotate (rot):ˆà
    ˆà31    def rotate (self, rot):ˆà
    2432        passˆà
Note: See TracChangeset for help on using the changeset viewer.