Документ взят из кэша поисковой машины. Адрес оригинального документа : http://kodomo.fbb.msu.ru/hg/snake/rev/36756bd7e7ed
Дата изменения: Unknown
Дата индексирования: Mon Oct 1 23:36:57 2012
Кодировка:
snake: 36756bd7e7ed

snake

changeset 167:36756bd7e7ed

added oftions for UI.restart()
author Alex Martynov
date Thu, 23 Dec 2010 20:24:56 +0300
parents f99b094a3d5d
children 0f7df983d610
files main.py
diffstat 1 files changed, 14 insertions(+), 9 deletions(-) [+]
line diff
     1.1 --- a/main.py	Thu Dec 23 20:09:48 2010 +0300
     1.2 +++ b/main.py	Thu Dec 23 20:24:56 2010 +0300
     1.3 @@ -42,7 +42,7 @@
     1.4          load_2.grid(row=2, column=3, stick="news")
     1.5          run_b = tk.Button(buttons, text="Run", command=lambda: self.start())
     1.6          run_b.grid(row=2, column=2, stick="news")
     1.7 -        restart_b = tk.Button(buttons, text="Restart", command=lambda: self.restart())
     1.8 +        restart_b = tk.Button(buttons, text="Restart", command=lambda: self.restart(survived="no"))
     1.9          restart_b.grid(row=1, column=5, stick="news")
    1.10          load_3 = tk.Button(buttons, text="Load 3", command=lambda: self.load(2))
    1.11          load_3.grid(row=3, column=2, stick="news")
    1.12 @@ -78,7 +78,7 @@
    1.13      def start (self):
    1.14          """Init running of the game."""
    1.15          if self.step_id == self.game_length + 666:
    1.16 -            self.next_round()
    1.17 +            self.restart(survived="yes")
    1.18          if self.dead_snake_check() == False:
    1.19              return
    1.20          if self.step_id > self.game_length:
    1.21 @@ -124,19 +124,24 @@
    1.22              self.end()
    1.23              return False
    1.24          
    1.25 -    def restart(self):
    1.26 -        """"Restarts the game after the end of the game with snakes survived"""
    1.27 +    def restart(self, survived):
    1.28 +        """"Restarts snakes positions after the end of the game
    1.29 +
    1.30 +        Options:
    1.31 +        survived = "yes" - restarts next round only with snakes survived in previous round
    1.32 +        survived = "no" - restart next roun with all snakes played in previous round"""
    1.33 +        if survived == "yes":
    1.34 +            snake_set = self.engine.snakes
    1.35 +        else:
    1.36 +            snake_set = self.engine.psnakes          
    1.37          self.step_id = 0
    1.38 -        for i, snake in enumerate(self.engine.psnakes):
    1.39 -            if self.engine.psnakes[i] != None:
    1.40 +        for i, snake in enumerate(snake_set):
    1.41 +            if snake_set[i] != None:
    1.42                  self.engine.snakes[i] = snake
    1.43                  self.engine.create_snake(i, snake)
    1.44          self.engine.refill()
    1.45          self.engine.redraw()
    1.46  
    1.47 -    def next_round(self):
    1.48 -        pass
    1.49 -
    1.50      def end (self):
    1.51          """End the game and raise the window that tels about it."""
    1.52          if self.after_id != None: