Пример #1
0
        private ButtonControl joinButton, helpButton, quitButton; // the buttons

        public MainMenu(Game game, GameStateManager gameStateManager, GuiManager gui, InputManager input)
            : base(gameStateManager)
        {
            // load textures
            // this can probably go in OnEntered()
            bg = game.Content.Load<Texture2D>("textures/menu/greentank");

            // stays in constructor
            this.gameStateManager = gameStateManager;
            this.game = game;
            this.gui = gui;
            this.input = input;

            // the following code can probably go in OnEntered() as well
            graphicsDevice = game.GraphicsDevice;
            spriteBatch = new SpriteBatch(graphicsDevice);
            
            Viewport viewport = game.GraphicsDevice.Viewport;
            mainMenuScreen = new Screen(viewport.Width, viewport.Height);

            gui.Screen = mainMenuScreen;
            mainMenuScreen.Desktop.Bounds = new UniRectangle(new UniScalar(0.0f, 0.0f), new UniScalar(0.0f, 0.0f),
                                                        new UniScalar(1.0f, 0.0f), new UniScalar(1.0f, 0.0f));
            InitializeComponents();

            joinButton.Pressed += new EventHandler(joinButton_Pressed);
            helpButton.Pressed += new EventHandler(helpButton_Pressed);
            quitButton.Pressed += new EventHandler(quitButton_Pressed);
        }
Пример #2
0
        public TetrisClone()
        {
            Graphics = new GraphicsDeviceManager(this) {PreferredBackBufferWidth = 640, PreferredBackBufferHeight = 800};

            Content.RootDirectory = "Content";

            StateManager = new GameStateManager(Services);

            Components.Add(new InputHandler(this));
        }
Пример #3
0
        public FusionGame()
        {
            Graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";

            Graphics.PreferredBackBufferWidth = 1024;
            Graphics.PreferredBackBufferHeight = 768;

            _gsm = new GameStateManager();

            Input = new InputManager(Services);
        }
Пример #4
0
        /// <summary>
        /// Creates a new Director instance using the specified Game.
        /// </summary>
        /// <param name="game">Game instance for the Director to use.</param>
        /// <param name="preferredResolution">Preferred resolution for game graphics.</param>
        /// <remarks>Protected to prevent instantiating Director instances outside of the static SharedDirector property.</remarks>
        protected Director(Game game, Vector2 preferredResolution)
            : base(game)
        {
            if (preferredResolution == null)
            {
                throw new ArgumentNullException("defaultResolution");
            }

            PreferredResolution = preferredResolution;
            DisplaySize = preferredResolution;
            DisplayCenter = new Vector2(DisplaySize.X / 2.0f, DisplaySize.Y / 2.0f);
            ResolutionIndependent = false;
            TransformationMatrix = new Matrix();

            EntityWorld = new EntityWorld(game);
            RenderSystem renderSystem = EntityWorld.SystemManager.SetSystem<RenderSystem>(new RenderSystem(), SystemExecutionType.Draw);
            AnimationSystem animationSystem = EntityWorld.SystemManager.SetSystem<AnimationSystem>(new AnimationSystem(), SystemExecutionType.Update);
            MovementSystem movementSystem = EntityWorld.SystemManager.SetSystem<MovementSystem>(new MovementSystem(), SystemExecutionType.Update);
            ControlSystem controlSystem = EntityWorld.SystemManager.SetSystem<ControlSystem>(new ControlSystem(), SystemExecutionType.Update);

            MessageBoard = new MessageBoard(game);
            GameStateManager = new GameStateManager(game.Services);
            InputManager = new InputManager(game.Services);
            InputBindingManager = new InputBindingManager(game);
            TextureManager = new TextureManager(game.Content);
            FontManager = new FontManager(game.Content);
            GuiManager = new GuiManager(game.Services);

            game.Components.Add(EntityWorld);
            game.Components.Add(MessageBoard);
            game.Components.Add(InputManager);
            game.Components.Add(InputBindingManager);

            game.Services.AddService(typeof(IEntityWorld), EntityWorld);
            game.Services.AddService(typeof(IMessageBoard), MessageBoard);
            game.Services.AddService(typeof(IInputBindingManager), InputBindingManager);
            game.Services.AddService(typeof(ITextureManager), TextureManager);
            game.Services.AddService(typeof(IFontManager), FontManager);
            #if DEBUG
            DebugDisplay = new DebugDisplay(game);
            game.Components.Add(DebugDisplay);
            game.Services.AddService(typeof(IDebugDisplay), DebugDisplay);
            #endif
        }
