Esempio n. 1
0
        public bool ExecuteCommand(ConsoleKey command)
        {
            var switchPlayer = false;

            switch (command)
            {
            case Command.UpArrow:
                if (MovementOptions == Movement.SelectChecker || MovementOptions == Movement.MoveChecker)
                {
                    _arrow.MoveUp();
                }
                else
                {
                    throw new BackgammonException("BackgammonException: Invalid player movement. Cannot execute command.");
                }
                break;

            case Command.DownArrow:
                if (MovementOptions == Movement.SelectChecker || MovementOptions == Movement.MoveChecker)
                {
                    _arrow.MoveDown();
                }
                else
                {
                    throw new BackgammonException("BackgammonException: Invalid player movement. Cannot execute command.");
                }
                break;

            case Command.LeftArrow:
                if (MovementOptions == Movement.SelectChecker || MovementOptions == Movement.MoveChecker)
                {
                    _arrow.MoveLeft();
                }
                else
                {
                    throw new BackgammonException("BackgammonException: Invalid player movement. Cannot execute command.");
                }
                break;

            case Command.RightArrow:
                if (MovementOptions == Movement.SelectChecker || MovementOptions == Movement.MoveChecker)
                {
                    _arrow.MoveRight();
                }
                else
                {
                    throw new BackgammonException("BackgammonException: Invalid player movement. Cannot execute command.");
                }
                break;

            case Command.Enter:
                if (MovementOptions == Movement.RollDice)
                {
                    RollDice();
                }
                else if (MovementOptions == Movement.SelectChecker)
                {
                    _arrow.SelectChecker();
                }
                else if (MovementOptions == Movement.MoveChecker)
                {
                    switchPlayer = _arrow.MoveChecker();
                }
                else
                {
                    throw new BackgammonException("BackgammonException: Invalid player movement. Cannot execute command.");
                }
                break;

            case Command.Spacebar:
                if (MovementOptions == Movement.MoveChecker)
                {
                    _arrow.ReleaseChecker();
                }
                else
                {
                    throw new BackgammonException("BackgammonException: Invalid player movement. Cannot execute command.");
                }
                break;

            case Command.Tab:
                if (MovementOptions != Movement.None)
                {
                    PassTurn();
                    switchPlayer = true;
                }
                else
                {
                    throw new BackgammonException("BackgammonException: Invalid player movement. Cannot execute command.");
                }
                break;

            default:
                throw new BackgammonException("BackgammonException: Invalid command cannot be executed.");
            }
            return(switchPlayer);
        }