コード例 #1
0
 public void Idle()
 {
     _timer.Enabled = false;
     if (_current == _leftDown)
     {
         if (NativeMethods.Section.TouchOverClick)
         {
             NativeMethods.MouseEvent(NativeMethods.Section.LeftHandMode ? MouseEventFlags.RightUp : MouseEventFlags.LeftUp);
         }
     }
     else if (_current == _rightDown)
     {
         if (NativeMethods.Section.TouchOverClick)
         {
             NativeMethods.MouseEvent(NativeMethods.Section.LeftHandMode ? MouseEventFlags.LeftUp : MouseEventFlags.RightUp);
         }
     }
     else if (_current == _middleDown)
     {
         if (NativeMethods.Section.MiddleClick)
         {
             NativeMethods.MouseEvent(MouseEventFlags.MiddleUp);
         }
     }
     _current = _idle;
 }
コード例 #2
0
ファイル: StateMachine.cs プロジェクト: justry/touchmousemate
 public void Idle()
 {
     _timer.Enabled = false;
     if (_current == _leftDown)
     {
         if (NativeMethods.Section.TouchOverClick)
         {
             NativeMethods.MouseEvent(NativeMethods.Section.LeftHandMode ? MouseEventFlags.RightUp : MouseEventFlags.LeftUp);
         }
     }
     else if (_current == _rightDown)
     {
         if (NativeMethods.Section.TouchOverClick)
         {
             NativeMethods.MouseEvent(NativeMethods.Section.LeftHandMode ? MouseEventFlags.LeftUp : MouseEventFlags.RightUp);
         }
     }
     else if (_current == _middleDown)
     {
         if (NativeMethods.Section.MiddleClick)
         {
             NativeMethods.MouseEvent(MouseEventFlags.MiddleUp);
         }
     }
     _current = _idle;
 }
コード例 #3
0
        public override void Initialize()
        {
            currentMouseState    = Mouse.GetState();
            lastMouseState       = Mouse.GetState();
            currentKeyboardState = Keyboard.GetState(Keys.Escape);
            lastKeyboardState    = Keyboard.GetState(Keys.Escape);

            reversiGame    = ReversiGame.CurrentGame;
            boardRectangle = boardRect;

            aiTypePieces = new Piece[2, AIMaxCount];
            AICount      = ReversiAIType.GetAINames().Length;
            AIIndex[0]   = GameSettings.DefaultAIIndex;
            AIIndex[1]   = GameSettings.DefaultAIIndex;
            board        = curGame.LoadContent <Texture2D>(@"Images\Board");
            settingBoard = curGame.LoadContent <Texture2D>(@"Images\SettingBoard");
            int pieceSize = boardRect.Width / ReversiGame.BoardSize;

            startButton = CreateChild <StartButton, Rectangle>(new Rectangle(boardRect.X + pieceSize * 3, boardRect.Y + pieceSize * 6, pieceSize * 2, pieceSize));
            startButton.Initialize(settingType);
            showPieces[0]                      = CreateChild <Piece, Rectangle>(new Rectangle(boardRect.X + pieceSize * 3, boardRect.Y + pieceSize * 2, pieceSize, pieceSize));
            showPieces[0].PieceState           = PieceState.Black;
            showPieces[1]                      = CreateChild <Piece, Rectangle>(new Rectangle(boardRect.X + pieceSize * 4, boardRect.Y + pieceSize * 2, pieceSize, pieceSize));
            showPieces[1].PieceState           = PieceState.White;
            playerTypePieces[0]                = CreateChild <Piece, Rectangle>(new Rectangle(boardRect.X + pieceSize * 1, boardRect.Y + pieceSize * 3, pieceSize, pieceSize));
            playerTypePieces[0].CurrentDisplay = DisplayState.CanMove;
            chooseIndex[0]                     = 0;
            PlayerType[0]                      = PlayerTypes.Human;
            playerTypePieces[1]                = CreateChild <Piece, Rectangle>(new Rectangle(boardRect.X + pieceSize * 2, boardRect.Y + pieceSize * 3, pieceSize, pieceSize));
            playerTypePieces[1].CurrentDisplay = DisplayState.Normal;
            playerTypePieces[2]                = CreateChild <Piece, Rectangle>(new Rectangle(boardRect.X + pieceSize * 5, boardRect.Y + pieceSize * 3, pieceSize, pieceSize));
            playerTypePieces[2].CurrentDisplay = DisplayState.CanMove;
            chooseIndex[1]                     = 2;
            PlayerType[1]                      = PlayerTypes.AI;
            playerTypePieces[3]                = CreateChild <Piece, Rectangle>(new Rectangle(boardRect.X + pieceSize * 6, boardRect.Y + pieceSize * 3, pieceSize, pieceSize));
            playerTypePieces[3].CurrentDisplay = DisplayState.Normal;
            for (int i = 0; i < AIMaxCount; i++)
            {
                aiTypePieces[0, i] = CreateChild <Piece, Rectangle>(new Rectangle(boardRect.X, boardRect.Y + pieceSize * (i + 3), pieceSize, pieceSize));
            }
            for (int i = 0; i < AIMaxCount; i++)
            {
                aiTypePieces[1, i] = CreateChild <Piece, Rectangle>(new Rectangle(boardRect.X + pieceSize * 7, boardRect.Y + pieceSize * (i + 3), pieceSize, pieceSize));
            }
            foreach (Piece piece in showPieces)
            {
                piece.ForceShow = true;
            }
            foreach (Piece piece in playerTypePieces)
            {
                piece.ForceShow = true;
            }
            foreach (Piece piece in aiTypePieces)
            {
                piece.ForceShow = true;
            }

            base.Initialize();
        }
