Esempio n. 1
0
        private void eatAndRemoveSoldier(Coordination i_BaseCoordination, Coordination i_DestinationCoordination)
        {
            int          x, y;
            Soldier      willKillSoldier;
            Coordination deleteCoordination;

            if (i_BaseCoordination.GetX() < i_DestinationCoordination.GetX())
            {
                x = i_BaseCoordination.GetX() + 1;
            }
            else
            {
                x = i_BaseCoordination.GetX() - 1;
            }

            if (i_BaseCoordination.GetY() < i_DestinationCoordination.GetY())
            {
                y = i_BaseCoordination.GetY() + 1;
            }
            else
            {
                y = i_BaseCoordination.GetY() - 1;
            }

            deleteCoordination = new Coordination(x, y);
            willKillSoldier    = m_TheBoard.GetSoliderFromCoordination(x, y);
            willKillSoldier.PlayerOfSoldier.SoldiersList.Remove(willKillSoldier);
            m_TheBoard.RemoveOneSoldierOnBoard(deleteCoordination);
        }
Esempio n. 2
0
        private bool isValidDestination(Coordination i_BaseCoordination, Coordination i_DestinationCoordination, Soldier i_BaseSoldier, List <BaseAndDestinationCoordinations> i_EatCoordinations)
        {
            bool isValid       = false;
            bool soldierIsKing = false;

            if (i_BaseSoldier.TypeOfSoldier == SoldierType.KingSoldier)
            {
                soldierIsKing = true;
            }

            if (i_EatCoordinations.Count == 0)
            {
                if (m_CurrentTurnPlayer.TypePlayer == PlayerType.MainRealPlayer || soldierIsKing == true)
                {
                    if ((i_DestinationCoordination.GetX() == i_BaseCoordination.GetX() + 1 || i_DestinationCoordination.GetX() == i_BaseCoordination.GetX() - 1) && i_DestinationCoordination.GetY() == i_BaseCoordination.GetY() - 1 &&
                        i_DestinationCoordination.GetY() < m_TheBoard.BoardSize && i_DestinationCoordination.GetY() >= 0 && m_TheBoard.GetBoard()[i_DestinationCoordination.GetX(), i_DestinationCoordination.GetY()] == null)
                    {
                        isValid = true;
                    }
                }

                if (m_CurrentTurnPlayer.TypePlayer == PlayerType.RivalComputerPlayer || m_CurrentTurnPlayer.TypePlayer == PlayerType.RivalRealPlayer || soldierIsKing == true)
                {
                    if ((i_DestinationCoordination.GetX() == i_BaseCoordination.GetX() + 1 || i_DestinationCoordination.GetX() == i_BaseCoordination.GetX() - 1) && i_DestinationCoordination.GetY() == i_BaseCoordination.GetY() + 1 &&
                        i_DestinationCoordination.GetY() < m_TheBoard.BoardSize && i_DestinationCoordination.GetY() >= 0 && m_TheBoard.GetBoard()[i_DestinationCoordination.GetX(), i_DestinationCoordination.GetY()] == null)
                    {
                        isValid = true;
                    }
                }
            }
            else
            {
                if (checkIfValidEatMove(i_BaseCoordination, i_DestinationCoordination, i_EatCoordinations) == true)
                {
                    eatAndRemoveSoldier(i_BaseCoordination, i_DestinationCoordination);
                    isValid = true;
                }
                else
                {
                    throw new Exception("Error: If you have option to eat - so you must to eat!");
                }
            }

            return(isValid);
        }
Esempio n. 3
0
        private string buildStringOfStep(Coordination i_BaseCoordination, Coordination i_DestantionCoordination)
        {
            char   xBase       = (char)(i_BaseCoordination.GetX() + (int)'A');
            char   yBase       = (char)(i_BaseCoordination.GetY() + (int)'a');
            char   xDestantion = (char)(i_DestantionCoordination.GetX() + (int)'A');
            char   yDestantion = (char)(i_DestantionCoordination.GetY() + (int)'a');
            string theStep     = string.Format("{0}{1}>{2}{3}", xBase, yBase, xDestantion, yDestantion);

            return(theStep);
        }
