Initial work, pong paddles move, lots of the groundwork for multiplayer or alternate displays is already done

This commit is contained in:
2013-12-14 22:54:21 -05:00
commit 26eb57c61d
9 changed files with 445 additions and 0 deletions

21
event.py Executable file
View File

@@ -0,0 +1,21 @@
from common import *
# Raise an EventBubble with a tuple(eventName, eventMessage) to post a new
# message to the queue. If you bubble a list of tuples - [(), (), ()] - then
# each tuple in the list of events is added to the queue.
class EventBubble(Exception):
pass
# Events are just tuples of (eventName, eventMessage), where eventMessage
# can be any object appropriate for eventName
class EventHandler:
def __init__(self, *args, **kwargs):
self.__eventHandlers__ = {}
def handleEvent(self, event):
self.__eventHandlers__[event[0]](event[1])
def bindEvent(self, eventName, function):
self.__eventHandlers__ = getattr(self, "__eventHandlers__", {})
self.__eventHandlers__[eventName] = function