In: Computer Science
Python
1.Suppose you were going to design an event-driven application
like the famous wack-a-mole game. Do the following:
a) draw a mockup of the layout of the screen--this is usually
easiest by hand. Submit a legible picture of your drawing.
b) List the events your game would have to respond to (such as when
certain keys are pressed).
2.Explain why you should avoid using loops to repeat actions in a GUI application. What should you do instead?
Wack-a-mole game:
1) a) Design Mockup:
Tool Used: MS Powerpoint.
1) b) Game Events:
i) <Button> : Mouse button press ( To hit the mole )
ii) <Motion> : Mouse is moved over the platform to reach out to different mole burrows.
iii) <ButtonRelease> : When button is released after hammer hit the mole burrow, this will move hammer back to its original state.
iv) <Leave> : When mouse pointer leave the widget and the focus is no longer on the game board.
2) Why avoid using loops to repeat actions in a GUI application? :
The main reason why there is a need to avoid loops in a GUI oriented application is that it may result in slowness of code as the compiler will be busy with loop intensive code and the game player may miss an event or have a delayed response to the event triggered which ultimately will result in a bad game/GUI user experience. Adding to this Python is not a very fast executing language which again boils down to the fact that the user experience will be impacted if the code is loop intensive.
A feasible solution to overcome the loop issues in code is Profiling which is a set of statistics that mentions how frequently and for how long certain parts of the program are executed.