Exemplo n.º 1
0
        /// <summary>
        /// When the user cancels the main menu, ask if they want to exit the sample.
        /// </summary>
        protected override void OnCancel()
        {
            const string message = "Are you sure you want to exit Pickture?";

            MessageBoxScreen confirmExitMessageBox = new MessageBoxScreen(message);

            confirmExitMessageBox.Accepted += ConfirmExitMessageBoxAccepted;
            ScreenManager.AddScreen(confirmExitMessageBox);
        }
Exemplo n.º 2
0
        public override void HandleInput(InputState input)
        {
            if (input.MenuCancel)
            {
                MessageBoxScreen messageBox = new MessageBoxScreen(
                    "Are you sure you want to quit this game?\nYour progress will be lost");

                messageBox.Accepted += QuitMessageBoxAccepted;
                ScreenManager.AddScreen(messageBox);
            }

            // Do not handle controls while the camera is flipping
            if (board.Camera.IsFlipping)
            {
                return;
            }

            // Some controls only apply when the puzzle is two sided
            if (board.TwoSided)
            {
                // Handle flipping camera to other side of board
                if (input.FlipCameraLeft)
                {
                    board.Camera.Flip(Camera.FlipDirection.Left);
                }
                else if (input.FlipCameraRight)
                {
                    board.Camera.Flip(Camera.FlipDirection.Right);
                }
                // Handle flipping the active chip
                else if (input.FlipUp)
                {
                    if (board.Camera.Side == Camera.BoardSide.Front)
                    {
                        ActiveChip.Flip(Chip.RevolveDirection.Up);
                    }
                    else
                    {
                        ActiveChip.Flip(Chip.RevolveDirection.Down);
                    }
                }
                else if (input.FlipDown)
                {
                    if (board.Camera.Side == Camera.BoardSide.Front)
                    {
                        ActiveChip.Flip(Chip.RevolveDirection.Down);
                    }
                    else
                    {
                        ActiveChip.Flip(Chip.RevolveDirection.Up);
                    }
                }
                else if (input.FlipLeft)
                {
                    ActiveChip.Flip(Chip.RevolveDirection.Left);
                }
                else if (input.FlipRight)
                {
                    ActiveChip.Flip(Chip.RevolveDirection.Right);
                }
            }

            // Handle selecting a new active chip
            HandleChipSelection(input);

            // Handle shifting
            if (input.ShiftActiveChip && !board.IsShifting)
            {
                board.Shift(activeChipX, activeChipY);
                if (board.IsShifting)
                {
                    // When a shift occurs, the active chip moves with the shift
                    SetActiveChip(activeChipX + board.ShiftX,
                                  activeChipY + board.ShiftY);
                }
            }

            // Did any moves during this update result in the puzzle being sovled?
            if (this.board.IsPuzzleComplete())
            {
                // Transition to the CompletedScreen
                ExitScreen();
                foreach (GameScreen screen in ScreenManager.GetScreens())
                {
                    if (screen is BoardScreen)
                    {
                        screen.ExitScreen();
                    }
                }
                ScreenManager.AddScreen(new CompletedScreen(board.CurrentPictureSet));
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Construct a new instance of Pickture. This method will enforce that it is
        /// only ever called once because the game class itself is a singleton.
        /// </summary>
        public Pickture()
        {
            // Enforce singleton
            if (instance != null)
            {
                throw new InvalidOperationException(
                          "Only one instance of Pickture may be created.");
            }
            instance = this;

            // Initalize graphics
            graphics = new GraphicsDeviceManager(this);
            graphics.MinimumVertexShaderProfile = ShaderProfile.VS_2_0;
            graphics.MinimumPixelShaderProfile  = ShaderProfile.PS_2_0;

#if XBOX360
            // On Xbox360, always use the user's preferred resolution and multisampling
            // The other approach is to always use the same resolution (typically
            // 1920x1080). The hardware will automatically down scale and letterbox as
            // needed. However, Pickture is already resolution independant for Windows
            graphics.PreferredBackBufferWidth  = Window.ClientBounds.Width;
            graphics.PreferredBackBufferHeight = Window.ClientBounds.Height;
            graphics.PreferMultiSampling       = true;
            graphics.PreparingDeviceSettings  +=
                new EventHandler <PreparingDeviceSettingsEventArgs>(
                    graphics_PreparingDeviceSettings);
#else
            // On Windows, just use a small and simple starting size, but allow
            // the user to resize the Window however they like
            graphics.PreferredBackBufferWidth  = 800;
            graphics.PreferredBackBufferHeight = 600;
            Window.AllowUserResizing           = true;
            graphics.IsFullScreen = false;
#endif


            // Initalzie content
            Content.RootDirectory = "Content";

            // Initalize screen management
            ScreenManager screenManager = new ScreenManager(this);
            Components.Add(screenManager);

            // Initalize picture database
            PictureDatabase.Initialize();

            // If enough pictures are available,
            if (PictureDatabase.Count >= 2)
            {
                // start up the game
                screenManager.AddScreen(new MainMenuScreen());
            }
            else
            {
                // Otherwise, show error and quit
                MessageBoxScreen messageBox = new MessageBoxScreen(
                    "Unable to find enough pictures to play.", false);
                messageBox.Accepted += new EventHandler <EventArgs>(messageBox_Accepted);
                screenManager.AddScreen(messageBox);
            }
        }