コード例 #4
0
 public override void Initialize()
 {
     currentMouseState    = Mouse.GetState();
     lastMouseState       = Mouse.GetState();
     currentKeyboardState = Keyboard.GetState(Keys.LeftControl, Keys.RightControl, Keys.Z);
     lastKeyboardState    = Keyboard.GetState(Keys.LeftControl, Keys.RightControl, Keys.Z);
     base.Initialize();
 }
コード例 #5
0
    public void Destroy()
    {
        EventSystem <UpdateEvent> .UnregisterListener(OnUpdate);

        state.Exit();
        state    = null;
        oldState = null;
    }
コード例 #6
0
ファイル: StateMachine.cs プロジェクト: justry/touchmousemate
 public void RightDown()
 {
     _timer.Enabled = false;
     _current       = _rightDown;
     if (NativeMethods.Section.TouchOverClick)
     {
         NativeMethods.MouseEvent(NativeMethods.Section.LeftHandMode ? MouseEventFlags.LeftDown : MouseEventFlags.RightDown);
     }
 }
コード例 #7
0
 public void MiddleDown()
 {
     _timer.Enabled = false;
     _current = _middleDown;
     if (NativeMethods.Section.MiddleClick)
     {
         NativeMethods.MouseEvent(MouseEventFlags.MiddleDown);
     }
 }
コード例 #8
0
 public void RightDown()
 {
     _timer.Enabled = false; 
     _current = _rightDown;
     if (NativeMethods.Section.TouchOverClick)
     {
         NativeMethods.MouseEvent(NativeMethods.Section.LeftHandMode ? MouseEventFlags.LeftDown : MouseEventFlags.RightDown);
     }
 }
コード例 #9
0
ファイル: StateMachine.cs プロジェクト: justry/touchmousemate
 public void MiddleDown()
 {
     _timer.Enabled = false;
     _current       = _middleDown;
     if (NativeMethods.Section.MiddleClick)
     {
         NativeMethods.MouseEvent(MouseEventFlags.MiddleDown);
     }
 }
コード例 #10
0
ファイル: MouseState.cs プロジェクト: jorolf/osu-framework
        public void SetLast(IMouseState last)
        {
            (last as MouseState)?.SetLast(null);

            LastState = last;
            if (last != null)
            {
                PositionMouseDown = last.PositionMouseDown;
            }
        }
コード例 #11
0
ファイル: Board.cs プロジェクト: walterlv/reversi-game
 // 获取鼠标指针所在的棋子位置
 public static ReversiPiecePosition IsMouseInPiece(IMouseState currentMouseState)
 {
     if (currentMouseState.X > Board.BoardRectangle.X && currentMouseState.Y > Board.BoardRectangle.Y)
     {
         int x, y;
         x = (currentMouseState.X - Board.BoardRectangle.X) / (Board.BoardRectangle.Width / ReversiGame.BoardSize);
         y = (currentMouseState.Y - Board.BoardRectangle.Y) / (Board.BoardRectangle.Height / ReversiGame.BoardSize);
         return(new ReversiPiecePosition(x, y));
     }
     return(null);
 }
