Äîêóìåíò âçÿò èç êýøà ïîèñêîâîé ìàøèíû. Àäðåñ îðèãèíàëüíîãî äîêóìåíòà : http://kodomo.cmm.msu.su/trac/snake/changeset/160
Äàòà èçìåíåíèÿ: Unknown
Äàòà èíäåêñèðîâàíèÿ: Sun Apr 10 01:35:14 2016
Êîäèðîâêà: IBM-866
Changeset 160:56e7d0bfd362 òÀÓ Python Battle

Changeset 160:56e7d0bfd362


Ignore:
Timestamp:
12/22/10 19:35:56 (5 years ago)
Author:
Alex Martynov
Branch:
default
Message:

changed numeration of the snakes
edited documentation
changed button placement
added restart button
added UI.step_length

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • engine.py

    r156 r160 ˆà
    186186        for y in range(self.start_snake_length):ˆà
    187187            cells_id.insert(0,((f_w-1)/2, y+1))ˆà
    188ˆà        for rot_num in range(snake_number - 1):ˆà
    ˆà188        for rot_num in range(snake_number):ˆà
    189189            for i, cell in enumerate(cells_id):ˆà
    190190                cells_id[i] = (min(f_h, f_w)-1-cell[1],cell[0])ˆà
    òÀæ òÀæ ˆà
    193193            cells.append(self.field[cell])ˆà
    194194        color_dic = {ˆà
    195ˆà            1:'blue',ˆà
    196ˆà            2:'green',ˆà
    197ˆà            3:'yellow',ˆà
    198ˆà            4:'red',}ˆà
    ˆà195            0:'blue',ˆà
    ˆà196            1:'green',ˆà
    ˆà197            2:'yellow',ˆà
    ˆà198            3:'red',}ˆà
    199199        if old_snake == None:ˆà
    200ˆà            self.snakes[snake_number-1] = snake.Snake(cells, color_dic[snake_number])ˆà
    ˆà200            self.snakes[snake_number] = snake.Snake(cells, color_dic[snake_number])ˆà
    201201        else:ˆà
    202202            old_snake.cells = cellsˆà
    203ˆà        self.psnakes[snake_number-1] = self.snakes[snake_number-1]ˆà
    204ˆà        return self.snakes[snake_number-1]ˆà
    ˆà203        return self.snakes[snake_number]ˆà
    205204    ˆà
    206205    def refill(self):ˆà
  • main.py

    r156 r160 ˆà
    77ˆà
    88class UI(object):ˆà
    9ˆà    """User Interface:"""ˆà
    ˆà9    """User Interface:ˆà
    ˆà10ˆà
    ˆà11    Atributes:ˆà
    ˆà12ˆà
    ˆà13    - 'root' - root Window game placed atˆà
    ˆà14    - 'engine' - engine of the gameˆà
    ˆà15    - 'canvas' - Widget field is pictured atˆà
    ˆà16    - 'step_id' - current step of the gameˆà
    ˆà17    - 'after_id' - identificator of runing game processˆà
    ˆà18    - 'step_legth' - fime of the step"""ˆà
    1019    def __init__ (self):ˆà
    1120        """Create Python Battle game window.ˆà
    òÀæ òÀæ ˆà
    1928        self.engine = engine.Engine(self.canvas)ˆà
    2029        self.after_id = Noneˆà
    ˆà30        self.step_length = 150ˆà
    2131        returnˆà
    2232    ˆà
    òÀæ òÀæ ˆà
    2535        Definition of button functions."""ˆà
    2636        buttons = tk.Frame(root)ˆà
    27ˆà        load_1 = tk.Button(buttons, text="Load 1", command=lambda: self.load(1))ˆà
    ˆà37        load_1 = tk.Button(buttons, text="Load 1", command=lambda: self.load(0))ˆà
    2838        load_1.grid(row=1, column=2, stick="news")ˆà
    29ˆà        load_2 = tk.Button(buttons, text="Load 2", command=lambda: self.load(2))ˆà
    ˆà39        load_2 = tk.Button(buttons, text="Load 2", command=lambda: self.load(1))ˆà
    3040        load_2.grid(row=2, column=3, stick="news")ˆà
    3141        run_b = tk.Button(buttons, text="Run", command=lambda: self.run())ˆà
    32ˆà        run_b.grid(row=1, column=5, stick="news")ˆà
    33ˆà        load_3 = tk.Button(buttons, text="Load 3", command=lambda: self.load(3))ˆà
    ˆà42        run_b.grid(row=2, column=2, stick="news")ˆà
    ˆà43        restart_b = tk.Button(buttons, text="Restart", command=lambda: self.restart())ˆà
    ˆà44        restart_b.grid(row=1, column=5, stick="news")ˆà
    ˆà45        load_3 = tk.Button(buttons, text="Load 3", command=lambda: self.load(2))ˆà
    3446        load_3.grid(row=3, column=2, stick="news")ˆà
    35ˆà        load_4 = tk.Button(buttons, text="Load 4", command=lambda: self.load(4))ˆà
    ˆà47        load_4 = tk.Button(buttons, text="Load 4", command=lambda: self.load(3))ˆà
    3648        load_4.grid(row=2, column=1, stick="news")ˆà
    3749        step_b = tk.Button(buttons, text="Step", command=lambda: self.step())ˆà
    òÀæ òÀæ ˆà
    5062            self.step_id = 0ˆà
    5163            self.engine.snakes = [None, None, None, None]ˆà
    52ˆà            self.engine.psnakes = [None, None, None, None]ˆà
    5364            passˆà
    5465        if self.step_id == 0:ˆà
    òÀæ òÀæ ˆà
    6475ˆà
    6576    def run (self):ˆà
    66ˆà        """Run the game with 150 ms step"""ˆà
    67ˆà        if self.step_id == 666:ˆà
    68ˆà            self.step_id = 0ˆà
    69ˆà            for i, snake in enumerate(self.engine.psnakes):ˆà
    70ˆà                self.engine.snakes[i] = snakeˆà
    71ˆà                self.engine.create_snake(i, snake)ˆà
    ˆà77        """Run the game with 'step_length' ms stepˆà
    ˆà78        After the end of the game - restarts it with snakes survived inˆà
    ˆà79        previous game"""ˆà
    ˆà80        self.restart()ˆà
    7281        if self.dead_snake_check() == False:ˆà
    7382            returnˆà
    òÀæ òÀæ ˆà
    7786        self.step_id = self.step_id+1ˆà
    7887        self.engine.step()ˆà
    79ˆà        self.after_id = self.canvas.after(150, self.run)ˆà
    ˆà88        self.after_id = self.canvas.after(self.step_length, self.run)ˆà
    8089        returnˆà
    ˆà90    ˆà
    8191    def step (self):ˆà
    8292        """Do the next game step"""ˆà
    òÀæ òÀæ ˆà
    106116            self.end()ˆà
    107117            return Falseˆà
    ˆà118        ˆà
    ˆà119    def restart(self):ˆà
    ˆà120        """"Restarts the game after the end of the game with snakes survived"""ˆà
    ˆà121        if self.step_id == 666:ˆà
    ˆà122            print "her"ˆà
    ˆà123            self.step_id = 0ˆà
    ˆà124            for i, snake in enumerate(self.engine.psnakes):ˆà
    ˆà125                if self.engine.psnakes[i] != None:ˆà
    ˆà126                    self.engine.snakes[i] = snakeˆà
    ˆà127                    self.engine.create_snake(i, snake)ˆà
    ˆà128            self.engine.refill()ˆà
    ˆà129            self.engine.redraw()ˆà
    ˆà130        self.engine.psnakes = self.engine.snakesˆà
    108131ˆà
    109132    def end (self):ˆà
Note: See TracChangeset for help on using the changeset viewer.