Beispiel #1
0
        public bool PlayerNextMove(Player player, int targetPoint, bool fixedToBoardLength)
        {
            bool moveIsDone = false;
            bool isPullOut  = false;
            int  usedDie    = 0;

            if (!fixedToBoardLength)
            {
                targetPoint--;
            }

            moveIsDone = MoveInsertFromEatenZone(player.Tool, targetPoint);
            if (!moveIsDone)
            {
                moveIsDone = MovePullOutTool(player.Tool, targetPoint);
                isPullOut  = true;
            }

            if (moveIsDone)
            {
                if ((Cell.O == player.Tool && !isPullOut) ||
                    Cell.X == player.Tool && isPullOut)
                {
                    usedDie = targetPoint + 1;
                }
                else
                {
                    usedDie = Board.GetLength(1) - targetPoint;
                }

                _gameLogic.UpdateAmountOfMovesAndDice(usedDie);
            }

            return(_gameLogic.IsEndOfTurn(player.Tool));
        }
Beispiel #2
0
        public void InitializeGame()
        {
            for (int i = 0; i < Board.GetLength(0); i++)
            {
                for (int j = 0; j < Board.GetLength(1); j++)
                {
                    Board[i, j] = Cell.Empty;
                }
            }

            Board[14, 0]  = Cell.O;
            Board[13, 0]  = Cell.O;
            Board[13, 23] = Cell.X;
            Board[14, 23] = Cell.X;

            for (int i = 0; i < 3; i++)
            {
                Board[12 + i, 7]  = Cell.X;
                Board[12 + i, 16] = Cell.O;
            }

            for (int i = 0; i < 5; i++)
            {
                Board[10 + i, 11] = Cell.O;
                Board[10 + i, 18] = Cell.O;
                Board[10 + i, 12] = Cell.X;
                Board[10 + i, 5]  = Cell.X;
            }

            _gameLogic.EatenTools.Clear();
        }
Beispiel #3
0
        private bool MoveInsertFromEatenZone(Cell tool, int targetPoint)
        {
            bool makeMove;
            int  targetPointInSizeOfHomeZone;

            if (Cell.X == tool)
            {
                targetPointInSizeOfHomeZone = Board.GetLength(1) - targetPoint;
            }
            else
            {
                targetPointInSizeOfHomeZone = targetPoint + 1;
            }

            makeMove = _gameLogic.IsPlayerHasEatenTool(tool) &&
                       _gameLogic.IsInRangeOfStartZone(tool, targetPoint) &&
                       _gameLogic.IsAccordingToDice(tool, 0, targetPointInSizeOfHomeZone) &&
                       _gameLogic.IsTargetPointLegal(tool, targetPoint);

            if (makeMove)
            {
                _gameLogic.SetToolOnTopOrEat(tool, targetPoint);
                _gameLogic.EatenTools.Remove(tool);
            }

            return(makeMove);
        }
Beispiel #4
0
        public void SetToolOnTopOrEat(Cell tool, int targetPoint)
        {
            bool isFindTheTopTool = false;

            if (Board[Board.GetLength(0) - 1, targetPoint] == Cell.Empty)
            {
                isFindTheTopTool = true;
                Board[Board.GetLength(0) - 1, targetPoint] = tool;
            }
            else
            {
                for (int i = 0; i < Board.GetLength(0) && !isFindTheTopTool; i++)
                {
                    if (Board[i, targetPoint] == tool)
                    {
                        isFindTheTopTool          = true;
                        Board[i - 1, targetPoint] = tool;
                    }
                    else if (Board[i, targetPoint] != tool && Board[i, targetPoint] != Cell.Empty)
                    {
                        isFindTheTopTool = true;
                        _eatenTools.Add(Board[i, targetPoint]);
                        Board[i, targetPoint] = tool;
                    }
                }
            }
        }
Beispiel #5
0
        private bool MovePullOutTool(Cell tool, int pullOutToolIndex)
        {
            bool pullOutToolLegal;
            bool isPullOutToolExist = false;

            pullOutToolLegal = _gameLogic.IsLegalToPullOut(tool, pullOutToolIndex);
            if (pullOutToolLegal)
            {
                for (int i = 0; i < Board.GetLength(0) && !isPullOutToolExist; i++)
                {
                    if (Board[i, pullOutToolIndex] == tool)
                    {
                        Board[i, pullOutToolIndex] = Cell.Empty;
                        isPullOutToolExist         = true;
                    }
                }
            }

            return(pullOutToolLegal && isPullOutToolExist);
        }
Beispiel #6
0
        private bool MoveFromPointToPoint(Cell tool, int startingPoint, int targetPoint)
        {
            bool makeMove;

            makeMove = _gameLogic.IsLegalMove(tool, startingPoint, targetPoint);
            if (makeMove)
            {
                bool findTheTopTool = false;
                for (int i = 0; i < Board.GetLength(0) && !findTheTopTool; i++)
                {
                    if (Board[i, startingPoint] == tool)
                    {
                        findTheTopTool          = true;
                        Board[i, startingPoint] = Cell.Empty;
                    }
                }

                _gameLogic.SetToolOnTopOrEat(tool, targetPoint);
            }

            return(makeMove);
        }