コード例 #12
0
 private void addTestInputManagerStep()
 {
     AddStep("Add InputManager", () =>
     {
         testInputManager = new TestInputManager();
         Add(testInputManager);
         state    = testInputManager.CurrentState;
         mouse    = state.Mouse;
         keyboard = state.Keyboard;
         joystick = state.Joystick;
     });
 }
コード例 #13
0
    private void OnUpdate(UpdateEvent updateEvent)
    {
        if (switchToNewState == true)
        {
            state            = newState;
            switchToNewState = false;
        }

        SpawnEnemy();

        state.Update();
    }
コード例 #14
0
        private void ProcessWheel(IMouseState currState)
        {
            if (currState.WheelPosition == prevState.WheelPosition)
            {
                return;
            }
            var wheelDelta = currState.WheelPosition - prevState.WheelPosition;
            var state      = prevState.CloneTyped();

            state.WheelPosition = currState.WheelPosition;
            FireWheel(state, wheelDelta);
            prevState = state;
        }
コード例 #15
0
 private void FireWheel(IMouseState state, int wheelDelta)
 {
     inputService.OnInputEvent(new MouseEventArgs
     {
         ComplexEventType = MouseEventType.Wheel,
         EventButtons     = MouseButtons.None,
         State            = state,
         Delta            = IntVector2.Zero,
         WheelDelta       = wheelDelta,
         KeyModifyers     = GetKeyModifyersFromInput(),
         Viewport         = guiLazy.Value.RenderControl.Viewports.Single()
     });
 }
コード例 #16
0
 private void FireButton(IMouseState state, MouseButtons button, MouseEventType eventType)
 {
     inputService.OnInputEvent(new MouseEventArgs
     {
         ComplexEventType = eventType,
         EventButtons     = button,
         State            = state,
         Delta            = IntVector2.Zero,
         WheelDelta       = 0,
         KeyModifyers     = GetKeyModifyersFromInput(),
         Viewport         = guiLazy.Value.RenderControl.Viewports.Single()
     });
 }
コード例 #17
0
ファイル: StartButton.cs プロジェクト: walterlv/reversi-game
        public override void Initialize()
        {
            buttonStartNormalTexture  = curGame.LoadContent <Texture2D>(@"Images\StartButton0");
            buttonStartRollTexture    = curGame.LoadContent <Texture2D>(@"Images\StartButton1");
            buttonResumeNormalTexture = curGame.LoadContent <Texture2D>(@"Images\ResumeButton0");
            buttonResumeRollTexture   = curGame.LoadContent <Texture2D>(@"Images\ResumeButton1");
            buttonRestartRollTexture  = curGame.LoadContent <Texture2D>(@"Images\ResumeButton2");

            currentMouseState    = Mouse.GetState();
            lastMouseState       = Mouse.GetState();
            currentKeyboardState = Keyboard.GetState(Keys.Enter);
            lastKeyboardState    = Keyboard.GetState(Keys.Enter);
        }
コード例 #18
0
    void SwitchMouseState()
    {
        hitInfo = Utility.CameraRay();
        var tag = (Tag)Enum.Parse(typeof(Tag), hitInfo.collider?.tag);

        if (EventSystem.current.IsPointerOverGameObject() || !mouseStates.ContainsKey(tag))
        {
            currentState = mouseStates[Tag.Untagged];
        }
        else
        {
            currentState = mouseStates[tag];
        }
        currentState.Hover();
    }
コード例 #19
0
ファイル: Mouse.cs プロジェクト: nick-zhang/StatePattern
        public bool Process(string command)
        {
            switch (command)
            {
                case "line":
                    _mouseState = new DrawLineMouseState();
                    return true;

                case "rectangle":
                    _mouseState = new DrawRectangleState();
                    return true;

                case "exit":
                    return false;

                default:
                    throw new InvalidCommandException(command + " is not recognized.");
            }
        }
コード例 #20
0
        private void ProcessMove(IMouseState currState)
        {
            if (currState.Position == prevState.Position)
            {
                return;
            }

            canBeClick       = false;
            canBeDoubleClick = false;

            var delta = currState.Position - prevState.Position;
            var state = prevState.CloneTyped();

            state.Position           = currState.Position;
            state.NormalizedPosition = currState.NormalizedPosition;
            state.HmgnPosition       = currState.HmgnPosition;
            FireMove(state, delta);
            prevState = state;
        }
