Exemple #1
0
 public void SetNeighbours(MillPoint neighbourUp, MillPoint neighbourRight, MillPoint neighbourDown, MillPoint neighbourLeft)
 {
     NeighbourUp    = neighbourUp;
     NeighbourRight = neighbourRight;
     NeighbourDown  = neighbourDown;
     NeighbourLeft  = neighbourLeft;
 }
        public NineMensMorrisGame()
        {
            Window.Title = "Nine Men's Morris";

            graphics = new GraphicsDeviceManager(this);
            graphics.PreferredBackBufferHeight = 800;
            graphics.PreferredBackBufferWidth  = 1300;

            Content.RootDirectory = "Content";

            tokenSize     = new Point(50, 50);
            boardSize     = new Point(750, 700);
            boardLocation = new Point(20, 30);

            IsMouseVisible = true;

            player1       = new Player(1, Color.OrangeRed);
            player2       = new Player(2, Color.SpringGreen);
            CurrentPlayer = player1;

            gamePhase = GamePhase.Placing;

            invalidDiscard  = false;
            messageDuration = TimeSpan.FromSeconds(3);
            elapsedTime     = TimeSpan.Zero;

            selectedToken = null;
            position      = new Vector2(0, 0);
        }
        private void UpdateMovingPhase()
        {
            if (selectedToken == null)
            {
                return;
            }

            //place the token to new spot
            var newMillPoint = gameBoard.Values.FirstOrDefault(_ => !_.IsOccupied && _.Contains(position.ToPoint()));

            if (newMillPoint == null)
            {
                selectedToken = null;
                return;
            }

            var tokenToMove = selectedToken.Token;

            selectedToken.RemoveToken();
            newMillPoint.PlaceToken(tokenToMove);

            selectedToken = null;

            CheckForDiscarding(newMillPoint);
            CheckForEnd();
        }
        private void SelectTokenToMove(MouseState mouseState)
        {
            //millPoint with this user's token
            var clickedMillPoint = gameBoard.Values
                                   .FirstOrDefault(_ => _.IsOccupied && _.Token.Owner.Id == CurrentPlayer.Id && _.Contains(mouseState.Position));

            if (clickedMillPoint != null)
            {
                selectedToken = clickedMillPoint;
                position.X    = selectedToken.Center.X;
                position.Y    = selectedToken.Center.Y;
            }
        }
        private void CheckForDiscarding(MillPoint millPoint)
        {
            /* check if mill
             *  YES
             *  - same player turn
             *  - enable discarding
             *  NO
             *  - next player turn
             */

            var mills = millPoint.GetNumberOfMills();

            if (mills > 0)
            {
                nmbTokensToDiscard = mills;
                gamePhase          = GamePhase.Discarding;
            }
            else
            {
                IsFirstPlayersTurn = !IsFirstPlayersTurn;
                CurrentPlayer      = IsFirstPlayersTurn ? player1 : player2;
            }
        }