Beispiel #1
0
        private bool isBeatingInPassing(PawColors color, IField field, int heighPosition, int heightOldPosition)
        {
            IPawnHistory lastMove = pawnHistoriesList.LastOrDefault();

            if (lastMove == null)
            {
                return(false);
            }

            var pawn                 = board.FieldList.First(f => f.Pawn?.ID == lastMove.PawID).Pawn;
            var fieldOldPosition     = board.FieldList.First(f => f.ID == lastMove.PreviusFiledID);
            var fieldCurrentPosition = board.FieldList.First(f => f.ID == lastMove.CurrentFiledID);

            return(field.Pawn.Color == color &&
                   field.Heigh == heighPosition &&
                   pawn != null &&
                   pawn.Color != field.Pawn.Color &&
                   pawn.Type == field.Pawn.Type &&
                   fieldOldPosition.Heigh == heightOldPosition &&
                   (fieldOldPosition.Width == field.Width - 1 ||
                    fieldOldPosition.Width == field.Width + 1) &&
                   fieldCurrentPosition.Heigh == heighPosition &&
                   (fieldCurrentPosition.Width == field.Width - 1 ||
                    fieldCurrentPosition.Width == field.Width + 1));
        }
Beispiel #2
0
        //Refaktor, metoda jest już nie czytelna
        public void PawnMove(IField fieldCurrent, IField fieldNew)
        {
            bool canPlayerPlayThisPaw = fieldCurrent.Pawn.Color == PlayerTurn.Color;

            if (!canPlayerPlayThisPaw)
            {
                return;
            }

            bool isMoveDone = Rules.PawnMove(fieldCurrent, fieldNew);

            if (!isMoveDone)
            {
                Alert(MessageContents.IncorrectMovement);
                return;
            }



            //Pomyśl. Zamisat mieć dwie moetody, gdzie szachmat musi wywolać szach. Przez co wołamy dwa razy tą samą metodę
            //Lepiej było by sprawdzić czy jest szach, zanotować tą informację (np. w Enum?), a potem sprawdzić czy jest szachmat.

            if (CheckGameStatus())
            {
                return;
            }


            if (Rules.IsPawnUpgrade(fieldNew))
            {
                PawChess pawChosed = ChosePawUpgrade(pawToChoseList);
                fieldNew.Pawn.Type = (PawType)pawChosed;
            }


            IPawnHistory history = KernelInstance.Get <IPawnHistory>();

            history.Turn           = Turn;
            history.PreviusFiledID = fieldCurrent.ID;
            history.CurrentFiledID = fieldNew.ID;
            history.PawID          = fieldNew.Pawn.ID;

            PawnHistoriesList.Add(history); //Myśę że można by zrobić extensiona

            Turn++;
            PlayerTurn = PlayerList.First(p => p.ID != PlayerTurn.ID);
        }