コード例 #21
0
ファイル: StateMachine.cs プロジェクト: justry/touchmousemate
 public void LeftDownPending()
 {
     _current       = _leftDownPending;
     _timer.Enabled = true;
 }
コード例 #22
0
        /// <summary>
        /// In order to provide a reliable event system to drawables, we want to ensure that we reprocess input queues (via the
        /// main loop in <see cref="InputManager"/> after each and every button or key change. This allows
        /// correct behaviour in a case where the input queues change based on triggered by a button or key.
        /// </summary>
        /// <param name="newStates">One ore more states which are to be converted to distinct states.</param>
        /// <returns>Processed states such that at most one attribute change occurs between any two consecutive states.</returns>
        private IEnumerable <InputState> createDistinctStates(IEnumerable <InputState> newStates)
        {
            IKeyboardState lastKeyboard = CurrentState.Keyboard;
            IMouseState    lastMouse    = CurrentState.Mouse;

            foreach (var state in newStates)
            {
                if (state.Mouse == null && state.Keyboard == null)
                {
                    // we still want to return at least one state change.
                    yield return(state);
                }

                if (state.Mouse != null)
                {
                    // first we want to create a copy of ourselves without any button changes
                    // this is done only for mouse handlers, as they have positional data we want to handle in a separate pass.
                    var iWithoutButtons = state.Mouse.Clone();

                    for (MouseButton b = 0; b < MouseButton.LastButton; b++)
                    {
                        iWithoutButtons.SetPressed(b, lastMouse?.IsPressed(b) ?? false);
                    }

                    //we start by adding this state to the processed list...
                    var newState = state.Clone();
                    newState.Mouse = lastMouse = iWithoutButtons;
                    yield return(newState);

                    //and then iterate over each button/key change, adding intermediate states along the way.
                    for (MouseButton b = 0; b < MouseButton.LastButton; b++)
                    {
                        if (state.Mouse.IsPressed(b) != (lastMouse?.IsPressed(b) ?? false))
                        {
                            lastMouse = lastMouse?.Clone() ?? new MouseState();

                            //add our single local change
                            lastMouse.SetPressed(b, state.Mouse.IsPressed(b));

                            newState       = state.Clone();
                            newState.Mouse = lastMouse;
                            yield return(newState);
                        }
                    }
                }

                if (state.Keyboard != null)
                {
                    if (lastKeyboard != null)
                    {
                        foreach (var releasedKey in lastKeyboard.Keys.Except(state.Keyboard.Keys))
                        {
                            var newState = state.Clone();
                            newState.Keyboard = lastKeyboard = new KeyboardState {
                                Keys = lastKeyboard.Keys.Where(d => d != releasedKey).ToArray()
                            };
                            yield return(newState);
                        }
                    }

                    foreach (var pressedKey in state.Keyboard.Keys.Except(lastKeyboard?.Keys ?? new Key[] { }))
                    {
                        var newState = state.Clone();
                        newState.Keyboard = lastKeyboard = new KeyboardState {
                            Keys = lastKeyboard?.Keys.Union(new[] { pressedKey }) ?? new[] { pressedKey }
                        };
                        yield return(newState);
                    }
                }
            }
        }
コード例 #23
0
 public void MiddleDownPending()
 {
     _current = _middleDownPending;
     _timer.Enabled = true;
 }
コード例 #24
0
 public InputState(InputState last = null)
 {
     Keyboard = new KeyboardState(last?.Keyboard);
     Mouse    = new MouseState(last?.Mouse);
 }
