예제 #1
0
 public void Back()
 {
     if (mode != ControlMode.EDITOR)
     {
         //puzzleBox = prevPuzzleBox.Copy();
         //masterGrid = prevMasterGrid.Copy();
         newPuzzleBox = prevPuzzleBox.Copy();
         newMasterGrid = prevMasterGrid.Copy();
         puzzleBox.Mark();
         masterGrid.Mark();
         newCubeDistance = prevCubeDistance;
         //gameState = State.NEWSET;
         pendingResult = GameStopCause.NONE;
         gameState = State.VANISH;
         animateTime = 0;
         prevPuzzleBox = null;
         prevMasterGrid = null;
     }
 }
예제 #2
0
        public GameStopCause Update(GameTime gameTime)
        {
            cooldown -= gameTime.ElapsedGameTime.Milliseconds;
            if (cooldown < 0) cooldown = 0;
            if (mode != ControlMode.EDITOR)
            {
                Matcher.UpdateTimeCountdown(puzzleBox, masterGrid, gameTime.ElapsedGameTime.Milliseconds);
                if (false == timer.Update(gameTime))
                {
                    Logger.totalScore = currentScore;
                    Logger.LogGame();
                    return GameStopCause.END;
                }
                clock.Update(gameTime);
            }
            // Game state flow
            if (gameState == State.DESTROY || gameState == State.VANISH || gameState == State.NEWSET)
            {
                animateTime += gameTime.ElapsedGameTime.Milliseconds;
                if (animateTime > maxAnimateTime)
                    animateTime = maxAnimateTime;
            }
            if (gameState == State.PAUSING || gameState == State.RESUMING)
            {
                animateTime += gameTime.ElapsedGameTime.Milliseconds;
                if (animateTime > 2*maxAnimateTime)
                    animateTime = 2*maxAnimateTime;
            }
            if (gameState == State.REGENERATE)
            {
                animateTime += gameTime.ElapsedGameTime.Milliseconds;
                if (animateTime > maxAnimateTime * maxSlideDistance)
                    animateTime = maxAnimateTime * maxSlideDistance;
            }
            if (gameState == State.MOVECOMPLETE)
            {
                if (mode == ControlMode.EDITOR) gameState = State.READY;
                else
                {
                    if(Game.currentSettings.mode==GameMode.MoveChallenge)
                        movesRemaining--;
                    Matcher.UpdateToggleState(puzzleBox, masterGrid);
                    gameState = State.VERIFY;
                }
            }
            if (gameState == State.VERIFY)
            {
                List<ScoringSet> scoreSet = Matcher.Solve(puzzleBox, masterGrid);
                if (scoreSet.Count > 0)
                    SoundEffects.PlayScore();
                foreach (ScoringSet s in scoreSet)
                {
                    if (Game.currentSettings.loseType == LoseType.BADCOLOR)
                    {
                        if (s.color == Game.currentSettings.dangerColor)
                            pendingResult = GameStopCause.LOSE_ERROR;
                    }
                    s.CalculateScore();
                    s.LogScore();
                    currentScore += s.score;
                    scoreList.Add(s);
                }
                if (Matcher.AllGray(puzzleBox, masterGrid))
                {
                    if (Game.currentSettings.mode == GameMode.Tutorial)
                    {
                        TutorialStage.phase = TutorialPhase.Pass;
                        return GameStopCause.TUTORIAL_PASS;
                    }
                    return GameStopCause.WIN;
                }
                maxSlideDistance = Matcher.GetMaxReplaceDistance(puzzleBox, masterGrid);
                if (0 == maxSlideDistance)
                {
                    if (movesRemaining == 0)
                        return GameStopCause.END;

                    if (!Matcher.HasValidMove(puzzleBox, masterGrid))
                    {
                        if (Game.currentSettings.mode == GameMode.Puzzle)
                        {
                            return GameStopCause.LOSE_STUCK;
                        }
                        else if (Game.currentSettings.mode == GameMode.Tutorial)
                        {
                            return GameStopCause.TUTORIAL_FAIL;
                        }
                        else
                        {
                            newPuzzleBox = new PuzzleBox();
                            newMasterGrid = new MasterGrid();
                            Matcher.Reset(newPuzzleBox, newMasterGrid);
                            newPuzzleBox.activeZ = puzzleBox.activeZ;
                            newCubeDistance = cubeDistance;
                            gameState = State.VANISH;
                            puzzleBox.Mark();
                            masterGrid.Mark();
                            animateTime = 0;
                        }
                    }
                    else
                    {
                        Matcher.UpdateMoveCountdown(puzzleBox, masterGrid);
                        gameState = State.READY;
                        animateTime = 0;
                    }
                }
                else
                {
                    gameState = State.DESTROY;
                    animateTime = 0;
                }
            }
            if (gameState == State.DESTROY && animateTime == maxAnimateTime)
            {
                if (pendingResult != GameStopCause.NONE)
                    return pendingResult;
                for (int x = 0; x < gridSize; x++)
                {
                    for (int y = 0; y < gridSize; y++)
                    {
                        if (masterGrid[x, y].marked)
                        {
                            fragmentList.Add(new Fragment(masterGrid[x, y].screenX, masterGrid[x, y].screenY, Game.screenSizeX, Game.screenSizeY, masterGrid[x, y].scale, masterGrid[x, y].color));
                        }
                    }
                }
                for (int y = 0; y < boxSize; y++)
                {
                    for (int z = 0; z < boxSize; z++)
                    {
                        if (puzzleBox[0, y, z].marked)
                        {
                            fragmentList.Add(new Fragment(puzzleBox[0, y, z].screenX, puzzleBox[0, y, z].screenY, Game.screenSizeX, Game.screenSizeY, puzzleBox[0, y, z].scale, puzzleBox[0, y, z].color));
                        }
                    }
                }
                // Regenerate orbs
                Matcher.Replace(puzzleBox, masterGrid);
                gameState = State.REGENERATE;
                animateTime = 0;
            }
            if (gameState == State.PAUSING && animateTime == 2 * maxAnimateTime)
            {
                gameState = State.RESUMING;
                animateTime = 0;
                SoundEffects.PlayMove();
                return GameStopCause.PAUSE;
            }
            if (gameState == State.RESUMING && animateTime == 2 * maxAnimateTime)
            {
                //Matcher.Reset(puzzleBox,masterGrid);
                Matcher.Clear(puzzleBox, masterGrid);
                gameState = State.READY;
                animateTime = 0;
                if (Game.currentSettings.mode == GameMode.Tutorial && firstResume == true)
                {
                    firstResume = false;
                    return GameStopCause.TUTORIAL_TEXT;
                }
            }
            if (gameState == State.VANISH && animateTime == maxAnimateTime)
            {
                if (newPuzzleBox != null)
                {
                    puzzleBox = newPuzzleBox.Copy();
                    masterGrid = newMasterGrid.Copy();
                    cubeDistance = newCubeDistance;
                    newPuzzleBox = null;
                    newMasterGrid = null;
                }
                gameState = State.NEWSET;
                animateTime = 0;
            }
            if (gameState == State.NEWSET && animateTime == maxAnimateTime)
            {
                Matcher.Clear(puzzleBox, masterGrid);
                gameState = State.READY;
                animateTime = 0;
                if (Game.currentSettings.mode == GameMode.Tutorial && firstResume==true)
                {
                    firstResume = false;
                    return GameStopCause.TUTORIAL_TEXT;
                }
            }
            if (gameState == State.REGENERATE && animateTime == maxAnimateTime * maxSlideDistance)
            {
                // Clear orbs
                Matcher.Clear(puzzleBox, masterGrid);
                gameState = State.VERIFY;
            }

            if (gameState == State.READY)
            {
                if(mode!=ControlMode.EDITOR)
                    Matcher.UpdateTimeCountdown(puzzleBox, masterGrid, gameTime.ElapsedGameTime.Milliseconds);
                if (mode == ControlMode.NORMAL)
                {
                    if (Keyboard.GetState().IsKeyDown(Keys.P) || GamePad.GetState(Game.playerIndex).IsButtonDown(Buttons.Start))
                    {
                        gameState = State.PAUSING;
                        savedShift = shift;
                        animateTime = 0;
                    }
                }
                if (mode == ControlMode.NORMAL || mode == ControlMode.EDITOR)
                {
                    Vector2 stick = GamePad.GetState(Game.playerIndex).ThumbSticks.Left;
                    GamePadState gamePadState = GamePad.GetState(Game.playerIndex);
                    //if (gamePadState.IsConnected == false)
                    //{
                        //gameState = State.PAUSING;
                        //animateTime = 0;
                    //}
                    if (Keyboard.GetState().IsKeyDown(Keys.B) || gamePadState.IsButtonDown(Buttons.B))
                    {
                        if (Game.currentSettings.mode == GameMode.Puzzle)
                        {
                            if (prevPuzzleBox == null)
                                SoundEffects.PlayClick();
                            else
                            {
                                SoundEffects.PlayScore();
                                Back();
                            }
                        }
                    }
                    if ((Keyboard.GetState().IsKeyDown(Keys.E) || gamePadState.IsButtonDown(Buttons.Y)))
                    {
                        if (cooldown == 0)
                        {
                            Game.gameSettings.soundEffectsEnabled = !Game.gameSettings.soundEffectsEnabled;
                            cooldown = 250;
                        }
                    }
                    if (cooldown==0 && (Keyboard.GetState().IsKeyDown(Keys.M) || gamePadState.IsButtonDown(Buttons.X)))
                    {
                        if (Game.gameSettings.musicEnabled)
                        {
                            Game.gameSettings.musicEnabled = false;
                            MusicControl.Stop();
                        }
                        else
                        {
                            Game.gameSettings.musicEnabled = true;
                            if (Game.currentSettings.mode == GameMode.Tutorial)
                                MusicControl.PlayMenuMusic();
                            else
                                MusicControl.PlayGameMusic();
                        }
                        cooldown = 250;
                    }
                    if(cooldown==0 && (Keyboard.GetState().IsKeyDown(Keys.OemPlus) || gamePadState.IsButtonDown(Buttons.Back)))
                    {
                        Game.gameSettings.displayControls = !Game.gameSettings.displayControls;
                        cooldown = 250;
                    }
                    if ((TutorialStage.phase == TutorialPhase.None || TutorialStage.restrictions == ControlRestrictions.None || TutorialStage.restrictions == ControlRestrictions.StickOnly))
                    {
                        if (gamePadState.IsButtonDown(Buttons.DPadLeft) || gamePadState.IsButtonDown(Buttons.DPadLeft) || Keyboard.GetState().IsKeyDown(Keys.Left) || stick.X < -Game.gameSettings.controlStickTrigger)
                        {
                            SoundEffects.PlayMove();
                            prevMasterGrid = masterGrid.Copy();
                            prevPuzzleBox = puzzleBox.Copy();
                            prevCubeDistance = cubeDistance;
                            gameState = State.ROTATEPOSY;
                        }
                        if (gamePadState.IsButtonDown(Buttons.DPadRight) || gamePadState.IsButtonDown(Buttons.DPadRight) || Keyboard.GetState().IsKeyDown(Keys.Right) || stick.X > Game.gameSettings.controlStickTrigger)
                        {
                            SoundEffects.PlayMove();
                            prevMasterGrid = masterGrid.Copy();
                            prevPuzzleBox = puzzleBox.Copy();
                            prevCubeDistance = cubeDistance;
                            gameState = State.ROTATENEGY;
                        }
                        if (gamePadState.IsButtonDown(Buttons.DPadUp) || gamePadState.IsButtonDown(Buttons.DPadUp) || Keyboard.GetState().IsKeyDown(Keys.Up) || stick.Y > Game.gameSettings.controlStickTrigger)
                        {
                            SoundEffects.PlayMove();
                            prevMasterGrid = masterGrid.Copy();
                            prevPuzzleBox = puzzleBox.Copy();
                            prevCubeDistance = cubeDistance;
                            gameState = State.ROTATEPOSX;
                        }
                        if (gamePadState.IsButtonDown(Buttons.DPadDown) || gamePadState.IsButtonDown(Buttons.DPadDown) || gamePadState.IsButtonDown(Buttons.DPadDown) || Keyboard.GetState().IsKeyDown(Keys.Down) || stick.Y < -Game.gameSettings.controlStickTrigger)
                        {
                            SoundEffects.PlayMove();
                            prevMasterGrid = masterGrid.Copy();
                            prevPuzzleBox = puzzleBox.Copy();
                            prevCubeDistance = cubeDistance;
                            gameState = State.ROTATENEGX;
                        }
                    }
                    if (TutorialStage.phase==TutorialPhase.None || TutorialStage.restrictions == ControlRestrictions.None || TutorialStage.restrictions == ControlRestrictions.ShouldersOnly)
                    {
                        if (Keyboard.GetState().IsKeyDown(Keys.S) || gamePadState.IsButtonDown(Buttons.RightShoulder))
                        {
                            SoundEffects.PlayMove();
                            prevMasterGrid = masterGrid.Copy();
                            prevPuzzleBox = puzzleBox.Copy();
                            prevCubeDistance = cubeDistance;
                            gameState = State.ROTATEPOSZ;
                        }
                        if (Keyboard.GetState().IsKeyDown(Keys.A) || gamePadState.IsButtonDown(Buttons.LeftShoulder))
                        {
                            SoundEffects.PlayMove();
                            prevMasterGrid = masterGrid.Copy();
                            prevPuzzleBox = puzzleBox.Copy();
                            prevCubeDistance = cubeDistance;
                            gameState = State.ROTATENEGZ;
                        }
                    }
                    if (TutorialStage.phase == TutorialPhase.None || TutorialStage.restrictions == ControlRestrictions.None || TutorialStage.restrictions == ControlRestrictions.TriggersOnly)
                    {
                        if (Keyboard.GetState().IsKeyDown(Keys.Q) || gamePadState.IsButtonDown(Buttons.LeftTrigger) || gamePadState.IsButtonDown(Buttons.LeftTrigger))
                        {
                            if (cubeDistance < spacing * 2)
                            {
                                SoundEffects.PlayMove();
                                prevMasterGrid = masterGrid.Copy();
                                prevPuzzleBox = puzzleBox.Copy();
                                prevCubeDistance = cubeDistance;
                                cubeDistanceGoal = cubeDistance + spacing;
                                gameState = State.PUSH;
                            }
                        }
                        if (Keyboard.GetState().IsKeyDown(Keys.W) || gamePadState.IsButtonDown(Buttons.RightTrigger) || gamePadState.IsButtonDown(Buttons.RightTrigger))
                        {
                            if (cubeDistance > 0)
                            {
                                SoundEffects.PlayMove();
                                prevMasterGrid = masterGrid.Copy();
                                prevPuzzleBox = puzzleBox.Copy();
                                prevCubeDistance = cubeDistance;
                                cubeDistanceGoal = cubeDistance - spacing;
                                gameState = State.PULL;
                            }
                        }
                    }
                }
                if (mode == ControlMode.AUTOMATED)
                {
                    int x = automator.Next(0, 8);
                    if (x == 0) gameState = State.ROTATEPOSY;
                    if (x == 1) gameState = State.ROTATEPOSZ;
                    if (x == 2) gameState = State.ROTATEPOSX;
                    if (x == 3) gameState = State.ROTATENEGX;
                    if (x == 4) gameState = State.ROTATENEGY;
                    if (x == 5) gameState = State.ROTATENEGZ;
                    if (x == 6)
                    {
                        if (cubeDistance > 0)
                        {
                            cubeDistanceGoal = cubeDistance - spacing;
                            gameState = State.PULL;
                        }
                    }
                    if (x == 7)
                    {
                        if (cubeDistance < spacing * 2)
                        {
                            cubeDistanceGoal = cubeDistance + spacing;
                            gameState = State.PUSH;
                        }
                    }
                }
                if (mode == ControlMode.EDITOR)
                {
                    editorCooldown-=gameTime.ElapsedGameTime.Milliseconds;
                    if (editorCooldown < 0) editorCooldown = 0;
                    if (editorCooldown == 0)
                    {
                        if (Keyboard.GetState().IsKeyDown(Keys.NumPad1))
                        {
                            puzzleBox.ClearSelection();
                            masterGrid.ClearSelection();
                            selectedNode = puzzleBox[puzzleBox.activeZ, 2, 0];
                            selectedQueue = null;
                            selectedNode.selected = true;

                        }
                        if (Keyboard.GetState().IsKeyDown(Keys.NumPad2))
                        {
                            puzzleBox.ClearSelection();
                            masterGrid.ClearSelection();
                            selectedNode = puzzleBox[puzzleBox.activeZ, 2, 1];
                            selectedQueue = null;
                            selectedNode.selected = true;
                        }
                        if (Keyboard.GetState().IsKeyDown(Keys.NumPad3))
                        {
                            puzzleBox.ClearSelection();
                            masterGrid.ClearSelection();
                            selectedNode = puzzleBox[puzzleBox.activeZ, 2, 2];
                            selectedQueue = null;
                            selectedNode.selected = true;
                        }
                        if (Keyboard.GetState().IsKeyDown(Keys.NumPad4))
                        {
                            puzzleBox.ClearSelection();
                            masterGrid.ClearSelection();
                            selectedNode = puzzleBox[puzzleBox.activeZ, 1, 0];
                            selectedQueue = null;
                            selectedNode.selected = true;
                        }
                        if (Keyboard.GetState().IsKeyDown(Keys.NumPad5))
                        {
                            puzzleBox.ClearSelection();
                            masterGrid.ClearSelection();
                            selectedNode = puzzleBox[puzzleBox.activeZ, 1, 1];
                            selectedQueue = null;
                            selectedNode.selected = true;
                        }
                        if (Keyboard.GetState().IsKeyDown(Keys.NumPad6))
                        {
                            puzzleBox.ClearSelection();
                            masterGrid.ClearSelection();
                            selectedNode = puzzleBox[puzzleBox.activeZ, 1, 2];
                            selectedQueue = null;
                            selectedNode.selected = true;
                        }
                        if (Keyboard.GetState().IsKeyDown(Keys.NumPad7))
                        {
                            puzzleBox.ClearSelection();
                            masterGrid.ClearSelection();
                            selectedNode = puzzleBox[puzzleBox.activeZ, 0, 0];
                            selectedQueue = null;
                            selectedNode.selected = true;
                        }
                        if (Keyboard.GetState().IsKeyDown(Keys.NumPad8))
                        {
                            puzzleBox.ClearSelection();
                            masterGrid.ClearSelection();
                            selectedNode = puzzleBox[puzzleBox.activeZ, 0, 1];
                            selectedQueue = null;
                            selectedNode.selected = true;
                        }
                        if (Keyboard.GetState().IsKeyDown(Keys.NumPad9))
                        {
                            puzzleBox.ClearSelection();
                            masterGrid.ClearSelection();
                            selectedNode = puzzleBox[puzzleBox.activeZ, 0, 2];
                            selectedQueue = null;
                            selectedNode.selected = true;
                        }

                        if (Keyboard.GetState().IsKeyDown(Keys.Insert))
                        {
                            puzzleBox.ClearSelection();
                            masterGrid.ClearSelection();
                            selectedNode = masterGrid[1, 0];
                            selectedQueue = masterGrid.queues[1, 0]; ;
                            selectedNode.selected = true;
                        }
                        if (Keyboard.GetState().IsKeyDown(Keys.Home))
                        {
                            puzzleBox.ClearSelection();
                            masterGrid.ClearSelection();
                            selectedNode = masterGrid[2, 0];
                            selectedQueue = masterGrid.queues[2, 0]; ;
                            selectedNode.selected = true;
                        }
                        if (Keyboard.GetState().IsKeyDown(Keys.PageUp))
                        {
                            puzzleBox.ClearSelection();
                            masterGrid.ClearSelection();
                            selectedNode = masterGrid[3, 0];
                            selectedQueue = masterGrid.queues[3, 0]; ;
                            selectedNode.selected = true;
                        }
                        if (Keyboard.GetState().IsKeyDown(Keys.Delete))
                        {
                            puzzleBox.ClearSelection();
                            masterGrid.ClearSelection();
                            selectedNode = masterGrid[1, 4];
                            selectedQueue = masterGrid.queues[1, 4]; ;
                            selectedNode.selected = true;
                        }
                        if (Keyboard.GetState().IsKeyDown(Keys.End))
                        {
                            puzzleBox.ClearSelection();
                            masterGrid.ClearSelection();
                            selectedNode = masterGrid[2, 4];
                            selectedQueue = masterGrid.queues[2, 4]; ;
                            selectedNode.selected = true;
                        }
                        if (Keyboard.GetState().IsKeyDown(Keys.PageDown))
                        {
                            puzzleBox.ClearSelection();
                            masterGrid.ClearSelection();
                            selectedNode = masterGrid[3, 4];
                            selectedQueue = masterGrid.queues[3, 4]; ;
                            selectedNode.selected = true;
                        }
                        if (Keyboard.GetState().IsKeyDown(Keys.OemCloseBrackets))
                        {
                            puzzleBox.ClearSelection();
                            masterGrid.ClearSelection();
                            selectedNode = masterGrid[4, 1];
                            selectedQueue = masterGrid.queues[4, 1];
                            selectedNode.selected = true;
                        }
                        if (Keyboard.GetState().IsKeyDown(Keys.OemQuotes))
                        {
                            puzzleBox.ClearSelection();
                            masterGrid.ClearSelection();
                            selectedNode = masterGrid[4, 2];
                            selectedQueue = masterGrid.queues[4, 2];
                            selectedNode.selected = true;
                        }
                        if (Keyboard.GetState().IsKeyDown(Keys.OemQuestion))
                        {
                            puzzleBox.ClearSelection();
                            masterGrid.ClearSelection();
                            selectedNode = masterGrid[4, 3];
                            selectedQueue = masterGrid.queues[4, 3];
                            selectedNode.selected = true;
                        }
                        if (Keyboard.GetState().IsKeyDown(Keys.OemOpenBrackets))
                        {
                            puzzleBox.ClearSelection();
                            masterGrid.ClearSelection();
                            selectedNode = masterGrid[0, 1];
                            selectedQueue = masterGrid.queues[0,1];
                            selectedNode.selected = true;
                        }
                        if (Keyboard.GetState().IsKeyDown(Keys.OemSemicolon))
                        {
                            puzzleBox.ClearSelection();
                            masterGrid.ClearSelection();
                            selectedNode = masterGrid[0, 2];
                            selectedQueue = masterGrid.queues[0, 2];
                            selectedNode.selected = true;
                        }
                        if (Keyboard.GetState().IsKeyDown(Keys.OemPeriod))
                        {
                            puzzleBox.ClearSelection();
                            masterGrid.ClearSelection();
                            selectedNode = masterGrid[0, 3];
                            selectedQueue = masterGrid.queues[0, 3];
                            selectedNode.selected = true;
                        }
                        if (Keyboard.GetState().IsKeyDown(Keys.M))
                        {
                            if (selectedQueue != null)
                            {
                                puzzleBox.ClearSelection();
                                masterGrid.ClearSelection();
                                selectedDepth++;
                                if (selectedDepth >= selectedQueue.Count)
                                    selectedDepth = selectedQueue.Count - 1;
                                selectedNode = selectedQueue[selectedDepth];
                                selectedNode.selected = true;
                                editorCooldown = 250;
                            }
                        }
                        if (Keyboard.GetState().IsKeyDown(Keys.N))
                        {
                            if (selectedQueue != null)
                            {
                                puzzleBox.ClearSelection();
                                masterGrid.ClearSelection();
                                selectedDepth--;
                                if (selectedDepth < 0) selectedDepth = 0;
                                selectedNode = selectedQueue[selectedDepth];
                                selectedNode.selected = true;
                                editorCooldown = 250;
                            }
                        }

                        if (Keyboard.GetState().IsKeyDown(Keys.R))
                        {
                            selectedNode.color = Color.Red;
                        }
                        if (Keyboard.GetState().IsKeyDown(Keys.G))
                        {
                            selectedNode.color = Color.Green;
                        }
                        if (Keyboard.GetState().IsKeyDown(Keys.B))
                        {
                            selectedNode.color = Game.jellyBlue;
                        }
                        if (Keyboard.GetState().IsKeyDown(Keys.Y))
                        {
                            selectedNode.color = Color.Yellow;
                        }
                        if (Keyboard.GetState().IsKeyDown(Keys.P))
                        {
                            selectedNode.color = Color.Magenta;
                        }
                        if (Keyboard.GetState().IsKeyDown(Keys.O))
                        {
                            selectedNode.color = Color.DarkOrange;
                        }
                        if (Keyboard.GetState().IsKeyDown(Keys.X))
                        {
                            selectedNode.color = Color.Gray;
                        }
                        if (Keyboard.GetState().IsKeyDown(Keys.F10))
                        {
                            LevelLoader.SaveLevel(puzzleBox, masterGrid);
                        }
                        if (Keyboard.GetState().IsKeyDown(Keys.F5))
                        {
                            mode = ControlMode.NORMAL;
                        }
                        if (Keyboard.GetState().IsKeyDown(Keys.F))
                        {
                            if (selectedNode.toggleOrb == false)
                            {
                                selectedNode.toggleColor = Color.Gray;
                            }
                            selectedNode.toggleOrb = true;
                        }

                        if (Keyboard.GetState().IsKeyDown(Keys.C))
                        {
                            if (selectedNode.moveCountdownOrb == false)
                            {
                                selectedNode.moveCountdownOrb = true;
                                selectedNode.countdown = 10;
                            }
                            else
                                selectedNode.moveCountdownOrb = false;
                        }
                        if(Keyboard.GetState().IsKeyDown(Keys.LeftShift)) {
                            if(Keyboard.GetState().IsKeyDown(Keys.F))
                            {
                                if (selectedNode.toggleOrb)
                                {
                                    Color temp = selectedNode.color;
                                    selectedNode.color = selectedNode.toggleColor;
                                    selectedNode.toggleColor = temp;
                                    editorCooldown = 250;
                                }
                            }
                        }

                        if (Keyboard.GetState().IsKeyDown(Keys.T))
                        {
                            if (selectedNode.timeCountdownOrb == false)
                            {
                                selectedNode.timeCountdownOrb = true;
                                selectedNode.countdown = 10000;
                            }
                            else
                                selectedNode.timeCountdownOrb = false;
                        }
                        if (Keyboard.GetState().IsKeyDown(Keys.OemPlus))
                        {
                            if(selectedNode.moveCountdownOrb)
                                selectedNode.countdown++;
                            if (selectedNode.timeCountdownOrb)
                                selectedNode.countdown += 1000;
                            editorCooldown = 250;
                        }
                        if (Keyboard.GetState().IsKeyDown(Keys.OemMinus))
                        {
                            if (selectedNode.moveCountdownOrb)
                                selectedNode.countdown--;
                            if (selectedNode.timeCountdownOrb)
                                selectedNode.countdown -= 1000;
                            editorCooldown = 250;
                        }
                    }

                }
            }

            // Update fragment animation positions
            for (int i = 0; i < fragmentList.Count; i++)
            {
                if (false == fragmentList[i].Update(gameTime))
                {
                    fragmentList.RemoveAt(i);
                }
            }
            // Update scoring animation positions
            for (int i = 0; i < scoreList.Count; i++)
            {
                if (false == scoreList[i].Update(gameTime))
                {
                    scoreList.RemoveAt(i);
                }
            }
            return GameStopCause.NONE;
        }
