Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from Tkinter import *
- from WalkingUnitsModel import walkingUnitsModel
- import time
- class walkingUnitsApp(Frame):
- """Creates a Frame for showing units moving along a path"""
- def __init__(self):
- """initializes frame"""
- Frame.__init__(self)
- self.master.title("Walking Units Simulator")
- self.config(width=600)
- self.config(height=500)
- self.master.resizable(0,0)
- self.grid()
- #self._dataModel = walkingUnitsModel()
- self._queueTotal = 0
- self._background = PhotoImage(file = 'BackGround.gif')
- self._backgroundLabel = Label(self, image = self._background)
- self._backgroundLabel.grid(column = 0, row = 0, rowspan = 3)
- self._enqueueButton = Button(self, text = "Queue a Unit", command = self._enqueue)
- self._enqueueButton.grid(column = 1, row = 0)
- self._dequeueButton = Button(self, text = "Start a Unit", command = self._dequeue)
- self._dequeueButton.grid(column = 1, row = 1)
- self._queueLabel = Label(self, text = "In Queue: " + str(self._queueTotal))
- self._queueLabel.grid(column = 1, row = 2)
- #self._countdown()
- def _enqueue(self):
- """queues a unit in to be set on the path"""
- #self._dataModel.makeUnit()
- self._queueTotal += 1
- def _dequeue(self):
- """sets a queued unit on the path"""
- #self._dataModel.startUnit()
- self._queueTotal -= 1
- def _countdown(self):
- """timer for redrawing units"""
- #while True:
- #self._draw()
- #time.sleep(1)
- def _draw(self):
- """redraws the units"""
- #self._dataModel.moveAll()
- def main():
- walkingUnitsApp().mainloop()
- if __name__ == "__main__":
- main()
- from linkedlist import LinkedList
- from coordinate import Coordinate
- from linkedqueue import LinkedQueue
- from unit import Unit
- from images import Image
- class walkingUnitsModel(object):
- def __init__(self):
- self._path = LinkedList()
- for i in range(500):
- self._path.add(Coordinate(i, i))
- self._movingUnits = LinkedList()
- self._queuedUnits = LinkedQueue()
- def makeUnit(self):
- self._queuedUnits.add(Unit(Image("unitsmall.gif"), self._path.head))
- def startUnit(self):
- self._movingUnits.add(self._queuedUnits.pop())
- def __step(self, unit):
- unit._position = unit._position.next
- if unit._position == None:
- self._movingUnits.remove(unit)
- def moveAll(self):
- for unit in self._movingUnits:
- self.__step(unit)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement