当前位置: 首页>>代码示例>>C#>>正文


C# IBoard.GetFigurePosition方法代码示例

本文整理汇总了C#中IBoard.GetFigurePosition方法的典型用法代码示例。如果您正苦于以下问题:C# IBoard.GetFigurePosition方法的具体用法?C# IBoard.GetFigurePosition怎么用?C# IBoard.GetFigurePosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IBoard的用法示例。


在下文中一共展示了IBoard.GetFigurePosition方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Move

        public override Move Move(string command,IBoard board)
        {
            int[] deltaRed = { -1, +1, +1, -1 }; //UR, DR, DL, UL

            int[] deltaColona = { +1, +1, -1, -1 };
            int indexOfChange = -1;

            if (command.Length != 3)
            {
                //TODO:Change the exception to custom exception
                throw new ArgumentOutOfRangeException("The command should contain three symbols");
            }

            switch (command)
            {
                case "adr":
                case "bdr":
                case "cdr":
                case "ddr":
                    { indexOfChange = 1; }
                    break;
                case "adl":
                case "bdl":
                case "cdl":
                case "ddl":
                    { indexOfChange = 2; }
                    break;
                default:
                    //TODO:change the exception to custom exception
                    throw new ArgumentOutOfRangeException("The command is not correct");
            }
            int pawnIndex = -1;
            switch (command[0])
            {
                case 'a':
                case 'A':
                    { pawnIndex = 0; }
                    break;
                case 'b':
                case 'B':
                    { pawnIndex = 1; }
                    break;
                case 'c':
                case 'C':
                    { pawnIndex = 2; }
                    break;
                case 'd':
                case 'D':
                    { pawnIndex = 3; }
                    break;
            }
            var fig = this.Figures;
            var oldPosition = board.GetFigurePosition(this.Figures[pawnIndex]);
            int pawnNewRow = oldPosition.Row + deltaRed[indexOfChange];
            int pawnNewColum = oldPosition.Col + deltaColona[indexOfChange];
            var newPosition = new Position(pawnNewRow, pawnNewColum);
            //Position.CheckIfValid(newPosition, GlobalErrorMessages.PositionNotValidMessage);
               // this.Figures[pawnIndex].Position = newPosition;
            return new Move(oldPosition, newPosition);
        }
开发者ID:havaliova,项目名称:King-Survival-4,代码行数:60,代码来源:PawnPlayer.cs

示例2: CheckIfKingIsCatched

        private bool CheckIfKingIsCatched(IPlayer player, IBoard board)
        {
            int kingRow = board.GetFigurePosition(player.Figures[0]).Row;
            int kingCol = board.GetFigurePosition(player.Figures[0]).Col;
            var kingDownRightPosition = new Position(kingRow + 1, kingCol + 1);
            var kingDownLeftPosition = new Position(kingRow + 1, kingCol - 1);
            var kingUpRightPosition = new Position(kingRow - 1, kingCol + 1);
            var kingUpLeftPosition = new Position(kingRow - 1, kingCol - 1);
            if (!this.CheckIfPositionIsEmpty(kingDownRightPosition, board) && !this.CheckIfPositionIsEmpty(kingDownLeftPosition, board) &&
               !this.CheckIfPositionIsEmpty(kingUpRightPosition, board) && !this.CheckIfPositionIsEmpty(kingUpLeftPosition, board))
            {
                return true;
            }

            return false;
        }
开发者ID:Fatme,项目名称:King-Survival-4,代码行数:16,代码来源:WinningConditions.cs

示例3: KingWon

        /// <summary>
        /// Method that checks whether the king won or not
        /// </summary>
        /// <param name="players">The game players</param>
        /// <param name="board">The game board</param>
        /// <returns>Returns true if the king meets curtain conditions</returns>
        public bool KingWon(IList<IPlayer> players, IBoard board)
        {
            var kingPlayer = players[0];
            var pawnPlayer = players[1];

            ////check if king is on the first row
            foreach (var figure in kingPlayer.Figures)
            {
                    if (board.GetFigurePosition((IFigure)figure.Value).Row == 0)
                    {
                        return true;
                    }
            }

            //// check if all powns are on the last row
            for (int i = 1; i < board.NumberOfRows; i += 2)
            {
                if (board.GetFigureAtPosition(new Position(board.NumberOfColumns - 1, i)) == null)
                {
                    return false;
                }
            }

            return true;
        }
开发者ID:kskondov,项目名称:King-Survival-4,代码行数:31,代码来源:WinningConditions.cs

示例4: Move

        public override Move Move(string command,IBoard board)
        {
            int[] deltaRed = { -1, +1, +1, -1 }; //UR, DR, DL, UL

            int[] deltaColona = { +1, +1, -1, -1 };
            int indexOfChange = -1;

            if (command.Length != 3)
            {
                //TODO:change the exception to custom exception
                throw new ArgumentOutOfRangeException("The command should contain three symbols");
            }

            var oldPosition = board.GetFigurePosition(this.Figures[0]);

            switch (command)
            {
                case "kur": { indexOfChange = 0; } break;
                case "kdr": { indexOfChange = 1; } break;
                case "kdl": { indexOfChange = 2; } break;
                case "kul": { indexOfChange = 3; } break;
                default:
                    //TODO:change the exception to custom exception
                    throw new ArgumentOutOfRangeException("The command is not correct");

            }
            int newRow = oldPosition.Row + deltaRed[indexOfChange];
            int newColumn = oldPosition.Col + deltaColona[indexOfChange];
            var newPosition = new Position(newRow, newColumn);
            //Position.CheckIfValid(newPosition, GlobalErrorMessages.PositionNotValidMessage);
              //  this.Figures[0].Position = newPosition;
            return new Move(oldPosition, newPosition);
        }
开发者ID:havaliova,项目名称:King-Survival-4,代码行数:33,代码来源:KingPlayer.cs

示例5: MoveFigure

        /// <summary>
        /// Move Figure  method that moves figures
        /// </summary>
        /// <param name="from">From position</param>
        /// <param name="direction">To direction</param>
        /// <param name="board">The board on which we are moving the figure</param>
        public void MoveFigure(IPosition from, int direction, IBoard board)
        {
            var figurePosition = board.GetFigurePosition(this.Figure);
            IPosition to = figurePosition.GenerateNewPosition(direction);

            Validator.CheckIfPositionValid(to);
            Validator.CheckIfFigureOnTheWay(to, board);

            board.RemoveFigure(from);
            board.AddFigure(this.Figure, to);
        }
开发者ID:kskondov,项目名称:King-Survival-4,代码行数:17,代码来源:MoveableFigure.cs


注:本文中的IBoard.GetFigurePosition方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。