예제 #1
0
        /// <summary>
        /// Execute move
        /// </summary>
        /// <remarks>
        /// It is executed when CanMove return true, it set up start and end Field,
        /// if was beat, it call Kill() on beaten pawn.
        /// If wasn't it call BeatOrDieChecker.CheckBeats(List{PawnController}),
        /// If CheckQueen returned true, it also call PawnController.TransformToQueen()
        /// </remarks>
        /// <param name="pawn">Pawn which is moving</param>
        /// <seealso cref="BeatOrDieChecker.CheckBeats(List{PawnController})"/>
        public void ExecuteMove(GameObject pawn)
        {
            var startField = board.fields[posStartX, posStartY];
            var endField   = board.fields[posEndX, posEndY];

            TurnManager.NextTurn();
            if (beat)
            {
                board.fields[beatX, beatY].PawnController.Kill();
                TurnManager.turn = pawnController.playerPosition;
                beat             = false;
            }
            else
            {
                var pawnsToDie = beatOrDieChecker.CheckBeats(players[(int)startField.playerPosition].pawns);
                foreach (var pawnToKill in pawnsToDie)
                {
                    if (pawnToKill != pawnController)
                    {
                        pawnToKill.Kill();
                    }
                }
            }

            startField.Free           = true;
            startField.playerPosition = PlayerPosition.Empty;
            startField.PawnController = null;
            endField.Free             = false;
            endField.playerPosition   = pawnController.playerPosition;
            endField.PawnController   = pawnController;

            if (queen)
            {
                pawnController.TransformToQueen();
            }

            pawn.transform.localPosition = board.CalculatePosition(posEndX, posEndY);
        }