Пример #5
0
        public AngryTanks()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";

            // increase update rate to 120 Hz
            IsFixedTimeStep = true;
            TargetElapsedTime = new TimeSpan(0, 0, 0, 0, (int)(1000 / 120));

            // instantiate server link
            serverLink = new ServerLink();

            // get GameStateManager up and running
            gameStateManager = new GameStateManager(Services);
            Components.Add(gameStateManager);
            gameStateManager.UpdateOrder = 200;
            gameStateManager.DrawOrder = 200;

            // down with xna's input!
            input = new InputManager(Services, Window.Handle);
            Components.Add(input);
            input.UpdateOrder = 100;

            input.GetKeyboard().KeyPressed += HandleKeyPress;

            // instantiate world
            world = new World(Services, serverLink);
            world.UpdateOrder = 500;
            world.DrawOrder = 500;
            Components.Add(world);

            // instantiate game console
            gameConsole = new GameConsole(this, new Vector2(0, 400), new Vector2(800, 200),
                                          new Vector2(10, 10), new Vector2(10, 10), new Color(255, 255, 255, 100));
            Components.Add(gameConsole);
            gameConsole.UpdateOrder = 1000;
            gameConsole.DrawOrder = 1000;

            gameConsole.PromptReceivedInput += HandlePromptInput;
            
            // instantiate  AudioManager 
            audioManager = new AudioManager(this);

        }
Пример #6
0
        public Game1()
        {
            this.graphics = new GraphicsDeviceManager(this);
            this.input = new InputManager(Services, Window.Handle);
            this.gui = new GuiManager(Services);
            this.manager = new GameStateManager(Services);

            Components.Add(this.input);
            Components.Add(this.gui);
            this.gui.DrawOrder = 1000;
            Components.Add(this.manager);

            IsMouseVisible = true;
            quit = false;
            music = null;
            cursorTrigger = false;

            Content.RootDirectory = "Content";
            Window.Title = "GunBond";
            MediaPlayer.IsRepeating = true;
        }
Пример #7
0
        public JoinMenu(Game game, GameStateManager gameStateManager, GuiManager gui, InputManager input)
            : base(gameStateManager)
        {
            this.game = game;
            this.gameStateManager = gameStateManager;
            this.gameService = new GameServiceContainer();
            this.gui = gui;
            this.input = input;

            spriteBatch = new SpriteBatch(game.GraphicsDevice);
            bg = game.Content.Load<Texture2D>("textures/menu/ScoutTank");
            
            Viewport viewport = game.GraphicsDevice.Viewport;
            joinScreen = new Screen(viewport.Width, viewport.Height);
            gui.Screen = joinScreen;

            joinScreen.Desktop.Bounds = new UniRectangle(new UniScalar(0.0f, 0.0f), new UniScalar(0.0f, 0.0f),
                                                        new UniScalar(1.0f, 0.0f), new UniScalar(1.0f, 0.0f));
            InitializeComponents();

            joinButton.Pressed += new EventHandler(joinButton_Pressed);
            backButton.Pressed += new EventHandler(backButton_Pressed);
        }
