#! /usr/bin/env python
# -*- coding: utf-8 -*-

class MessageHandler:
    def __init__(self, game):
        self.game = game

    def handle(self, msg, client):
        '''
        Explode a given message and call the corresponding method
        in the Game object
        '''
        message = msg.split(':')
        action = message[0]
        params = message[1].split(';')

        options = {}
        for param in params:
            param = param.split('=')
            options[ param[0] ] = param[1]

        res = False
        if action == 'move':
            res = self.game.move(options['unit'], options['to_x'], options['to_y'])

        if res == True:
            self.game.server.send_all(msg)
        else:
            client.send('false')
