public void Setup(Game game)
        {
            GlobalServices.SetGame(game);

            var soundPlayer = new SoundPlayer(new SoundLibrary(), new ActiveSoundService());

            GlobalServices.SetSoundPlayer(soundPlayer);

            var spriteLibrary = new SpriteLibrary(game);

            GlobalServices.SetSpriteLibrary(spriteLibrary);

            var randomness = new StandardRandom();

            GlobalServices.SetRandomness(randomness);
        }
Exemple #2
0
        public World([NotNull] IWorldLoader worldLoader, [NotNull] string world)
        {
            worldLoader.LoadWorld(world);
            this._worldSize         = worldLoader.WorldSize;
            this._tiles             = worldLoader.FloorTiles;
            this._restartInSameRoom = worldLoader.RestartInSameRoom;
            this._playerStartStates = worldLoader.PlayerStartStates;

            var boundMovementFactory = new BoundMovementFactory(this._worldSize);

            GlobalServices.SetBoundMovementFactory(boundMovementFactory);

            var gameObjectCollection = new GameObjectCollection(worldLoader.WorldSize);
            var gameState            = new GameState(gameObjectCollection);

            GlobalServices.SetGameState(gameState);
            worldLoader.AddGameObjects(gameState);
            this._player = gameState.Player;

            this._worldClock = new WorldClock();
            if (worldLoader.UnlockLevels)
            {
                this._worldClock.AddEventHandler(new UnlockLevel(this));
            }
            foreach (var dist in worldLoader.FruitDistributions.Where(item => item.PopulationMethod.WillReplenish()))
            {
                var replenishFruit = new ReplenishFruit(dist);
                this._worldClock.AddEventHandler(replenishFruit);
            }

            this._worldWindow = new WorldWindow();
            GlobalServices.SetCentrePointProvider(this._worldWindow);

            ValidateGameState(gameState);

            Messenger.Default.Register <WorldCompleted>(this, WorldCompleted);
            Messenger.Default.Register <LifeLost>(this, LostLife);
        }