/// <summary>Pushes the specified state onto the state stack</summary> /// <param name="state">State that will be pushed onto the stack</param> public void Push(GameState state) { if(this.activeGameStates.Count > 0) { // Pause the state the was previously active this.activeGameStates.Peek().InternalPause(); } try { this.activeGameStates.Push(state); // Push the new state onto the stack and notify it that it has become active try { state.InternalEntered(); } catch(Exception) { this.activeGameStates.Pop(); throw; } } catch(Exception) { if(this.activeGameStates.Count > 0) { this.activeGameStates.Peek().InternalResume(); } throw; } }
/// <summary>Switches the game to the specified state</summary> /// <param name="state">State the game will be switched to</param> /// <remarks> /// This replaces the running game state in the stack with the specified state. /// </remarks> public void Switch(GameState state) { GameState topMostGameState; if(this.activeGameStates.Count > 0) { topMostGameState = this.activeGameStates.Peek(); // If something goes wrong here, the stack is still in order topMostGameState.InternalLeaving(); this.activeGameStates.Pop(); } else { topMostGameState = null; } try { Push(state); } catch(Exception) { if(topMostGameState != null) { topMostGameState.InternalEntered(); this.activeGameStates.Push(topMostGameState); } throw; } }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> public override void Update(GameTime gameTime) { // Allows the game to exit //if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) // this.Exit(); //// TODO: Add your update logic here clock += gameTime.ElapsedGameTime; if (clock.TotalSeconds >= 20) { NextPlayer(); } if (currentPlayer.PeerId == Game1.main_console.PeerId) { ProcessKeyboard(); } if (rocketFlying) { UpdateRocket(); CheckCollisions(gameTime); } MouseState mouseState; switch (gamestate) { case GameState.Play: if (teamA.FindIndex(fpeer => fpeer.IsAlive == true) == -1 || teamB.FindIndex(fpeer => fpeer.IsAlive == true) == -1) { gamestate = GameState.GameOver; } break; case GameState.GameOver: mouseState = Mouse.GetState(); System.Console.WriteLine("pencet" + mouseState.X + ", " + mouseState.Y); if (mouseState.X > 300 && mouseState.X < 500 && mouseState.Y < 400 && mouseState.Y > 250 && mouseState.LeftButton == ButtonState.Pressed && prev.LeftButton == ButtonState.Released) { //gamestate = GameState.BackToRoom; Game1.main_console.Room.Reset(); DrawableGameState state = new RoomState(previousState, gameStateService, guiService, inputService, graphics, Content); gameStateService.Switch(state); } break; case GameState.BackToRoom: break; } prev = Mouse.GetState(); //if(clock%20 == 0) //{ // Game1.main_console.GameEvent += ProcessMessages; // if (clock == 480) // { // clock = 1; // } //} }