Example #1
0
    /// <summary>
    /// 
    /// </summary>
    private void _run()
    {
      //initialize the game params first
      GameParameters.Initialize((int)_viewFramework.GetScreenDimension().X, (int)_viewFramework.GetScreenDimension().Y);
      
      GameLogger.Initialize(Console.Out);
      EventBus eventBus = new EventBus();
      EventFactory eventFactory = new EventFactory();
      EventMonitor eventMonitor = new EventMonitor(eventFactory,eventBus);
      //this thread will be blocked at GetIGameSpriteFactory() until ContentManager is initialized
      GameObjectFactory gameObjectFactory = new GameObjectFactory(eventMonitor, _viewFramework.GetIGameSpriteFactory());
      GameObjectContainer gameObjects = new GameObjectContainer();
      MainEventProcessor mainEventListener = new MainEventProcessor(gameObjects, gameObjectFactory, eventBus);
      GameModel gameModel = new GameModel(gameObjects, gameObjectFactory);
      GameController gameController = new GameController(eventBus, gameModel, eventFactory, _viewFramework);

      //controller runs forever-loop
      gameController.Run();
    }
    public GameController(EventBus eventBus, GameModel model, EventFactory factory, IGameViewFramework viewFramework)
    {
      _gameModel = model;
      _eventBus = eventBus;
      _timerQ = new TimerQueue(eventBus);
      _eventFactory = factory;
      _tickMS = (int)GameParameters.REFRESH_RATE_MS;

      //TODO: The level paths should be an input from some game configuration file, instead of hardcoding them here
      //initialize the level paths. Does this belon here, or in model?
      _levels = new List<string>();
      for (int i = 1; i <= 3; i++)
      {
        _levels.Add(Environment.CurrentDirectory + "\\Levels\\Level" + i.ToString() + ".xml");
      }
      _matchManager = new MatchManager(model, _timerQ, eventBus, _eventFactory, _levels);

      //TODO: setting these could be moved outside this constructor. This object needs no persistent reference to view.
      viewFramework.SetKeyboardInputHandler(OnKeyboardInput);
      viewFramework.SetMouseInputHandler(OnMouseInput);
      _matchManager.OnLevelCompletion += viewFramework.OnLevelCompletion;
      _matchManager.OnGameOver += viewFramework.OnGameOver;
    }