예제 #1
0
        /// <summary>
        /// updates the game based on gametime
        /// </summary>
        /// <param name="gameTime"></param>
        public override void Update(GameTime gameTime) {
            MouseState state = Mouse.GetState();
            mposition.X = state.X;
            mposition.Y = state.Y;
            
            if (previousMouseState.LeftButton == ButtonState.Pressed && state.LeftButton == ButtonState.Pressed && current._isPressed) {

                current.position.X = mposition.X - 50;
                current.position.Y = mposition.Y - 50;
                if (Game1.hosting == true) {
                    string sending = "Chess" + " " + current.pieceNo + " " + current.position.X + " " + current.position.Y + " ";
                    //System.Diagnostics.Debug.WriteLine("Host sending");
                    Host.Send(sending);
                }
                else {
                    string sending = "Chess" + " " + current.pieceNo + " " + current.position.X + " " + current.position.Y + " ";
                    //System.Diagnostics.Debug.WriteLine("Client sending");
                    Join.Send(sending);
                }

            }
            if (state.LeftButton == ButtonState.Pressed && !current._isPressed) {
                MousePressed((int)mposition.X, (int)mposition.Y);
            }
            if (previousMouseState.LeftButton == ButtonState.Pressed && state.LeftButton == ButtonState.Released) {
                current._isPressed = false;
                current = new CheckersPiece();
            }
            previousMouseState = state;
        }
예제 #2
0
        /// <summary>
        /// updates the game based on gametime
        /// </summary>
        /// <param name="gameTime"></param>
        public override void Update(GameTime gameTime) {
            MouseState state = Mouse.GetState();
            mposition.X = state.X;
            mposition.Y = state.Y;
            if (previousMouseState.LeftButton == ButtonState.Pressed && state.LeftButton == ButtonState.Pressed && current._isPressed) {

                current.position.X = mposition.X - 50;
                current.position.Y = mposition.Y - 50;
                ///Doesn't work if we have just 1 big string at the top for some reason
                if (Game1.hosting == true) {
                    string sending = " " + "Checkers" + " " + current.pieceNo + " " + current.position.X + " " + current.position.Y + " ";
                    Host.Send(sending);
                }
                else {
                    string sending = " " + "Checkers" + " " + current.pieceNo + " " + current.position.X + " " + current.position.Y + " ";
                    Join.Send(sending);
                }
            }
            ///What happens if a piece is pressed
            if (state.LeftButton == ButtonState.Pressed && !current._isPressed) {
                MousePressed((int)mposition.X, (int)mposition.Y);
            }
            ///What happens when a piece is released
            if (previousMouseState.LeftButton == ButtonState.Pressed && state.LeftButton == ButtonState.Released) {
                current._isPressed = false;
                current = new CheckersPiece();
            }
            previousMouseState = state;
        }
예제 #3
0
        public void MousePressed(int x, int y) {
            Rectangle mouseRect = new Rectangle(x, y, 1, 1);
            for (int i = 0; i < pieces.Length; i++) {
                list[i] = (new Rectangle((int)pieces[i].position.X, (int)pieces[i].position.Y, 100, 100));
            }

            for (int i = 0; i < list.Length; i++) {
                if (mouseRect.Intersects(list[i])) {
                    current = pieces[i];
                    current._isPressed = true;
                    break;
                }
            }
        }