コード例 #25
0
        public override void Update(GameTime gameTime)
        {
            if (settingBoardState == SettingBoardState.Showing)
            {
                settingBoardState = SettingBoardState.Show;
            }
            else if (settingBoardState == SettingBoardState.Show)
            {
                if (startButton.StartButtonClicked)
                {
                    for (int i = 0; i < 2; i++)
                    {
                        PlayerSettings.Player[i].Type = PlayerType[i];
                        if (PlayerType[i] == PlayerTypes.AI)
                        {
                            PlayerSettings.Player[i].AIIndex = AIIndex[i];
                        }
                    }
                    settingBoardState = SettingBoardState.HidingForNewGame;
                }
                else if (startButton.ResumeButtonClicked)
                {
                    settingBoardState = SettingBoardState.HidingForResume;
                }
                else
                {
                    // 绘制选择状态
                    foreach (Piece piece in showPieces)
                    {
                        piece.CurrentDisplay = DisplayState.Normal;
                    }
                    foreach (Piece piece in playerTypePieces)
                    {
                        piece.CurrentDisplay = DisplayState.Normal;
                    }
                    foreach (int i in chooseIndex)
                    {
                        playerTypePieces[i].CurrentDisplay = DisplayState.CanMove;
                    }
                    for (int i = 0; i < AICount; i++)
                    {
                        if (chooseIndex[0] == 1)
                        {
                            aiTypePieces[0, i].PieceState = PieceState.Black;
                        }
                        else
                        {
                            aiTypePieces[0, i].PieceState = PieceState.Empty;
                        }
                        if (chooseIndex[1] == 2)
                        {
                            aiTypePieces[1, i].PieceState = PieceState.White;
                        }
                        else
                        {
                            aiTypePieces[1, i].PieceState = PieceState.Empty;
                        }
                    }
                    if (chooseIndex[0] == 1)
                    {
                        aiTypePieces[0, AIIndex[0]].CurrentDisplay = DisplayState.WillReverse;
                    }
                    if (chooseIndex[1] == 2)
                    {
                        aiTypePieces[1, AIIndex[1]].CurrentDisplay = DisplayState.WillReverse;
                    }
                    if (curGame.IsActive)
                    {
                        // 获取鼠标状态
                        lastMouseState    = currentMouseState;
                        currentMouseState = Mouse.GetState();
                        ReversiPiecePosition tempPosition = Board.IsMouseInPiece(currentMouseState);
                        // 如果移动鼠标
                        if (tempPosition != null)
                        {
                            // 如果划过的是黑白子
                            if (tempPosition.Y == 2)
                            {
                                if (tempPosition.X == 3)
                                {
                                    showPieces[0].CurrentDisplay = DisplayState.WillMove;
                                }
                                else if (tempPosition.X == 4)
                                {
                                    showPieces[1].CurrentDisplay = DisplayState.WillMove;
                                }
                            }
                            // 如果划过的是玩家类型选择
                            else if (tempPosition.Y == 3)
                            {
                                int index = -1;
                                if (tempPosition.X == 1)
                                {
                                    index = 0;
                                }
                                else if (tempPosition.X == 2)
                                {
                                    index = 1;
                                }
                                else if (tempPosition.X == 5)
                                {
                                    index = 2;
                                }
                                else if (tempPosition.X == 6)
                                {
                                    index = 3;
                                }
                                if (index >= 0)
                                {
                                    playerTypePieces[index].CurrentDisplay = DisplayState.WillMove;
                                }
                            }
                            // 如果划过的是AI类型
                            if ((tempPosition.X == 0 || tempPosition.X == 7) && (tempPosition.Y >= 3 && tempPosition.Y <= 2 + AICount))
                            {
                                if (chooseIndex[0] == 1 && tempPosition.X == 0)
                                {
                                    int index = tempPosition.Y - 3;
                                    aiTypePieces[0, index].CurrentDisplay = DisplayState.WillMove;
                                }
                                if (chooseIndex[1] == 2 && tempPosition.X == 7)
                                {
                                    int index = tempPosition.Y - 3;
                                    aiTypePieces[1, index].CurrentDisplay = DisplayState.WillMove;
                                }
                            }
                            // 如果按下鼠标左键
                            if ((currentMouseState.LeftButton == ButtonState.Pressed) && (lastMouseState.LeftButton == ButtonState.Released))
                            {
                                // 如果点击的是黑白子
                                if (tempPosition.Y == 2)
                                {
                                    if (tempPosition.X == 3)
                                    {
                                        chooseIndex[0] = 0; PlayerType[0] = PlayerTypes.Human;
                                        chooseIndex[1] = 2; PlayerType[1] = PlayerTypes.AI;
                                    }
                                    else if (tempPosition.X == 4)
                                    {
                                        chooseIndex[0] = 1; PlayerType[0] = PlayerTypes.AI;
                                        chooseIndex[1] = 3; PlayerType[1] = PlayerTypes.Human;
                                    }
                                }
                                // 如果点击的是玩家类型选择
                                else if (tempPosition.Y == 3)
                                {
                                    if (tempPosition.X == 1)
                                    {
                                        chooseIndex[0] = 0; PlayerType[0] = PlayerTypes.Human;
                                    }
                                    if (tempPosition.X == 2)
                                    {
                                        chooseIndex[0] = 1; PlayerType[0] = PlayerTypes.AI;
                                    }
                                    if (tempPosition.X == 5)
                                    {
                                        chooseIndex[1] = 2; PlayerType[1] = PlayerTypes.AI;
                                    }
                                    if (tempPosition.X == 6)
                                    {
                                        chooseIndex[1] = 3; PlayerType[1] = PlayerTypes.Human;
                                    }
                                }
                                // 如果点击的是AI类型选择
                                if (tempPosition.X == 0 || tempPosition.X == 7)
                                {
                                    if (chooseIndex[0] == 1 && tempPosition.X == 0)
                                    {
                                        AIIndex[0] = tempPosition.Y - 3;
                                    }
                                    if (chooseIndex[1] == 2 && tempPosition.X == 7)
                                    {
                                        AIIndex[1] = tempPosition.Y - 3;
                                    }
                                }
                            }
                        }
                    }
                    foreach (Piece piece in showPieces)
                    {
                        piece.Update(gameTime);
                    }
                    foreach (Piece piece in playerTypePieces)
                    {
                        piece.Update(gameTime);
                    }
                    foreach (Piece piece in aiTypePieces)
                    {
                        piece.Update(gameTime);
                    }
                    startButton.Update(gameTime);
                }
                // 获取键盘状态
                lastKeyboardState    = currentKeyboardState;
                currentKeyboardState = Keyboard.GetState(Keys.Escape);
                // 当按下 Escape 键时
                if (currentKeyboardState.IsKeyUp(Keys.Escape) && lastKeyboardState.IsKeyDown(Keys.Escape))
                {
                    if (settingType == SettingType.Pause)
                    {
                        settingBoardState = SettingBoardState.HidingForResume;
                    }
                }
            }
            else if (settingBoardState == SettingBoardState.HidingForNewGame)
            {
                // TODO: 隐藏动画
                settingBoardState = SettingBoardState.HideForNewGame;
            }
            else if (settingBoardState == SettingBoardState.HidingForResume)
            {
                // TODO: 隐藏动画
                settingBoardState = SettingBoardState.HideForResume;
            }
            else if (settingBoardState == SettingBoardState.HideForNewGame)
            {
                curGame.State = GameState.StartLoad;
            }
            else if (settingBoardState == SettingBoardState.HideForResume)
            {
                curGame.State = GameState.InGame;
            }
//            base.Update(gameTime);
        }
