Ejemplo n.º 1
0
        public GameplayScreen()
        {
            pendingCommands     = new Queue <Keys>();
            Mode                = GameplayDrawMode.Puzzle;
            previewVector       = new Vector2(0, 0);
            totalGameTimeVector = new Vector2(10, 10);
            gameOptionsScreen   = new InGameOptionsScreen(this);
            previewScreen       = new PreviewScreen(this);

            TransitionOnTime  = TimeSpan.Zero;
            TransitionOffTime = TimeSpan.Zero;
        }
Ejemplo n.º 2
0
        private void CheckForCompletion()
        {
            for (int i = 0; i < scrambledPieces.Count - 1; i++)
            {
                if (scrambledPieces[i].Index != i)
                {
                    return;
                }
            }

            solved = true;
            Mode   = GameplayDrawMode.Congratulations;
        }
Ejemplo n.º 3
0
        public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
        {
#if WINDOWS_PHONE
            var mouseState = Mouse.GetState();
            if (mouseState.LeftButton == ButtonState.Pressed)
            {
                //if (animating)
                //{
                //    playingTime += gameTime.ElapsedGameTime.TotalMilliseconds;
                //    base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
                //    return;
                //}

                var clickedRectangle = new Rectangle(mouseState.X, mouseState.Y, width, height);
                var pieceRect        = new Rectangle(0, 0, width, height);

                for (int i = 0; i < scrambledPieces.Count; i++)
                {
                    pieceRect.X = (int)scrambledPieces[i].Bounds.X;
                    pieceRect.Y = (int)scrambledPieces[i].Bounds.Y;

                    if (!pieceRect.Intersects(clickedRectangle))
                    {
                        continue;
                    }

                    if (mouseState.X >= emptyPiece.X &&
                        mouseState.X <= emptyPiece.X + width &&
                        mouseState.Y >= emptyPiece.Y &&
                        mouseState.Y <= emptyPiece.Y + height)
                    {
                        continue;
                    }

                    Keys command = Keys.None;
                    if (pieceRect.X >= emptyPiece.X && pieceRect.X <= emptyPiece.X)
                    {
                        if (pieceRect.Y - height == emptyPiece.Y)
                        {
                            command = Keys.Up;
                        }
                        else if (pieceRect.Y + height == emptyPiece.Y)
                        {
                            command = Keys.Down;
                        }
                    }
                    else if (pieceRect.Y >= emptyPiece.Y && pieceRect.Y <= emptyPiece.Y)
                    {
                        if (pieceRect.X - width == emptyPiece.X)
                        {
                            command = Keys.Left;
                        }
                        else if (pieceRect.X + width == emptyPiece.X)
                        {
                            command = Keys.Right;
                        }
                    }

                    if (command != Keys.None && !pendingCommands.Contains(command))
                    {
                        pendingCommands.Enqueue(command);
                        Debug.WriteLine("Clicked: " + i);
                    }
                    break;
                }
            }
            else
            {
                elapsedTime += gameTime.ElapsedGameTime.TotalMilliseconds;
            }
#elif WINDOWS
            var keyState = Keyboard.GetState();
            if (keyState.IsKeyDown(Keys.Enter) || keyState.IsKeyDown(Keys.F1))
            {
                Mode = GameplayDrawMode.Preview;
            }
            else
            {
                //if (animating)
                //{
                //    playingTime += gameTime.ElapsedGameTime.TotalMilliseconds;
                //    base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
                //    return;
                //}

                if (!solved)
                {
                    Mode = GameplayDrawMode.Puzzle;
                }

                Keys command     = Keys.None;
                var  pressedKeys = keyState.GetPressedKeys();
                if (pressedKeys.Length > 0)
                {
                    for (int i = 0; i < pressedKeys.Length; i++)
                    {
                        if (pressedKeys[i] != Keys.None)
                        {
                            command = pressedKeys[i];
                            Debug.WriteLine(string.Format("Key Pressed [{0}]:{1}", i, pressedKeys[i]));
                        }
                    }
                }

                switch (command)
                {
                case Keys.Up:
                case Keys.Down:
                case Keys.Left:
                case Keys.Right:
                    //if (animating)
                    //{
                    //    base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
                    //    return;
                    //}

                    if (!pendingCommands.Contains(command))
                    {
                        pendingCommands.Enqueue(command);
                    }
                    break;

                //case Keys.Q:
                //case Keys.Escape:
                //    ScreenManager.Game.Exit();
                //    break;
                case Keys.R:
                case Keys.F5:
                    Scramble();
                    solved      = false;
                    playingTime = 0;
                    break;

                default:
                    elapsedTime += gameTime.ElapsedGameTime.TotalMilliseconds;
                    break;
                }
            }
#endif
            if (elapsedTime >= 10)
            {
                if (pendingCommands.Count > 0)
                {
                    MovePiece(pendingCommands.Dequeue());
                    CheckForCompletion();
                }
                elapsedTime = 0;
            }

            if (!solved)
            {
                playingTime += gameTime.ElapsedGameTime.TotalMilliseconds;
            }

            base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
        }