/// <summary>
        /// Updates the view
        /// </summary>
        public void Update()
        {
            MouseState state = MouseHandle.GetState();

            if (Rect.Contains(state.X, state.Y))
            {
                Selected = true;

                //if (mdown && state.LeftButton == ButtonState.Released)
                //{
                //    boardView.SetSelected(this);
                //}

                mdown = state.LeftButton == ButtonState.Pressed;
                if (mdown)
                {
                    boardView.SetStart(this);
                }
            }
            else
            {
                mdown    = false;
                Selected = false;
            }

            Color = (Selected || Clicked) ? Color.Gray : Color.White;
        }
        /// <summary>
        /// Updates the view
        /// </summary>
        public void Update()
        {
            MouseState state = MouseHandle.GetState();

            if (Rect.Contains(state.X, state.Y))
            {
                Selected = true;

                mdown = state.LeftButton == ButtonState.Pressed;
                if (mdown && HasMarble)
                {
                    view.SetStart(this);
                }
            }
            else
            {
                Selected = false;
                mdown    = false;
            }

            Color = (Selected || Clicked) ? Color.Gray : Color.White;
        }
Beispiel #3
0
        /// <summary>
        /// Updates the view of the board
        /// </summary>
        /// <param name="gameTime">Current GameTime</param>
        public void Update(GameTime gameTime)
        {
            //Update logic
            KeyboardState kState = Keyboard.GetState();
            MouseState    mState = MouseHandle.GetState();

            //Updates squares
            UpdateSquares();

            if (Playing)
            {
                //Update current animation
                if (currentAnimation != null)
                {
                    currentAnimation.Update(gameTime);
                }

                if (kState.IsKeyDown(Keys.Q) && rollOver)
                {
                    for (int i = 0; i < currentMove.Count; i++)
                    {
                        if (currentMove[i].IsTakingOutMarble)
                        {
                            PutBackMarble(currentPlayer.Team);
                        }
                    }

                    RemoveMove();
                }

                if (!currentPlayer.IsThinking && CanRoll())
                {
                    if (!currentPlayer.IsHuman)
                    {
                        rollOver = false;
                        RollDice(gameTime);
                    }
                    else if (!isDiceRolling && kState.IsKeyDown(Keys.R)) //Check for user starting a roll
                    {
                        rollOver = false;
                        RollDice(gameTime);
                    }
                }

                //Check if dice are done rolling
                if (die1 != -1 && die2 != -1 && !rollOver)
                {
                    currentRoll = new DiceRoll(die1, die2);
                    OnRollFinished();
                }

                //Check if dice have rolled for too long
                if (rollStartTime.HasValue)
                {
                    TimeSpan timeElapsed   = gameTime.TotalGameTime.Subtract(rollStartTime.Value);
                    double   timeElapsedMs = timeElapsed.TotalMilliseconds;
                    if (timeElapsedMs >= 10000)
                    {
                        StopDice();
                        UpdateDie(die1Body, ref die1, true);
                        UpdateDie(die2Body, ref die2, true);

                        if (die1 != -1 && die2 != -1)
                        {
                            currentRoll = new DiceRoll(die1, die2);
                            OnRollFinished();
                        }
                    }
                }

                //If the player is a human and hasnt rolled yet, disallow any movement of marbles
                if (!CanRoll())
                {
                    //Update drag
                    UpdateDrag(mState);

                    ////Handle user submitting move
                    if (rollOver && kState.IsKeyDown(Keys.Enter) && currentPlayer.IsHuman)
                    {
                        if (!HasMove)
                        {
                            //Pressed enter without making a move
                            MoveCollection collection = board.GetMoves(currentRoll, currentPlayer.Team);

                            if (collection.Count == 0)
                            {
                                //End the player step
                                ProcessRoll();
                                SetReadyForRoll();
                                //
                            }
                        }
                        else
                        {
                            if (currentRoll == null)
                            {
                                RemoveMove();
                            }
                            else
                            {
                                Move move = GetMove(currentPlayer.Team);
                                if (board.IsPossibleMove(currentRoll, move, out move))
                                {
                                    currentPlayer.SetMove(move);
                                }
                                else
                                {
                                    for (int i = 0; i < currentMove.Count; i++)
                                    {
                                        if (currentMove[i].IsTakingOutMarble)
                                        {
                                            PutBackMarble(currentPlayer.Team);
                                        }
                                    }

                                    RemoveMove();
                                }
                            }
                        }
                    }
                }

                if (currentPlayer.HasMove)
                {
                    OnMoveFound(currentPlayer.GetMove());
                }

                //Update dice
                UpdateDie(die1Body, ref die1, IsNearlyZero(die1Body.LinearVelocity));
                UpdateDie(die2Body, ref die2, IsNearlyZero(die2Body.LinearVelocity));

                if (!Resizing)
                {
                    world.Step(1 / 30f, false);
                    //world.Step((float)gameTime.TotalGameTime.TotalSeconds, false, (float)gameTime.ElapsedGameTime.TotalSeconds, 1);
                }
            }
        }