예제 #3
0
파일: Game.cs 프로젝트: kevincos/PuzzleBox
        protected override void Update(GameTime gameTime)
        {
            if (metaState == MetaState.InitialLoad)
            {
                splashScreen = new SplashScreen();
                metaState    = MetaState.SplashScreen;
            }

            // Controls
            //if (GamePad.GetState(Game.playerIndex).Buttons.Back == ButtonState.Pressed)
            //  this.Exit();
            if (HighScoreTracker.device != null && Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                HighScoreData data = HighScoreTracker.LoadHighScores();
                data.soundEffectsEnabled = gameSettings.soundEffectsEnabled;
                data.musicEnabled        = gameSettings.musicEnabled;
                data.displayHelp         = gameSettings.displayControls;
                data.wideScreen          = gameSettings.wideScreen;
                data.keyboardControls    = gameSettings.keyboardControls;
                HighScoreTracker.SaveHighScores(data);
                Logger.CloseLogger();
                this.Exit();
            }
            if (metaState == MetaState.SplashScreen)
            {
                if (MenuResult.GoToMainMenu == splashScreen.Update(gameTime))
                {
                    base.Initialize();
                    try
                    {
                        if (Guide.IsVisible == true)
                        {
                            splashScreen.stillActive = true;
                        }
                        else
                        {
                            StorageDevice.BeginShowSelector(this.GetDevice, "Select Storage Device");
                        }
                    }
                    catch
                    {
                        splashScreen.stillActive = true;
                    }
                }
            }
            if (HighScoreTracker.device != null && HighScoreTracker.device.IsConnected == true)
            {
                showRetry = false;
            }
            if (backToRetry == true || (HighScoreTracker.device != null && showRetry == false && HighScoreTracker.device.IsConnected == false))
            {
                if (Guide.IsVisible == false)
                {
                    try
                    {
                        StorageDevice.BeginShowSelector(this.RetryDevice, "Select Storage Device");
                        backToRetry = false;
                        showRetry   = true;
                    }
                    catch
                    {
                    }
                }
            }
            if (metaState == MetaState.SplashScreen && deviceSelected == true)
            {
                HighScoreData data = HighScoreTracker.LoadHighScores();
                gameSettings = new GameSettings();
                gameSettings.displayControls     = data.displayHelp;
                gameSettings.musicEnabled        = data.musicEnabled;
                gameSettings.soundEffectsEnabled = data.soundEffectsEnabled;
                gameSettings.fullScreen          = data.fullScreen;
                gameSettings.wideScreen          = data.wideScreen;
                gameSettings.keyboardControls    = data.keyboardControls;
                currentSettings  = new Settings();
                p1engine         = new Engine(-1);
                mainMenu         = new MainMenu();
                pauseMenu        = new PauseMenu();
                summaryMenu      = new SummaryMenu(false);
                gameOverMenu     = new GameOverMenu();
                selectMenu       = new LevelSelectMenu();
                tutorialLauncher = new TutorialLauncher();
                settingsMenu     = new Menu(MenuClass.SettingsMenu);

                currentSettings  = new Settings();
                p1engine         = new Engine(-1);
                mainMenu         = new MainMenu();
                pauseMenu        = new PauseMenu();
                summaryMenu      = new SummaryMenu(false);
                gameOverMenu     = new GameOverMenu();
                selectMenu       = new LevelSelectMenu();
                tutorialLauncher = new TutorialLauncher();
                settingsMenu     = new Menu(MenuClass.SettingsMenu);

                if (Guide.IsTrialMode)
                {
                    mainMenu.AddMenuItem(MenuResult.GoToTutorial, "Tutorial", "Learn to play Jellyfish, MD");
                }
                mainMenu.AddMenuItem(MenuResult.GoToTimeAttack, "Emergency Room", "Score as many points as you can within the \ntime limit.");
                mainMenu.AddMenuItem(MenuResult.GoToMoveChallenge, "Operation", "Score as many points as you can with a \nlimited number of moves.");
                mainMenu.AddMenuItem(MenuResult.GoToPuzzle, "Challenge", "Solve a series of unique challenges.");
                if (Guide.IsTrialMode == false)
                {
                    mainMenu.AddMenuItem(MenuResult.GoToTutorial, "Tutorial", "Learn to play Jellyfish, MD");
                }
                mainMenu.AddMenuItem(MenuResult.BuyFullGame, "Unlock Full Game", "Purchase the full version of Jellyfish, MD");
                mainMenu.AddMenuItem(MenuResult.GoToJellyfishCity, "Jellyfish Parade", "Check in on your former patients!");
                mainMenu.AddMenuItem(MenuResult.GoToSettings, "Settings", "Change settings for Jellyfish, MD");
                mainMenu.AddMenuItem(MenuResult.Quit, "Quit", "Quit Jellyfish, MD??");
                gameOverMenu.AddMenuItem(MenuResult.StartTimeAttack, "Replay");
                gameOverMenu.AddMenuItem(MenuResult.GoToMainMenu, "Main Menu");
                gameOverMenu.AddMenuItem(MenuResult.GoToLevelSelect, "Level Select");
                settingsMenu.AddMenuItem(MenuResult.GoToMainMenu, "Return to Menu");
                settingsMenu.AddMenuItem(MenuType.SoundToggle, "Sound Effects");
                settingsMenu.AddMenuItem(MenuType.MusicToggle, "Music");
                settingsMenu.AddMenuItem(MenuType.HelpToggle, "Help Overlay");

                #if WINDOWS
                settingsMenu.AddMenuItem(MenuType.FullScreenToggle, "Full Screen");
                settingsMenu.AddMenuItem(MenuType.WideScreenToggle, "Wide Screen");
                #endif
                UpdateResolution();

                metaState = MetaState.MainMenu;
            }
            if (metaState == MetaState.GamePlay && IsActive == true)
            {
                GameStopCause cause = p1engine.Update(gameTime);
                if (cause == GameStopCause.PAUSE)
                {
                    pauseMenu = new PauseMenu();
                    metaState = MetaState.Paused;
                }
                if (cause == GameStopCause.END)
                {
                    gameOverMenu.score = p1engine.currentScore;
                    gameOverMenu.level = currentSettings.level;
                    gameOverMenu.state = GameOverMenuState.SCORECHECK;
                    summaryMenu        = new SummaryMenu(true);
                    if (currentSettings.mode == GameMode.MoveChallenge)
                    {
                        summaryMenu.text = "Looks like you're out of moves, Doctor! \nLet's see how you did...";
                    }
                    if (currentSettings.mode == GameMode.TimeAttack)
                    {
                        summaryMenu.text = "Time's up, Doctor! Let's see \nhow you did...";
                    }
                    MusicControl.PlayMenuMusic();
                    metaState = MetaState.Summary;
                }
                if (cause == GameStopCause.WIN)
                {
                    gameOverMenu.score = Engine.clock.timeElapsed;
                    gameOverMenu.level = currentSettings.level;
                    gameOverMenu.state = GameOverMenuState.SCORECHECK;
                    summaryMenu        = new SummaryMenu(true);
                    summaryMenu.text   = "Way to go, Doctor! You did it!";
                    metaState          = MetaState.Summary;
                    MusicControl.PlayMenuMusic();
                }
                if (cause == GameStopCause.TUTORIAL_TEXT)
                {
                    TutorialStage.phase = TutorialPhase.Intro;
                    summaryMenu         = new SummaryMenu(true);
                    summaryMenu.text    = TutorialStage.IntroText();
                    if (summaryMenu.text == null)
                    {
                        metaState = MetaState.GamePlay;
                    }
                    summaryMenu.state = SummaryMenuState.READY;

                    metaState = MetaState.Summary;
                }
                if (cause == GameStopCause.TUTORIAL_PASS)
                {
                    TutorialStage.phase = TutorialPhase.Pass;
                    String text = TutorialStage.SuccessText();
                    summaryMenu      = new SummaryMenu(true);
                    summaryMenu.text = text;
                    metaState        = MetaState.Summary;
                }
                if (cause == GameStopCause.TUTORIAL_FAIL)
                {
                    TutorialStage.phase = TutorialPhase.Fail;
                    String text = TutorialStage.FailureText();
                    summaryMenu      = new SummaryMenu(false);
                    summaryMenu.text = text;
                    metaState        = MetaState.Summary;
                }
                if (cause == GameStopCause.LOSE_STUCK)
                {
                    summaryMenu        = new SummaryMenu(false);
                    summaryMenu.text   = "Oh no! Looks like you're stuck! Try to be more \ncareful next time!";
                    gameOverMenu.state = GameOverMenuState.READY;
                    metaState          = MetaState.Summary;
                }
                if (cause == GameStopCause.LOSE_ERROR)
                {
                    summaryMenu        = new SummaryMenu(false);
                    summaryMenu.text   = "Oh no! You burst a " + currentSettings.dangerColorDisplay + " bubble! Try to be more \ncareful next time!";
                    gameOverMenu.state = GameOverMenuState.READY;
                    metaState          = MetaState.Summary;
                }
            }
            else if (metaState == MetaState.Paused)
            {
                MenuResult result = pauseMenu.Update(gameTime);
                if (result == MenuResult.GoToMainMenu)
                {
                    TutorialStage.phase = TutorialPhase.None;
                    metaState           = MetaState.MainMenu;
                }
                if (result == MenuResult.ResumeGame)
                {
                    summaryMenu.state = SummaryMenuState.NURSEIN;
                    metaState         = MetaState.GamePlay;
                }
                if (result == MenuResult.GoToLevelSelect)
                {
                    MusicControl.PlayMenuMusic();
                    if (currentSettings.mode == GameMode.TimeAttack)
                    {
                        metaState = MetaState.Settings_TimeAttack;
                    }
                    if (currentSettings.mode == GameMode.Puzzle)
                    {
                        metaState = MetaState.Settings_Puzzle;
                    }
                    if (currentSettings.mode == GameMode.MoveChallenge)
                    {
                        metaState = MetaState.Settings_Move;
                    }
                }
                if (result == MenuResult.Replay)
                {
                    p1engine  = new Engine(-1);
                    metaState = MetaState.GamePlay;
                }
            }
            else if (metaState == MetaState.Summary)
            {
                if (Game.currentSettings.mode == GameMode.Puzzle && gameOverMenu.state != GameOverMenuState.SCORECHECK)
                {
                    Engine.clock.Update(gameTime);
                }
                MenuResult result = summaryMenu.Update(gameTime);
                if (TutorialStage.phase != TutorialPhase.None && TutorialStage.introIndex - 1 == TutorialStage.controlLessonIndex)
                {
                    p1engine.Update(gameTime);
                }
                if (result == MenuResult.GoToMainMenu)
                {
                    TutorialStage.phase = TutorialPhase.None;
                    metaState           = MetaState.MainMenu;
                }
                if (result == MenuResult.Replay)
                {
                    if (TutorialStage.phase == TutorialPhase.Fail)
                    {
                        p1engine.LoadTutorial(TutorialStage.lessonIndex);
                        TutorialStage.phase        = TutorialPhase.Intro;
                        TutorialStage.failureIndex = 0;
                        TutorialStage.introIndex   = 0;
                        TutorialStage.successIndex = 0;
                        p1engine.firstResume       = true;
                        metaState = MetaState.GamePlay;
                    }
                    else if (TutorialStage.phase == TutorialPhase.Pass)
                    {
                        p1engine.LoadTutorial(TutorialStage.lessonIndex);
                        TutorialStage.phase        = TutorialPhase.Intro;
                        TutorialStage.failureIndex = 0;
                        TutorialStage.introIndex   = 0;
                        TutorialStage.successIndex = 0;
                        p1engine.firstResume       = false;
                        metaState = MetaState.GamePlay;
                    }
                    else
                    {
                        p1engine = new Engine(-1);
                        MusicControl.PlayGameMusic();
                        metaState = MetaState.GamePlay;
                    }
                }
                if (result == MenuResult.Undo)
                {
                    p1engine.Back();
                    metaState = MetaState.GamePlay;
                }
                if (result == MenuResult.GoToResults)
                {
                    if (currentSettings.mode == GameMode.Tutorial)
                    {
                        if (TutorialStage.phase == TutorialPhase.Intro)
                        {
                            metaState = MetaState.GamePlay;
                        }
                        else if (TutorialStage.phase == TutorialPhase.Pass)
                        {
                            TutorialStage.lessonIndex++;
                            if (TutorialStage.lessonIndex == TutorialStage.maxLesson)
                            {
                                TutorialStage.phase = TutorialPhase.None;
                                summaryMenu         = new SummaryMenu(false);
                                metaState           = MetaState.MainMenu;
                            }
                            else
                            {
                                //p1engine = new Engine(TutorialStage.lessonIndex);
                                p1engine.LoadTutorial(TutorialStage.lessonIndex);
                                p1engine.firstResume = true;
                                //p1engine.gameState = State.VANISH;
                                TutorialStage.phase = TutorialPhase.Intro;
                                metaState           = MetaState.GamePlay;
                            }
                        }
                        else
                        {
                        }
                    }
                    else
                    {
                        metaState = MetaState.GameOver_TimeAttack;
                    }
                }
                if (result == MenuResult.GoToLevelSelect)
                {
                    MusicControl.PlayMenuMusic();
                    if (currentSettings.mode == GameMode.TimeAttack)
                    {
                        metaState = MetaState.Settings_TimeAttack;
                    }
                    if (currentSettings.mode == GameMode.Puzzle)
                    {
                        metaState = MetaState.Settings_Puzzle;
                    }
                    if (currentSettings.mode == GameMode.MoveChallenge)
                    {
                        metaState = MetaState.Settings_Move;
                    }
                }
            }
            else if (metaState == MetaState.Settings_TimeAttack || metaState == MetaState.Settings_Puzzle || metaState == MetaState.Settings_Move)
            {
                MenuResult result = selectMenu.Update(gameTime);
                if (result == MenuResult.GoToMainMenu)
                {
                    System.Threading.Thread.Sleep(100);
                    metaState = MetaState.MainMenu;
                }
                if (result == MenuResult.StartTimeAttack)
                {
                    currentSettings       = selectMenu.GetCurrentSettings();
                    currentSettings.level = selectMenu.currentLevel;
                    p1engine = new Engine(-1);
                    MusicControl.PlayGameMusic();
                    metaState = MetaState.GamePlay;
                }
            }
            else if (metaState == MetaState.GameOver_TimeAttack)
            {
                if (Engine.mode == ControlMode.AUTOMATED)
                {
                    p1engine  = new Engine(-1);
                    metaState = MetaState.GamePlay;
                }
                else
                {
                    MenuResult result = gameOverMenu.Update(gameTime);
                    if (result == MenuResult.GoToMainMenu)
                    {
                        metaState = MetaState.MainMenu;
                        System.Threading.Thread.Sleep(100);
                    }
                    if (result == MenuResult.GoToLevelSelect)
                    {
                        selectMenu       = new LevelSelectMenu();
                        selectMenu.state = LevelSelectMenu.SelectMenuState.LOAD;

                        if (currentSettings.mode == GameMode.MoveChallenge)
                        {
                            metaState               = MetaState.Settings_Move;
                            selectMenu.cooldown     = 250;
                            selectMenu.currentLevel = gameSettings.moveChallengeViewLevel;
                            selectMenu.levelList    = SettingsLoader.LoadMoveCountLevels();
                            currentSettings.mode    = GameMode.MoveChallenge;
                        }
                        if (currentSettings.mode == GameMode.TimeAttack)
                        {
                            metaState               = MetaState.Settings_TimeAttack;
                            selectMenu.cooldown     = 250;
                            selectMenu.currentLevel = gameSettings.timeAttackViewLevel;
                            selectMenu.levelList    = SettingsLoader.LoadTimeAttackLevels();
                            currentSettings.mode    = GameMode.TimeAttack;
                        }
                        if (currentSettings.mode == GameMode.Puzzle)
                        {
                            metaState               = MetaState.Settings_Puzzle;
                            selectMenu.cooldown     = 250;
                            selectMenu.levelList    = SettingsLoader.LoadPuzzleLevels();
                            selectMenu.currentLevel = gameSettings.puzzleViewLevel;
                            currentSettings.mode    = GameMode.Puzzle;
                        }
                    }
                    if (result == MenuResult.StartTimeAttack)
                    {
                        p1engine = new Engine(-1);
                        MusicControl.PlayGameMusic();
                        metaState = MetaState.GamePlay;
                    }
                }
            }
            else if (metaState == MetaState.Settings)
            {
                MenuResult result = settingsMenu.Update(gameTime);
                if (result == MenuResult.GoToMainMenu)
                {
                    metaState = MetaState.MainMenu;
                }
            }
            else if (metaState == MetaState.JellyfishCity)
            {
                MenuResult result = jellyCity.Update(gameTime);
                if (result == MenuResult.GoToMainMenu)
                {
                    metaState = MetaState.MainMenu;
                }
            }
            else if (metaState == MetaState.Tutorial)
            {
                MenuResult result = tutorialLauncher.Update(gameTime);
                if (result == MenuResult.StartTutorial)
                {
                    summaryMenu.state    = SummaryMenuState.READY;
                    currentSettings      = SettingsLoader.Tutorial();
                    p1engine             = new Engine(0);
                    p1engine.firstResume = true;
                    metaState            = MetaState.GamePlay;
                }
            }
            else if (metaState == MetaState.MainMenu)
            {
                MenuResult result = mainMenu.Update(gameTime);
                if (result == MenuResult.ReturnToSplashScreen)
                {
                    HighScoreData data = HighScoreTracker.LoadHighScores();
                    data.soundEffectsEnabled = gameSettings.soundEffectsEnabled;
                    data.musicEnabled        = gameSettings.musicEnabled;
                    data.displayHelp         = gameSettings.displayControls;
                    data.fullScreen          = gameSettings.fullScreen;
                    data.wideScreen          = gameSettings.wideScreen;
                    data.keyboardControls    = gameSettings.keyboardControls;
                    HighScoreTracker.SaveHighScores(data);

                    deviceSelected          = false;
                    HighScoreTracker.device = null;
                    if (HighScoreTracker.container != null)
                    {
                        HighScoreTracker.container.Dispose();
                    }
                    HighScoreTracker.container  = null;
                    HighScoreTracker.cachedData = null;
                    splashScreen = new SplashScreen();
                    metaState    = MetaState.SplashScreen;
                }
                if (result == MenuResult.BuyFullGame)
                {
                    try { Guide.ShowMarketplace(Game.playerIndex); }
                    catch (GamerPrivilegeException)
                    {
                        Guide.BeginShowMessageBox("Oops!",
                                                  "The current controller is either not signed in or is unable to purchase games on XBox Live.",
                                                  new string[] { "OK" },
                                                  0, MessageBoxIcon.None, null, null);
                    }
                    catch
                    {
                    }
                }
                if (result == MenuResult.GoToSettings)
                {
                    metaState = MetaState.Settings;
                }
                if (result == MenuResult.GoToTimeAttack)
                {
                    metaState               = MetaState.Settings_TimeAttack;
                    selectMenu              = new LevelSelectMenu();
                    selectMenu.levelList    = SettingsLoader.LoadTimeAttackLevels();
                    selectMenu.currentLevel = gameSettings.timeAttackViewLevel;
                    selectMenu.state        = LevelSelectMenu.SelectMenuState.LOAD;
                    currentSettings.mode    = GameMode.TimeAttack;
                    System.Threading.Thread.Sleep(100);
                }
                if (result == MenuResult.GoToPuzzle)
                {
                    metaState               = MetaState.Settings_Puzzle;
                    selectMenu              = new LevelSelectMenu();
                    selectMenu.levelList    = SettingsLoader.LoadPuzzleLevels();
                    selectMenu.state        = LevelSelectMenu.SelectMenuState.LOAD;
                    selectMenu.currentLevel = gameSettings.puzzleViewLevel;
                    currentSettings.mode    = GameMode.Puzzle;
                    System.Threading.Thread.Sleep(100);
                }
                if (result == MenuResult.GoToJellyfishCity)
                {
                    metaState = MetaState.JellyfishCity;
                    jellyCity = new JellyfishCity();
                }
                if (result == MenuResult.GoToTutorial)
                {
                    metaState                 = MetaState.Tutorial;
                    TutorialStage.phase       = TutorialPhase.Intro;
                    TutorialStage.lessonIndex = 0;
                    TutorialStage.loaded      = false;
                    tutorialLauncher          = new TutorialLauncher();
                }
                if (result == MenuResult.GoToMoveChallenge)
                {
                    metaState               = MetaState.Settings_Move;
                    selectMenu              = new LevelSelectMenu();
                    selectMenu.levelList    = SettingsLoader.LoadMoveCountLevels();
                    selectMenu.state        = LevelSelectMenu.SelectMenuState.LOAD;
                    selectMenu.currentLevel = gameSettings.moveChallengeViewLevel;
                    currentSettings.mode    = GameMode.TimeAttack;
                }
                if (result == MenuResult.StartCollect)
                {
                    p1engine  = new Engine(-1);
                    metaState = MetaState.GamePlay;
                }
                if (result == MenuResult.StartPuzzle)
                {
                    p1engine = new Engine(-1);

                    metaState = MetaState.GamePlay;
                }
                if (result == MenuResult.GoToSurvival)
                {
                    metaState = MetaState.GamePlay;
                }
                if (result == MenuResult.Quit)
                {
                    HighScoreData data = HighScoreTracker.LoadHighScores();
                    data.soundEffectsEnabled = gameSettings.soundEffectsEnabled;
                    data.musicEnabled        = gameSettings.musicEnabled;
                    data.displayHelp         = gameSettings.displayControls;
                    data.fullScreen          = gameSettings.fullScreen;
                    data.wideScreen          = gameSettings.wideScreen;
                    data.keyboardControls    = gameSettings.keyboardControls;
                    HighScoreTracker.SaveHighScores(data);
                    Logger.CloseLogger();
                    this.Exit();
                }
            }

            base.Update(gameTime);
        }