Äîêóìåíò âçÿò èç êýøà ïîèñêîâîé ìàøèíû. Àäðåñ îðèãèíàëüíîãî äîêóìåíòà : http://kodomo.cmm.msu.su/trac/snake/changeset/1.0.3
Äàòà èçìåíåíèÿ: Unknown
Äàòà èíäåêñèðîâàíèÿ: Sun Apr 10 02:07:44 2016
Êîäèðîâêà: IBM-866
Changeset 182:77dd3fe5a2d4 òÀÓ Python Battle

Changeset 182:77dd3fe5a2d4


Ignore:
Timestamp:
12/26/10 22:21:55 (5 years ago)
Author:
Alex Martynov
Branch:
default
Tags:
1.0.3
Message:

added UI.snake_len_check()

added a winer information at hte end of the game

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main.py

    r181 r182 ˆà
    139139            self.end()ˆà
    140140            return Falseˆà
    ˆà141    def snake_len_check(self):ˆà
    ˆà142        """Get the snake with maximum length - the winerˆà
    ˆà143ˆà
    ˆà144        Return:ˆà
    ˆà145        winer - list of snake or snakes with max lengthˆà
    ˆà146        length - this maximum length"""ˆà
    ˆà147        length=0ˆà
    ˆà148        winer = []ˆà
    ˆà149        for snake in self.engine.snakes:ˆà
    ˆà150            if snake != None:ˆà
    ˆà151                if len(snake.cells) > length:ˆà
    ˆà152                    length = len(snake.cells)ˆà
    ˆà153                    winer = [snake]ˆà
    ˆà154                elif len(snake.cells) == length:ˆà
    ˆà155                    winer.append(snake)    ˆà
    ˆà156        return winer, lengthˆà
    ˆà157        ˆà
    141158        ˆà
    142159    def restart(self, survived):ˆà
    òÀæ òÀæ ˆà
    165182        self.engine.redraw()ˆà
    166183        self.canvas.create_text(offset[0]+ field_geometry[0]/2.0, offset[1]+field_geometry[1]/2.0, text="End of the round", fill="white", font="bold")ˆà
    ˆà184        winer, length = self.snake_len_check()ˆà
    ˆà185        if len(winer) > 1:ˆà
    ˆà186            self.canvas.create_text(offset[0]+ field_geometry[0]/2.0, offset[1]+field_geometry[1]*2.0/3.0, text="Number of winers: %s" %(len(winer)), fill="white", font="bold")ˆà
    ˆà187        else:ˆà
    ˆà188            self.canvas.create_text(offset[0]+ field_geometry[0]/2.0, offset[1]+field_geometry[1]*2.0/3.0, text="Winer: %s" %(winer[0].name), fill="white", font="bold")ˆà
    ˆà189        self.canvas.create_text(offset[0]+ field_geometry[0]/2.0, offset[1]+field_geometry[1]*3.0/4.0, text="Total woner length: %s" %(length), fill="white", font="bold")ˆà
    167190        passˆà
    168191ˆà
Note: See TracChangeset for help on using the changeset viewer.