Пример #8
0
 /// <summary>Initializes a new test game state</summary>
 /// <param name="manager">
 ///   Game state manager the test game state belongs to
 /// </param>
 public TestGameState(GameStateManager manager) :
     base(manager)
 {
 }
 /// <summary>Initializes a new test game state</summary>
 /// <param name="manager">
 ///   Game state manager the test game state belongs to
 /// </param>
 public TestGameState(GameStateManager manager) : base(manager) { }
    public void TestReeantrantPush() {
      GameStateManager manager = new GameStateManager(new GameServiceContainer());
      ReentrantGameState test = new ReentrantGameState(manager);
      
      manager.Push(test);

      // The reentrant game state pushes another game state onto the stack in its
      // OnEntered() notification. If this causes the stack to be built in the wrong
      // order, the ReentrantGameState would become the new active game state instead
      // of the sub-game-state it pushed onto the stack.
      Assert.AreNotSame(test, manager.ActiveState);
    }
    public void TestActiveState() {
      GameStateManager manager = new GameStateManager(new GameServiceContainer());

      Assert.IsNull(manager.ActiveState);
      
      TestGameState test = new TestGameState(manager);
      manager.Push(test);

      Assert.AreSame(test, manager.ActiveState);
    }
    public void TestPopToUnresumableState() {
      GameStateManager manager = new GameStateManager(new GameServiceContainer());
      TestGameState test = new TestGameState(manager);

      manager.Push(new UnresumableGameState(manager));
      manager.Push(test);

      Assert.Throws<InvalidOperationException>(
        delegate() { manager.Pop(); }
      );

      Assert.AreEqual(test.OnPauseCallCount, test.OnResumeCallCount);
      Assert.AreEqual(test.OnLeavingCallCount + 1, test.OnEnteredCallCount);
    }
Пример #13
0
    public void TestPauseResume() {
      GameStateManager manager = new GameStateManager(new GameServiceContainer());
      TestGameState gameState = new TestGameState(manager);
      manager.Push(gameState);

      Assert.AreEqual(0, gameState.OnPauseCallCount);
      manager.Push(new TestGameState(manager));
      Assert.AreEqual(1, gameState.OnPauseCallCount);

      Assert.AreEqual(0, gameState.OnResumeCallCount);
      manager.Pop();
      Assert.AreEqual(1, gameState.OnResumeCallCount);
    }
Пример #14
0
    /// <summary>Initializes a new game state</summary>
    /// <param name="gameStateManager">Game state manager the game state belongs to</param>
    public GameState(GameStateManager gameStateManager) :
      base(gameStateManager.InternalGameServices) {

      this.gameStateManager = gameStateManager;
    }
Пример #15
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            viewport = GraphicsDevice.Viewport;
            Screen defaultScreen = new Screen(viewport.Width, viewport.Height);
            gui.Screen = defaultScreen;

            gameStateManager = new GameStateManager(new GameServiceContainer());
            gameStateManager.Push(new MainMenu(this, gameStateManager, gui, Input));

            base.Initialize();
        }
 public void TestConstructor() {
   GameStateManager manager = new GameStateManager(new GameServiceContainer());
 }
 /// <summary>Initializes a new unresumable game state</summary>
 /// <param name="manager">
 ///   Game state manager the unresumable game state belongs to
 /// </param>
 public ReentrantGameState(GameStateManager manager) : base(manager) { }
 /// <summary>Initializes a new unresumable game state</summary>
 /// <param name="manager">
 ///   Game state manager the unresumable game state belongs to
 /// </param>
 public UnresumableGameState(GameStateManager manager) : base(manager) { }
 /// <summary>Initializes a new unenterable game state</summary>
 /// <param name="manager">
 ///   Game state manager the unenterable game state belongs to
 /// </param>
 public UnenterableGameState(GameStateManager manager) : base(manager) { }
Пример #20
0
 /// <summary>Initializes a new loading screen game state</summary>
 /// <param name="gameStateManager">
 ///   Game state manager the loading screen state belongs to
 /// </param>
 /// <param name="gameStateToLoad">
 ///   Game state that will be loaded by the loading screen
 /// </param>
 public TestLoadingScreenState(
     GameStateManager gameStateManager, TestGameState gameStateToLoad
     ) :
     base(gameStateManager, gameStateToLoad)
 {
 }
