Ejemplo n.º 1
0
        // $G$ CSS-028 (0) method shouldn't include more then one return command.
        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].GetCellOccupation())
                    {
                    case Cell.e_CellOccupation.topPlayerRegularCoin:
                    case Cell.e_CellOccupation.topPlayerSpecialCoin:
                        if (destinationX == (m_boardSize - 1))
                        {
                            currentCoinUpdatedInformation.CoinType = Cell.e_CellOccupation.topPlayerSpecialCoin;
                        }
                        else
                        {
                            currentCoinUpdatedInformation.CoinType = i_listOfCoins[i].CoinType;
                        }

                        break;

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

                        break;
                    }

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

            return(false);
        }
Ejemplo n.º 2
0
        public void InitializeBoard() ////builds the first board by the given size
        {
            CoinInformation currentCoinInformation  = new CoinInformation();
            CellPosition    currentCoinCellPosition = new CellPosition();

            for (int i = 0; i < m_boardSize; i++)
            {
                currentCoinCellPosition.X = i;

                for (int j = 0; j < m_boardSize; j++)
                {
                    currentCoinCellPosition.Y = j;

                    if (i < (m_boardSize / 2) - 1)
                    {
                        if ((j + i) % 2 != 0)
                        {
                            m_gameBoard[i, j].SetCellOccupation(Cell.e_CellOccupation.topPlayerRegularCoin);

                            currentCoinInformation.CellPosition = currentCoinCellPosition;
                            currentCoinInformation.CoinType     = Cell.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].SetCellOccupation(Cell.e_CellOccupation.bottomPlayerRegularCoin);

                            currentCoinInformation.CellPosition = currentCoinCellPosition;
                            currentCoinInformation.CoinType     = Cell.e_CellOccupation.bottomPlayerRegularCoin;

                            bottomPlayerListOfCoins.Add(currentCoinInformation); ////Ready list of a new board with each coin of the bottom player
                        }
                    }
                }
            }
        }
Ejemplo n.º 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)
        {
            Cell.e_CellOccupation regularCoinOfOpponent = Cell.e_CellOccupation.bottomPlayerRegularCoin,
                                  specialCoinOfOpponent = Cell.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 = Cell.e_CellOccupation.topPlayerRegularCoin;
                specialCoinOfOpponent = Cell.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))
            {
                Cell.e_CellOccupation releventCellOccupation = i_board.GameBoard[i_targetCell.X, i_targetCell.Y].GetCellOccupation();

                Movement currentMovementToInsert = new Movement();
                currentMovementToInsert.SourcePosition = i_coin.CellPosition;
                if (releventCellOccupation == Cell.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].GetCellOccupation();
                        if (releventCellOccupation == Cell.e_CellOccupation.notOccupied)
                        {
                            currentMovementToInsert.DestinationPosition = skipOverTargetCell;

                            i_structOfLists.SkipOverMovementList.Add(currentMovementToInsert);
                        }
                    }
                }
            }
        }
Ejemplo n.º 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 == Cell.e_CellOccupation.topPlayerSpecialCoin) || (i_coin.CoinType == Cell.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);
            }
        }