コード例 #26
0
 public void RightDownPending()
 {
     _current = _rightDownPending;
     _timer.Enabled = true;
 }
コード例 #27
0
ファイル: MouseState.cs プロジェクト: HaKDMoDz/InVision
		/// <summary>
		/// Initializes a new instance of the <see cref="MouseState"/> class.
		/// </summary>
		/// <param name="native">The native.</param>
		protected internal MouseState(IMouseState native)
			: base(native)
		{ }
コード例 #28
0
 public LocalMouseState(IMouseState state, Drawable us)
 {
     NativeState = state;
     this.us     = us;
 }
コード例 #29
0
ファイル: MouseState.cs プロジェクト: NeoAdonis/osu-framework
 public MouseState(IMouseState last = null)
 {
     LastState         = last;
     PositionMouseDown = last?.PositionMouseDown;
 }
コード例 #30
0
ファイル: StartButton.cs プロジェクト: walterlv/reversi-game
        public override void Update(GameTime gameTime)
        {
            if (curGame.IsActive)
            {
                // 获取鼠标状态
                lastMouseState    = currentMouseState;
                currentMouseState = Mouse.GetState();
                bool isMouseInUp = false, isMouseInDown = false;
                if (currentMouseState.X >= buttonRectangle.Left && currentMouseState.Y >= buttonRectangle.Top &&
                    currentMouseState.X <= buttonRectangle.Right && currentMouseState.Y <= buttonRectangle.Bottom)
                {
                    if (currentMouseState.Y <= buttonRectangle.CenterY)
                    {
                        isMouseInUp = true;
                    }
                    else
                    {
                        isMouseInDown = true;
                    }
                }
                if (isMouseInUp || isMouseInDown)
                {
                    if (type == SettingType.Start)
                    {
                        buttonTexture = buttonStartRollTexture;
                    }
                    else if (type == SettingType.Pause)
                    {
                        if (isMouseInUp)
                        {
                            buttonTexture = buttonResumeRollTexture;
                        }
                        else if (isMouseInDown)
                        {
                            buttonTexture = buttonRestartRollTexture;
                        }
                    }
                    // 如果单击鼠标左键
                    if ((currentMouseState.LeftButton == ButtonState.Released) && (lastMouseState.LeftButton == ButtonState.Pressed))
                    {
                        if (type == SettingType.Start || isMouseInDown)
                        {
                            startButtonClicked = true;
                        }
                        else
                        {
                            resumeButtonClicked = true;
                        }
                    }
                }
                // 当按下 Enter 键时
                lastKeyboardState    = currentKeyboardState;
                currentKeyboardState = Keyboard.GetState(Keys.Enter);
                if (currentKeyboardState.IsKeyUp(Keys.Enter) && lastKeyboardState.IsKeyDown(Keys.Enter))
                {
                    if (type == SettingType.Start)
                    {
                        startButtonClicked = true;
                    }
                    else
                    {
                        resumeButtonClicked = true;
                    }
                }
                if (buttonTexture == null)
                {
                    if (type == SettingType.Start)
                    {
                        buttonTexture = buttonStartNormalTexture;
                    }
                    else if (type == SettingType.Pause)
                    {
                        buttonTexture = buttonResumeNormalTexture;
                    }
                }
            }
//            base.Update(gameTime);
        }
