Документ взят из кэша поисковой машины. Адрес оригинального документа : http://kodomo.fbb.msu.ru/hg/snake/annotate/76d0514d1ef9/main.py
Дата изменения: Unknown
Дата индексирования: Fri Feb 28 19:05:10 2014
Кодировка:
snake: main.py annotate

snake

annotate main.py @ 31:76d0514d1ef9

Engine.refill() -> Snake.fill()
author Alex Martynov <martiran@kodomo.fbb.msu.ru>
date Sun, 19 Dec 2010 16:54:12 +0300
parents 06f6a43de54a
children b2eaeeb74d87
rev   line source
martiran@18 1 import Tkinter as tk
Alex@23 2 import tkFileDialog as tkfd
martiran@20 3 import engine
martiran@18 4
martiran@18 5
martiran@18 6
martiran@18 7 class UI(object):
martiran@19 8 def __init__ (self):
martiran@29 9 self.root = tk.Tk()
martiran@29 10 self.root.title("Python Battle")
martiran@29 11 self.canvas = tk.Canvas(self.root, background = "black")
martiran@19 12 self.canvas.pack(side ="top", fill="both", expand="yes")
martiran@29 13 buttons = tk.Frame(self.root)
martiran@20 14 buttons.pack(side ="bottom", fill="both", expand="yes")
martiran@20 15 self.buttons_pack(buttons)
martiran@28 16 self.step_id = 0
martiran@19 17 self.engine = engine.Engine(self.canvas)
martiran@18 18 return
martiran@20 19 def buttons_pack(self, frame):
martiran@28 20 load_1 = tk.Button(frame, text="Load", command=lambda: self.load(1))
martiran@20 21 load_1.pack(side="top", fill="both", expand = "yes")
martiran@28 22 load_2 = tk.Button(frame, text="Load", command=lambda: self.load(2))
martiran@20 23 load_2.pack(side="top", fill="both", expand = "yes")
martiran@28 24 run_b = tk.Button(frame, text="Run", command=lambda: self.run())
martiran@20 25 run_b.pack(side="top", fill="both", expand = "yes")
martiran@28 26 load_3 = tk.Button(frame, text="Load", command=lambda: self.load(3))
martiran@20 27 load_3.pack(side="bottom", fill="both", expand = "yes")
martiran@28 28 load_4 = tk.Button(frame, text="Load", command=lambda: self.load(4))
martiran@20 29 load_4.pack(side="bottom", fill="both", expand = "yes")
martiran@28 30 step_b = tk.Button(frame, text="Step", command=lambda: self.step())
martiran@20 31 step_b.pack(side="bottom", fill="both", expand = "yes")
martiran@20 32 return
martiran@29 33
Alex@23 34 def load (self, snake_number):
martiran@29 35 if self.step_id >= 200:
martiran@29 36 self.step_id = 0
martiran@29 37 pass
martiran@29 38 elif self.step_id == 0:
martiran@29 39 file_name = tkfd.askopenfilename(title="Open file")
martiran@29 40 snake = self.engine.create_snake(snake_number)
martiran@29 41 snake.load(file_name)
martiran@29 42 pass
martiran@29 43 else:
martiran@29 44 pass
Alex@27 45 return
Alex@23 46
martiran@18 47 def run (self):
martiran@28 48 self.step_id = self.id+1
martiran@28 49 self.engine.step()
martiran@28 50 self.after_id = self.canvas.after(300, self.run())
martiran@28 51 if self.step_id == 200:
martiran@28 52 self.canvas.after_cancel(self.after_id)
martiran@28 53 self.end()
martiran@28 54 pass
martiran@28 55 return
martiran@28 56 def step (self):
martiran@29 57 if self.id <= 200:
martiran@29 58 self.canvas.after_cancel(self.after_id)
martiran@29 59 self.id = self.id+1
martiran@29 60 self.engine.step()
martiran@29 61 pass
martiran@29 62 else:
martiran@29 63 self.end()
martiran@29 64 pass
martiran@29 65 return
Alex@23 66
martiran@28 67 def end (self):
martiran@29 68 root = tk.Tk()
martiran@29 69 end_label = tk.Label(root, text="End")
martiran@29 70 end_label.pack()
martiran@29 71 root.mainloop()
martiran@18 72 pass
martiran@18 73