"This module implements the controller class."
#Author: Vian Gomez <vian@linux.ajusco.upn.mx>

from Event import SetCreatureEvent, IterationComplete, ControllerlEvent
import pygame
from pygame.locals import *
class Controller:
    ''
    def __init__(self, evManager):
        """__init__(self, evManager): init controller object"""
        # sets the eventManager for hear and raise events to the
        #the view and the modell
        self.evManager = evManager
        self.evManager.RegisterListener(self, "controller")
        
    def Notify(self, event):
        """Notify(self, event):
        is the method allow the controller to hear the events raised by
        the model and view"""

        # the controller only hear user events when the iteration of
        #the model is complet
        if event.name == "IterationComplete":
            #for now the controller check for user events in pygame.event.get()
            #in the future it will be diferent 
            for event in pygame.event.get():
                #mouse events hears
                if event.type == MOUSEBUTTONDOWN:
                    pos = pygame.mouse.get_pos()
                    self.evManager.post(SetCreatureEvent(pos[0],pos[1]))