コード例 #31
0
ファイル: Model.cs プロジェクト: RuiChen0101/sketch_system
 //SetPointerState
 public void SetPointerState()
 {
     _mouseState = new PointerState(this);
 }
コード例 #32
0
 public void LeftDownPending()
 {
     _current = _leftDownPending;
     _timer.Enabled = true;
 }
コード例 #33
0
        public override void Update(GameTime gameTime)
        {
            if (isMyTurn && !isMovingPiece && curGame.IsActive)
            {
                // 获取键盘状态
                lastKeyboardState    = currentKeyboardState;
                currentKeyboardState = Keyboard.GetState(Keys.LeftControl, Keys.RightControl, Keys.Z);
                // 当按下 Ctrl+Z 时
                if ((currentKeyboardState.IsKeyDown(Keys.LeftControl) || currentKeyboardState.IsKeyDown(Keys.RightControl)) &&
                    currentKeyboardState.IsKeyDown(Keys.Z))
                {
                    isCtrlZPressed = true;
                }
                else if (currentKeyboardState.IsKeyUp(Keys.Z))
                {
                    if (isCtrlZPressed)
                    {
                        isCtrlZPressed = false; if (GameSettings.IsRegretEnabled)
                        {
                            RegretMovePiece();
                        }
                    }
                }
                foreach (ReversiPiecePosition rpp in reversiGame.GetEnabledPositions())
                {
                    pieces[rpp.X, rpp.Y].CurrentDisplay = DisplayState.CanMove;
                }
                lastMouseState    = currentMouseState;
                currentMouseState = Mouse.GetState();
                ReversiPiecePosition tempPosition = Board.IsMouseInPiece(currentMouseState);
                // 如果移动鼠标
                if (tempPosition != null && reversiGame.IspieceEnabled(tempPosition))
                {
                    pieces[tempPosition.X, tempPosition.Y].CurrentDisplay = DisplayState.WillMove;
                    foreach (ReversiPiecePosition rpp in reversiGame.GetReversePositions(tempPosition))
                    {
                        pieces[rpp.X, rpp.Y].CurrentDisplay = DisplayState.WillReverse;
                    }
                }
                // 如果单击鼠标左键
                if ((currentMouseState.LeftButton == ButtonState.Released) && (lastMouseState.LeftButton == ButtonState.Pressed))
                {
                    if (tempPosition != null && reversiGame.IspieceEnabled(tempPosition))
                    {
                        isMovePieceCompleted = false;

                        /*pieces[tempPosition.X, tempPosition.Y].PieceState = (PieceState)myPieceColor;
                         * foreach (ReversiPiecePosition rpp in reversiGame.GetReversePositions(tempPosition))
                         *  pieces[rpp.X, rpp.Y].PieceState = (PieceState)myPieceColor;*/
                        MovePiece(tempPosition);
                    }
                }
            }
            if (isMovePieceCompleted && isMyTurn)
            {
                if (!reversiGame.IsGameOver && reversiGame.CurrentPiece == reversiGame.LastPiece)
                {
                    // TODO: 添加无子可下的显示
                }
                isMyTurn      = false;
                isMovingPiece = false;
            }

            base.Update(gameTime);
        }
コード例 #34
0
ファイル: Model.cs プロジェクト: RuiChen0101/sketch_system
 //SetDrawState
 public void SetDrawState(ShapeType type)
 {
     _mouseState = new DrawState(this, type);
     _selected   = null;
     this._shapeSelect("");
 }
