biquadris / controller.h
controller.h
Raw
/*
    Controller class module
    
    controls input from the client (or from a file) and controls 
    the Model stored

    default commands and special commands are supported

    Available default commands:
        "left"              : move Block left if possible
        "right"             : move Block right if possible
        "down"              : move Block down if possible
        "clockwise"         : rotates Block clockwise if possible
        "counterclockwise"  : rotates Block counterclockwise if possible
        "drop"              : drops the Block
        "levelup"           : increase level if possible
        "leveldown"         : decrease level if possible
        "norandom [file]"   : toggle off random, and get sequence of blocks from file
        "random"            : toggle on random
        "sequence [file]"   : set sequence of commands from file
        "hint"              : get hint
        "I"                 : set current undropped Block to "I" type if possible
        "J"                 : set current undropped Block to "J" type if possible
        "L"                 : set current undropped Block to "L" type if possible
        "O"                 : set current undropped Block to "O" type if possible
        "S"                 : set current undropped Block to "S" type if possible
        "Z"                 : set current undropped Block to "Z" type if possible
        "T"                 : set current undropped Block to "T" type if possible
        "restart"           : restart the board
        "rename"            : rename a command/macro (or make new command macro)

    Special Commands are commands if special action is triggered (may upon program)
*/

#ifndef _CONTROLLER_H_
#define _CONTROLLER_H_

#include <iostream>
#include <string>
#include <map>

class BiquadrisModel;
class View;

class Controller {
    std::istream *input, *defaultInput;
    static std::map<std::string, std::string> commands;
    BiquadrisModel *model;
    View &view;
    std::string findCommand(std::string keyword);
    public:
        Controller(View &view, std::istream *input = &std::cin);
        void addModel(BiquadrisModel *model);
        void getCommandInput();
        void getSpecialActionCommand();
};

#endif