Esempio n. 4
0
        public void UpdateSoldierOnBoard(Board i_Board, Coordination i_BaseCoordination, Coordination i_SoldierDestination)
        {
            this.SetCoordination(i_SoldierDestination.GetX(), i_SoldierDestination.GetY());
            i_Board.UpdateOneSoldierOnBoard(this, i_BaseCoordination, i_SoldierDestination);
            if (this.PlayerOfSoldier.TypePlayer == PlayerType.MainRealPlayer && this.GetYCoordination() == 0)
            {
                this.TypeOfSoldier = SoldierType.KingSoldier;
            }

            if (this.PlayerOfSoldier.TypePlayer != PlayerType.MainRealPlayer && this.GetYCoordination() == i_Board.BoardSize - 1)
            {
                this.TypeOfSoldier = SoldierType.KingSoldier;
            }
        }
Esempio n. 5
0
        private void buttonWas_Click(object sender, EventArgs e)
        {
            Button pressedButton = sender as Button;

            if (!m_isButtonwasChoosen)
            {
                pressedButton.BackColor = System.Drawing.Color.LightBlue;
                pressedButton.Click    -= buttonWas_Click;
                pressedButton.Click    += buttonWas_ClickAgain;
                m_isButtonwasChoosen    = true;
                m_CurrentSource         = new Coordination();
                getCoordinationFromClick(ref m_CurrentSource, pressedButton);
            }
            else if (m_isButtonwasChoosen)
            {
                m_CurrentDestination = new Coordination();
                getCoordinationFromClick(ref m_CurrentDestination, pressedButton);
                transferToLogicTheMoveChoosed(m_CurrentSource, m_CurrentDestination);
                m_isButtonwasChoosen = false;
                buttonWas_ClickAgain(m_CoordinationButtons[m_CurrentSource.GetX(), m_CurrentSource.GetY()], null);
            }
        }
Esempio n. 6
0
        private bool checkIfValidEatMove(Coordination i_BaseCoordination, Coordination i_DestinationCoordination, List <BaseAndDestinationCoordinations> i_EatCoordinations)
        {
            bool isCompatableCoordinations = false;

            foreach (BaseAndDestinationCoordinations currentEatCoordinations in i_EatCoordinations)
            {
                if (currentEatCoordinations.BaseCoordination.GetX() == i_BaseCoordination.GetX() && currentEatCoordinations.BaseCoordination.GetY() == i_BaseCoordination.GetY() && currentEatCoordinations.DestantionCoordination.GetX() == i_DestinationCoordination.GetX() && currentEatCoordinations.DestantionCoordination.GetY() == i_DestinationCoordination.GetY())
                {
                    isCompatableCoordinations = true;
                    break;
                }
            }

            return(isCompatableCoordinations);
        }
Esempio n. 7
0
        private void checkIfIsPossibleMoveAndExecuteIt(Coordination i_BaseCoordination, Coordination i_DestinationCoordination, List <BaseAndDestinationCoordinations> i_EatCoordinations)
        {
            Soldier baseSoldierToMove = m_TheBoard.GetSoliderFromCoordination(i_BaseCoordination.GetX(), i_BaseCoordination.GetY());

            if (baseSoldierToMove == null)
            {
                throw new Exception("Error: Invalid source point to move!");
            }
            else
            if (baseSoldierToMove.SoldierPlayerType != m_CurrentTurnPlayer.TypePlayer)
            {
                throw new Exception("Error: You cant move soldier of your rival! Please choose your soldier!");
            }
            else
            {
                if (isValidDestination(i_BaseCoordination, i_DestinationCoordination, baseSoldierToMove, i_EatCoordinations))
                {
                    baseSoldierToMove.UpdateSoldierOnBoard(m_TheBoard, i_BaseCoordination, i_DestinationCoordination);
                }
                else
                {
                    throw new Exception("Error: Invalid Move! Try Again!");
                }
            }
        }
