示例#1
0
        public ICommand CreatePlayerCommand(string commandName)
        {
            ICommand resultCommand;

             if (this.commands.ContainsKey(commandName))
             {
                 return this.commands[commandName];
             }

             var commandNameLowerCase = commandName.ToLower();
             switch (commandNameLowerCase)
             {
                 case "kdl":
                     resultCommand = new KingDownLeftCommand();
                     break;
                 case "kdr":
                     resultCommand = new KingDownRightCommand();
                     break;
                 case "kul":
                     resultCommand = new KingUpLeftCommand();
                     break;
                 case "kur":
                     resultCommand = new KingUpRightCommand();
                     break;
                 case "adl":
                     resultCommand = new PawnADownLeftCommand();
                     break;
                 case "adr":
                     resultCommand = new PawnADownRightCommand();
                     break;
                 case "bdl":
                     resultCommand = new PawnBDownLeftCommand();
                     break;
                 case "bdr":
                     resultCommand = new PawnBDownRightCommand();
                     break;
                 case "cdl":
                     resultCommand = new PawnCDownLeftCommand();
                     break;
                 case "cdr":
                     resultCommand = new PawnCDownRightCommand();
                     break;
                 case "ddl":
                     resultCommand = new PawnDDownLeftCommand();
                     break;
                 case "ddr":
                     resultCommand = new PawnDDownRightCommand();
                     break;
                 case "undo":
                     resultCommand = new UndoCommand();
                     break;
                 default:
                     throw new ArgumentException("Incorrect command " + commandName);
             }

             this.commands.Add(commandName, resultCommand);
             return resultCommand;
        }
        /// <summary>
        /// Method for creting player command depend on the command name
        /// </summary>
        /// <param name="commandName">Name od the command</param>
        /// <returns></returns>
        public ICommand CreatePlayerCommand(string commandName)
        {
            ICommand resultCommand;

             if (this.commands.ContainsKey(commandName))
             {
                 return this.commands[commandName];
             }

             var commandNameLowerCase = commandName.ToLower();
             switch (commandNameLowerCase)
             {
                 case Constants.KingDownLeftCommand:
                     resultCommand = new KingDownLeftCommand();
                     break;
                 case Constants.KingDownRightCommand:
                     resultCommand = new KingDownRightCommand();
                     break;
                 case Constants.KingUpLeftCommand:
                     resultCommand = new KingUpLeftCommand();
                     break;
                 case Constants.KingUpRightCommand:
                     resultCommand = new KingUpRightCommand();
                     break;
                 case Constants.AdlCommand:
                     resultCommand = new PawnADownLeftCommand();
                     break;
                 case Constants.AdrCommand:
                     resultCommand = new PawnADownRightCommand();
                     break;
                 case Constants.BdlCommand:
                     resultCommand = new PawnBDownLeftCommand();
                     break;
                 case Constants.BdrCommand:
                     resultCommand = new PawnBDownRightCommand();
                     break;
                 case Constants.CdlCommand:
                     resultCommand = new PawnCDownLeftCommand();
                     break;
                 case Constants.CdrCommand:
                     resultCommand = new PawnCDownRightCommand();
                     break;
                 case Constants.DdlCommand:
                     resultCommand = new PawnDDownLeftCommand();
                     break;
                 case Constants.DdrCommand:
                     resultCommand = new PawnDDownRightCommand();
                     break;
                 case Constants.UndoCommand:
                     resultCommand = new UndoCommand();
                     break;
                 default:
                     throw new InvalidCommandException("Invalid command " + commandName);
             }

             this.commands.Add(commandName, resultCommand);
             return resultCommand;
        }
        public void ExecuteMoveCommandShouldThrowExceptionWhenKingIsTryingToExecuteBdr()
        {
            IFigure figure = new KingFigure("K");
            var position = new Position(3, 6);
            var boardMock = new Mock<IBoard>();
            boardMock.SetupGet(x => x.NumberOfColumns).Returns(8);
            boardMock.SetupGet(x => x.NumberOfRows).Returns(8);
            var figures = new Dictionary<string, IMoveableFigure>();
            figures.Add(figure.DisplaySign, new MoveableFigure(figure));
            var playerMock = new Mock<IPlayer>();
            playerMock.SetupGet(x => x.Figures).Returns(figures);
            var memoryMock = new Mock<BoardMemory>();
            Mock<ICommandContext> mockContext = new Mock<ICommandContext>();
            mockContext.SetupGet(b => b.Board).Returns(boardMock.Object);
            mockContext.SetupGet(p => p.Player).Returns(playerMock.Object);
            mockContext.SetupGet(p => p.Memory).Returns(memoryMock.Object);

            var pawnCommand = new PawnBDownLeftCommand();
            pawnCommand.Execute(mockContext.Object);
        }