Guest User

Untitled

a guest
Jan 22nd, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.76 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Microsoft.Xna.Framework;
  5. using Microsoft.Xna.Framework.Audio;
  6. using Microsoft.Xna.Framework.Content;
  7. using Microsoft.Xna.Framework.GamerServices;
  8. using Microsoft.Xna.Framework.Graphics;
  9. using Microsoft.Xna.Framework.Input;
  10. using Microsoft.Xna.Framework.Media;
  11.  
  12. namespace GameStates
  13. {
  14.     class StateManager
  15.     {
  16.  
  17.         private List<GameState> gamestates = new List<GameState>();
  18.  
  19.         public void addState(ContentManager theContentManager, GameState newstate, string title, StateManager tempmanager)
  20.         {
  21.             newstate.Init(title, tempmanager);
  22.             newstate.loadContent(theContentManager);
  23.             gamestates.Add(newstate);
  24.          
  25.         }
  26.  
  27.         public void changeState(string title)
  28.         {
  29.             foreach (GameState state in gamestates)
  30.             {
  31.                 if (state.getActive())
  32.                 {
  33.                     state.toggleActive();
  34.                 }
  35.                 if (title.Equals(state.getTitle()))
  36.                 {
  37.                     state.toggleActive();
  38.                 }
  39.             }
  40.         }
  41.  
  42.         public void active(SpriteBatch spritebatch)
  43.         {
  44.             foreach (GameState state in gamestates)
  45.             {
  46.                 if (state.getActive())
  47.                 {
  48.                     state.Update();
  49.                     state.Draw(spritebatch);
  50.                 }
  51.             }
  52.         }
  53.  
  54.         public GameState getActive()
  55.         {
  56.             foreach (GameState state in gamestates)
  57.             {
  58.                 if (state.getActive())
  59.                 {
  60.                     return state;
  61.                 }
  62.             }
  63.             return null;
  64.         }
  65.     }
  66. }
Add Comment
Please, Sign In to add comment