Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. from Tkinter import *
  2. from WalkingUnitsModel import walkingUnitsModel
  3. import time
  4.  
  5. class walkingUnitsApp(Frame):
  6. """Creates a Frame for showing units moving along a path"""
  7.  
  8. def __init__(self):
  9. """initializes frame"""
  10. Frame.__init__(self)
  11. self.master.title("Walking Units Simulator")
  12. self.config(width=600)
  13. self.config(height=500)
  14. self.master.resizable(0,0)
  15. self.grid()
  16.  
  17. #self._dataModel = walkingUnitsModel()
  18. self._queueTotal = 0
  19.  
  20. self._background = PhotoImage(file = 'BackGround.gif')
  21. self._backgroundLabel = Label(self, image = self._background)
  22. self._backgroundLabel.grid(column = 0, row = 0, rowspan = 3)
  23.  
  24. self._enqueueButton = Button(self, text = "Queue a Unit", command = self._enqueue)
  25. self._enqueueButton.grid(column = 1, row = 0)
  26.  
  27. self._dequeueButton = Button(self, text = "Start a Unit", command = self._dequeue)
  28. self._dequeueButton.grid(column = 1, row = 1)
  29.  
  30. self._queueLabel = Label(self, text = "In Queue: " + str(self._queueTotal))
  31. self._queueLabel.grid(column = 1, row = 2)
  32.  
  33. #self._countdown()
  34.  
  35. def _enqueue(self):
  36. """queues a unit in to be set on the path"""
  37. #self._dataModel.makeUnit()
  38. self._queueTotal += 1
  39.  
  40. def _dequeue(self):
  41. """sets a queued unit on the path"""
  42. #self._dataModel.startUnit()
  43. self._queueTotal -= 1
  44.  
  45. def _countdown(self):
  46. """timer for redrawing units"""
  47. #while True:
  48. #self._draw()
  49. #time.sleep(1)
  50.  
  51. def _draw(self):
  52. """redraws the units"""
  53. #self._dataModel.moveAll()
  54.  
  55.  
  56. def main():
  57. walkingUnitsApp().mainloop()
  58.  
  59. if __name__ == "__main__":
  60. main()
  61.  
  62. from linkedlist import LinkedList
  63. from coordinate import Coordinate
  64. from linkedqueue import LinkedQueue
  65. from unit import Unit
  66. from images import Image
  67.  
  68. class walkingUnitsModel(object):
  69. def __init__(self):
  70. self._path = LinkedList()
  71. for i in range(500):
  72. self._path.add(Coordinate(i, i))
  73. self._movingUnits = LinkedList()
  74. self._queuedUnits = LinkedQueue()
  75.  
  76. def makeUnit(self):
  77. self._queuedUnits.add(Unit(Image("unitsmall.gif"), self._path.head))
  78.  
  79. def startUnit(self):
  80. self._movingUnits.add(self._queuedUnits.pop())
  81.  
  82. def __step(self, unit):
  83. unit._position = unit._position.next
  84. if unit._position == None:
  85. self._movingUnits.remove(unit)
  86.  
  87. def moveAll(self):
  88. for unit in self._movingUnits:
  89. self.__step(unit)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement