Exemple #1
0
        public bool ChangeCoinPositionInListOfCoins(ref List <CoinInformation> i_listOfCoins, Movement i_coinMovement)
        {
            int sourceX      = i_coinMovement.SourcePosition.X,
                sourceY      = i_coinMovement.SourcePosition.Y,
                destinationX = i_coinMovement.DestinationPosition.X;

            for (int i = 0; i < i_listOfCoins.Count; i++)
            {
                /*better use with the new methode:
                 * if(Logic.IsTwoPositionsEquale(i_listOfCoins[i].CellPosition, i_coinMovement.SourcePosition) == true)*/
                if ((i_listOfCoins[i].CellPosition.X == sourceX) && (i_listOfCoins[i].CellPosition.Y == sourceY))
                {
                    CoinInformation currentCoinUpdatedInformation = new CoinInformation();
                    currentCoinUpdatedInformation.CellPosition = i_coinMovement.DestinationPosition;

                    switch (m_gameBoard[sourceX, sourceY].CellOccupation)
                    {
                    case MyButton.e_CellOccupation.topPlayerRegularCoin:
                    case MyButton.e_CellOccupation.topPlayerSpecialCoin:
                        if (destinationX == (m_boardSize - 1))
                        {
                            currentCoinUpdatedInformation.CoinType = MyButton.e_CellOccupation.topPlayerSpecialCoin;
                        }
                        else
                        {
                            currentCoinUpdatedInformation.CoinType = i_listOfCoins[i].CoinType;
                        }

                        break;

                    case MyButton.e_CellOccupation.bottomPlayerRegularCoin:
                    case MyButton.e_CellOccupation.bottomPlayerSpecialCoin:
                        if (destinationX == 0)
                        {
                            currentCoinUpdatedInformation.CoinType = MyButton.e_CellOccupation.bottomPlayerSpecialCoin;
                        }
                        else
                        {
                            currentCoinUpdatedInformation.CoinType = i_listOfCoins[i].CoinType;
                        }

                        break;
                    }

                    i_listOfCoins.RemoveAt(i);
                    i_listOfCoins.Add(currentCoinUpdatedInformation);
                    return(true);
                }
            }

            return(false);
        }
Exemple #2
0
        private void InitializeBoard() ////builds the first board by the given size
        {
            CoinInformation currentCoinInformation = new CoinInformation();

            for (int i = 0; i < m_boardSize; i++)
            {
                for (int j = 0; j < m_boardSize; j++)
                {
                    if (i < (m_boardSize / 2) - 1)
                    {
                        if ((j + i) % 2 != 0)
                        {
                            m_gameBoard[i, j].Enabled        = true;
                            m_gameBoard[i, j].CellOccupation = MyButton.e_CellOccupation.topPlayerRegularCoin;

                            currentCoinInformation.CellPosition = m_gameBoard[i, j].Position;
                            currentCoinInformation.CoinType     = MyButton.e_CellOccupation.topPlayerRegularCoin;

                            topPlayerListOfCoins.Add(currentCoinInformation); ////Ready list of a new board with each coin of the top player
                        }
                    }
                    else if (i > m_boardSize / 2)
                    {
                        if ((j + i) % 2 != 0)
                        {
                            m_gameBoard[i, j].Enabled        = true;
                            m_gameBoard[i, j].CellOccupation = MyButton.e_CellOccupation.bottomPlayerRegularCoin;

                            currentCoinInformation.CellPosition = m_gameBoard[i, j].Position;
                            currentCoinInformation.CoinType     = MyButton.e_CellOccupation.bottomPlayerRegularCoin;

                            bottomPlayerListOfCoins.Add(currentCoinInformation); ////Ready list of a new board with each coin of the bottom player
                        }
                    }
                }
            }
        }
Exemple #3
0
        public static void AddPossibleMovementsToStructFromSpecificCellToSpecificDirection(ref Board i_board, ref RegularAndSkipOverMovementsLists i_structOfLists, CoinInformation i_coin, Player.e_PlayerPosition i_playerPosition, CellPosition i_targetCell)
        {
            MyButton.e_CellOccupation regularCoinOfOpponent = MyButton.e_CellOccupation.bottomPlayerRegularCoin,
                                      specialCoinOfOpponent = MyButton.e_CellOccupation.bottomPlayerSpecialCoin; // assuming top player is the active one
            //// if top player is NOT the active one...change will be made

            if (i_playerPosition == Player.e_PlayerPosition.Bottom)
            {
                regularCoinOfOpponent = MyButton.e_CellOccupation.topPlayerRegularCoin;
                specialCoinOfOpponent = MyButton.e_CellOccupation.topPlayerSpecialCoin;
            }

            //// Checking weather target cell is inside the board bounderies

            if ((i_targetCell.X >= 0) &&
                (i_targetCell.X <= i_board.BoardSize - 1) &&
                (i_targetCell.Y >= 0) &&
                (i_targetCell.Y <= i_board.BoardSize - 1))
            {
                MyButton.e_CellOccupation releventCellOccupation = i_board.GameBoard[i_targetCell.X, i_targetCell.Y].CellOccupation;

                Movement currentMovementToInsert = new Movement();
                currentMovementToInsert.SourcePosition = i_coin.CellPosition;
                if (releventCellOccupation == MyButton.e_CellOccupation.notOccupied)
                {
                    currentMovementToInsert.DestinationPosition = i_targetCell;

                    i_structOfLists.RegularMovementList.Add(currentMovementToInsert);
                }
                else if ((releventCellOccupation == regularCoinOfOpponent) || (releventCellOccupation == specialCoinOfOpponent))
                {
                    int sourceX = i_coin.CellPosition.X,
                        sourceY = i_coin.CellPosition.Y; // keeping the values of sourceX and sourceY to calculate the vector of movement together with i_tagerCell in order to calculate the skipOver cell
                    CellPosition skipOverTargetCell = new CellPosition();

                    skipOverTargetCell.X = i_targetCell.X + (i_targetCell.X - sourceX);
                    skipOverTargetCell.Y = i_targetCell.Y + (i_targetCell.Y - sourceY);

                    if ((skipOverTargetCell.X >= 0) &&
                        (skipOverTargetCell.X <= i_board.BoardSize - 1) &&
                        (skipOverTargetCell.Y >= 0) &&
                        (skipOverTargetCell.Y <= i_board.BoardSize - 1))
                    {
                        releventCellOccupation = i_board.GameBoard[skipOverTargetCell.X, skipOverTargetCell.Y].CellOccupation;
                        if (releventCellOccupation == MyButton.e_CellOccupation.notOccupied)
                        {
                            currentMovementToInsert.DestinationPosition = skipOverTargetCell;

                            i_structOfLists.SkipOverMovementList.Add(currentMovementToInsert);
                        }
                    }
                }
            }
        }
Exemple #4
0
        public static void AddPossibleMovementsToStructFromSpecificCell(ref Board i_board, ref RegularAndSkipOverMovementsLists i_structOfLists, CoinInformation i_coin, Player.e_PlayerPosition i_playerPosition)

        // Will be called from inside "for"- which means each cell of the list will be checked for possible moves and the found possible move will be put into the relevant list in the struct
        {
            int horizontalStepSize = 1; // growing direction, topPlayer moving downwards

            if (i_playerPosition == Player.e_PlayerPosition.Bottom)
            {
                horizontalStepSize = -1; // bottomPlayer moving upwards
            }

            CellPosition targetCell = new CellPosition();

            targetCell.X = /*need to make the x and y in cellposition to int and not a uint,
                            * due to this change need to remove the force casting to uing here
                            * and the same few lines later in this code*//*(uint)*/(int)i_coin.CellPosition.X + horizontalStepSize;
            targetCell.Y = i_coin.CellPosition.Y - 1;
            AddPossibleMovementsToStructFromSpecificCellToSpecificDirection(ref i_board, ref i_structOfLists, i_coin, i_playerPosition, targetCell);
            targetCell.Y = i_coin.CellPosition.Y + 1;
            AddPossibleMovementsToStructFromSpecificCellToSpecificDirection(ref i_board, ref i_structOfLists, i_coin, i_playerPosition, targetCell);
            if ((i_coin.CoinType == MyButton.e_CellOccupation.topPlayerSpecialCoin) || (i_coin.CoinType == MyButton.e_CellOccupation.bottomPlayerSpecialCoin))
            {
                ////also downwards
                targetCell.X = /*(uint)*/ (int)i_coin.CellPosition.X - horizontalStepSize;
                targetCell.Y = i_coin.CellPosition.Y - 1;
                AddPossibleMovementsToStructFromSpecificCellToSpecificDirection(ref i_board, ref i_structOfLists, i_coin, i_playerPosition, targetCell);
                targetCell.Y = i_coin.CellPosition.Y + 1;
                AddPossibleMovementsToStructFromSpecificCellToSpecificDirection(ref i_board, ref i_structOfLists, i_coin, i_playerPosition, targetCell);
            }
        }