Пример #21
0
    public void TestDrawPropagation() {
      GameStateManager manager = new GameStateManager(new GameServiceContainer());
      TestGameState gameState = new TestGameState(manager);
      manager.Switch(gameState);

      manager.Draw(new GameTime());
      Assert.AreEqual(1, gameState.DrawCallCount);
    }
Пример #22
0
 public void TestEnterLeave() {
   GameStateManager manager = new GameStateManager(new GameServiceContainer());
   TestGameState gameState = new TestGameState(manager);
   
   Assert.AreEqual(0, gameState.OnEnteredCallCount);
   manager.Push(gameState);
   Assert.AreEqual(1, gameState.OnEnteredCallCount);
   
   Assert.AreEqual(0, gameState.OnLeavingCallCount);
   manager.Pop();
   Assert.AreEqual(1, gameState.OnLeavingCallCount);
 }
    public void TestSwitchToUnenterableState() {
      GameStateManager manager = new GameStateManager(new GameServiceContainer());
      TestGameState test = new TestGameState(manager);

      manager.Push(new TestGameState(manager));
      manager.Push(test);

      Assert.Throws<InvalidOperationException>(
        delegate() { manager.Switch(new UnenterableGameState(manager)); }
      );

      // Make sure the test state is still running. Whether pause was
      // called zero times or more, we only care that it's running after
      // the push has failed
      Assert.AreEqual(test.OnResumeCallCount, test.OnPauseCallCount);
      // Make sure the state is entered (meaning entered has been called
      // one more time than leave)
      Assert.AreEqual(test.OnLeavingCallCount + 1, test.OnEnteredCallCount);
    }
    public void TestLeaveOnDisposal() {
      GameStateManager manager = new GameStateManager(new GameServiceContainer());
      TestGameState test = new TestGameState(manager);

      manager.Switch(test);

      Assert.AreEqual(0, test.OnLeavingCallCount);
      manager.Dispose();
      Assert.AreEqual(1, test.OnLeavingCallCount);
    }
Пример #25
0
    public void TestGameStateManagerReference() {
      GameStateManager manager = new GameStateManager(new GameServiceContainer());
      TestGameState gameState = new TestGameState(manager);

      Assert.AreSame(manager, gameState.GameStateManager);
    }
    public void TestPauseOnPush() {
      GameStateManager manager = new GameStateManager(new GameServiceContainer());
      TestGameState test = new TestGameState(manager);

      manager.Switch(test);

      Assert.AreEqual(0, test.OnPauseCallCount);
      manager.Push(new TestGameState(manager));
      Assert.AreEqual(1, test.OnPauseCallCount);
    }
    public void TestSwitchOnlyChangesActiveState() {
      GameStateManager manager = new GameStateManager(new GameServiceContainer());
      TestGameState test1 = new TestGameState(manager);
      TestGameState test2 = new TestGameState(manager);

      manager.Push(test1);
      manager.Push(test2);

      Assert.AreEqual(0, test1.OnLeavingCallCount);
      Assert.AreEqual(0, test2.OnLeavingCallCount);

      manager.Switch(new TestGameState(manager));

      Assert.AreEqual(0, test1.OnLeavingCallCount);
      Assert.AreEqual(1, test2.OnLeavingCallCount);
    }
Пример #28
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // load settings file
            LoadSettings();

            InitializeGraphics();

            GameStates = new GameStateManager(Services);
            Input = new InputManager(Services);
            Services.AddService(typeof(ContentManager), Content);

            GameStates.Initialize();

            base.Initialize();
        }
Пример #29
0
 public void TestUpdateForwarding() {
   GameStateManager manager = new GameStateManager(new GameServiceContainer());
   TestGameState gameState = new TestGameState(manager);
   manager.Switch(gameState);
   
   manager.Update(new GameTime());
   Assert.AreEqual(1, gameState.UpdateCallCount);
 }