Beispiel #1
0
        /// <summary>
        /// Update method for game
        /// </summary>
        void UpdateGame()
        {
            if (placingSquare.team != 2 && gridSystem.isItTheEnd(placingSquare.name, placingSquare.team) && dice.needToDraw == false)
            {
                pageNumber = 2;
            }

            if (placingSquare.wrong)
            {
                currentTimeWrong += 16;
            }
            if (currentTimeWrong >= periodWrong)
            {
                currentTimeWrong = 0;
                placingSquare.WrongPlace(0);
            }

            MouseState currentMouseState = Mouse.GetState();

            if (currentMouseState.X != lastMouseState.X || currentMouseState.Y != lastMouseState.Y)//мышка сдвинулась вообще
            {
                if ((currentMouseState.X > startPoint.X && currentMouseState.X < startPoint.X + 1080) && (currentMouseState.Y > 0 && currentMouseState.Y < 1080))
                {
                    positionPoint = new Point((int)((currentMouseState.X - startPoint.X) / Square.sizeOfGrid.X), (int)((currentMouseState.Y - startPoint.Y) / Square.sizeOfGrid.Y)); //относительные координаты
                    mousePosition = new Point(currentMouseState.X - 27, currentMouseState.Y - 27);                                                                                   //возможно стоит переделать для удобства
                }
            }

            lastMouseState = currentMouseState;

            if (currentTimeKeyboard > periodKeyboard)
            {
                currentTimeKeyboard -= periodKeyboard;
                KeyboardState keyboardState = Keyboard.GetState();

                if (keyboardState.IsKeyDown(Keys.R))
                {
                    placingSquare.ChangeRotate();
                }
                if (keyboardState.IsKeyDown(Keys.H))
                {
                    if (hideHelp == false)
                    {
                        hideHelp = true;
                    }
                    else
                    {
                        hideHelp = false;
                    }
                }
            }
            if (currentMouseState.LeftButton == ButtonState.Pressed)
            {
                if (pressed == 0)
                {
                    pressed = 1;
                }
            }
            if (currentMouseState.LeftButton == ButtonState.Released)
            {
                if (pressed == 1)                                                                                             //клавиша была нажата
                {
                    if (gridSystem.isItFit(placingSquare.name, placingSquare.rotate, positionPoint, placingSquare.team) == 0) //место подходит для установки
                    {
                        if (dice.needToDraw == false)
                        {
                            gridSystem.addSquare(placingSquare.name, placingSquare.rotate, placingSquare.team, positionPoint);//добавляем в систему
                            //а почему просто placingSquare не передавать то...
                            int prCount = dice.NewRoll(1, 0);
                            int count   = dice2.NewRoll(2, prCount);
                            placingSquare.ChangeDices(dice.GetRandom(), dice2.GetRandom());
                            placingSquare.ChangeTeam();
                            placingSquare.rotate = 0;

                            pressed = 0;
                        }
                    }
                    else
                    {
                        if (placingSquare.wrong == false)
                        {
                            placingSquare.WrongPlace(1);
                        }
                        pressed = 0;
                    }
                }
            }
        }