Esempio n. 8
0
        private bool checkAndExecuteIfIsValidEatAgainMove(Soldier i_SoldierEatAgain, List <BaseAndDestinationCoordinations> i_SoldierNewDestantionsForEatAgain, Coordination i_PlayerBaseInput, Coordination i_PlayerDestantionInput)
        {
            bool validEatAgain = false;

            foreach (BaseAndDestinationCoordinations currentSoldierNewDestantionsForEatAgain in i_SoldierNewDestantionsForEatAgain)
            {
                if (currentSoldierNewDestantionsForEatAgain.DestantionCoordination.GetX() == i_PlayerDestantionInput.GetX() && currentSoldierNewDestantionsForEatAgain.DestantionCoordination.GetY() == i_PlayerDestantionInput.GetY() && i_SoldierEatAgain.GetXCoordination() == i_PlayerBaseInput.GetX() && i_SoldierEatAgain.GetYCoordination() == i_PlayerBaseInput.GetY())
                {
                    eatAndRemoveSoldier(i_PlayerBaseInput, i_PlayerDestantionInput);
                    i_SoldierEatAgain.UpdateSoldierOnBoard(m_TheBoard, i_PlayerBaseInput, i_PlayerDestantionInput);
                    validEatAgain = true;
                    break;
                }
            }

            return(validEatAgain);
        }
Esempio n. 9
0
        public bool StartStep()
        {
            List <BaseAndDestinationCoordinations> possibleEatCoordinations = new List <BaseAndDestinationCoordinations>();
            List <BaseAndDestinationCoordinations> soldierNewDestantionsForEatAgain;
            Soldier soldierEatAgain             = null;
            string  stepString                  = null;
            bool    necesseryToEat              = false;
            bool    necesseryToEatAgain         = false;
            bool    haveValidMoves              = m_CurrentTurnPlayer.CheckIfHaveValidMove(m_TheBoard);
            bool    playerThatNoComputerNeedEat = false;

            if (haveValidMoves == true)
            {
                necesseryToEat = m_CurrentTurnPlayer.CheckIfPlayerIsNecesseryToEat(possibleEatCoordinations, m_TheBoard);

                if (m_CurrentTurnPlayer.TypePlayer != PlayerType.RivalComputerPlayer)
                {
                    checkIfIsPossibleMoveAndExecuteIt(m_Source, m_Destination, possibleEatCoordinations);
                }
                else
                {
                    if (necesseryToEat == true)
                    {
                        soldierEatAgain = computerRandomEat(possibleEatCoordinations, ref stepString);
                    }
                    else
                    {
                        computerRandomWithoutEat();
                    }
                }

                if (necesseryToEat == true)
                {
                    do
                    {
                        if (m_CurrentTurnPlayer.TypePlayer != PlayerType.RivalComputerPlayer)
                        {
                            soldierEatAgain = m_TheBoard.GetSoliderFromCoordination(m_Destination.GetX(), m_Destination.GetY());
                        }

                        soldierNewDestantionsForEatAgain = new List <BaseAndDestinationCoordinations>();
                        necesseryToEatAgain = soldierEatAgain.CheckIfSoldierNeedEat(soldierNewDestantionsForEatAgain, m_TheBoard);
                        if (necesseryToEatAgain == true)
                        {
                            if (m_CurrentTurnPlayer.TypePlayer != PlayerType.RivalComputerPlayer)
                            {
                                playerThatNoComputerNeedEat = true;
                                necesseryToEatAgain         = false; // Because if is not computer, we need get a input again so we end this loop.
                            }
                            else
                            {
                                soldierEatAgain = computerRandomEat(soldierNewDestantionsForEatAgain, ref stepString);
                            }
                        }
                    }while (necesseryToEatAgain == true);
                }
            }

            return(playerThatNoComputerNeedEat);
        }
Esempio n. 10
0
 public void RemoveOneSoldierOnBoard(Coordination i_Coordination)
 {
     m_TheBoard[i_Coordination.GetX(), i_Coordination.GetY()] = null;
 }
Esempio n. 11
0
 public void UpdateOneSoldierOnBoard(Soldier i_Soldier, Coordination i_BaseCoordination, Coordination i_SoldierDestination)
 {
     m_TheBoard[i_BaseCoordination.GetX(), i_BaseCoordination.GetY()]     = null;
     m_TheBoard[i_SoldierDestination.GetX(), i_SoldierDestination.GetY()] = i_Soldier;
 }
Esempio n. 12
0
 public int GetYCoordination()
 {
     return(m_XYCoordinationOnBoard.GetY());
 }