コード例 #35
0
ファイル: StateMachine.cs プロジェクト: justry/touchmousemate
 public void RightDownPending()
 {
     _current       = _rightDownPending;
     _timer.Enabled = true;
 }
コード例 #36
0
        /// <summary>
        /// Reads the mouse state from <see cref="GameHost.GetMouseState"/>.
        /// </summary>
        /// <param name="elapsedSeconds">Fractional seconds passed since Update was called.</param>
        public void Update(TimeSpan elapsedSeconds)
        {
            IMouseState currentState = GameHost.Instance.GetMouseState();

            // Update local state
            bool leftDown   = currentState.IsLeftButtonDown;
            bool rightDown  = currentState.IsRightButtonDown;
            bool middleDown = currentState.IsMiddleButtonDown;

            ScrollWheelValueChange = ScrollWheelValue - currentState.MouseWheel;
            ScrollWheelValue       = currentState.MouseWheel;

            ScreenPosition = new Point((int)(currentState.ScreenPosition.X * Settings.Rendering.RenderScale.X), (int)(currentState.ScreenPosition.Y * Settings.Rendering.RenderScale.Y)) - new Point((int)(Settings.Rendering.RenderRect.X * Settings.Rendering.RenderScale.X), (int)(Settings.Rendering.RenderRect.Y * Settings.Rendering.RenderScale.Y));

            // Count time for full clicks
            if (!_leftPressedLastFrame && leftDown)
            {
                _leftPressedLastFrame = true;
            }
            else if (leftDown)
            {
                _leftLastClickedTime += elapsedSeconds;
            }

            if (!_rightPressedLastFrame && rightDown)
            {
                _rightPressedLastFrame = true;
            }
            else if (rightDown)
            {
                _rightLastClickedTime += elapsedSeconds;
            }

            if (!_middlePressedLastFrame && middleDown)
            {
                _middlePressedLastFrame = true;
            }
            else if (middleDown)
            {
                _middleLastClickedTime += elapsedSeconds;
            }

            // Get the mouse button state change
            bool newLeftClicked   = LeftButtonDown && !leftDown;
            bool newRightClicked  = RightButtonDown && !rightDown;
            bool newMiddleClicked = MiddleButtonDown && !middleDown;

            // Set state of double clicks
            if (!newLeftClicked)
            {
                LeftDoubleClicked = false;
            }

            if (!newRightClicked)
            {
                RightDoubleClicked = false;
            }

            if (!newMiddleClicked)
            {
                MiddleDoubleClicked = false;
            }

            if (LeftClicked && newLeftClicked && _leftLastClickedTime < Settings.Input.MouseDoubleClickTime)
            {
                LeftDoubleClicked = true;
            }

            if (RightClicked && newRightClicked && _rightLastClickedTime < Settings.Input.MouseDoubleClickTime)
            {
                RightDoubleClicked = true;
            }

            if (MiddleClicked && newMiddleClicked && _middleLastClickedTime < Settings.Input.MouseDoubleClickTime)
            {
                MiddleDoubleClicked = true;
            }

            // Set state of click and mouse down
            LeftClicked      = newLeftClicked && _leftLastClickedTime < Settings.Input.MouseClickTime;
            RightClicked     = newRightClicked && _rightLastClickedTime < Settings.Input.MouseClickTime;
            MiddleClicked    = newMiddleClicked && _middleLastClickedTime < Settings.Input.MouseClickTime;
            LeftButtonDown   = leftDown;
            RightButtonDown  = rightDown;
            MiddleButtonDown = middleDown;

            // Clear any click frame tracking
            if (_leftPressedLastFrame && !leftDown)
            {
                _leftPressedLastFrame = false;
                _leftLastClickedTime  = TimeSpan.Zero;
            }

            if (_rightPressedLastFrame && !rightDown)
            {
                _rightPressedLastFrame = false;
                _rightLastClickedTime  = TimeSpan.Zero;
            }

            if (_middlePressedLastFrame && !middleDown)
            {
                _middlePressedLastFrame = false;
                _middleLastClickedTime  = TimeSpan.Zero;
            }
        }
コード例 #37
0
ファイル: StateMachine.cs プロジェクト: justry/touchmousemate
 public void MiddleDownPending()
 {
     _current       = _middleDownPending;
     _timer.Enabled = true;
 }