This class encapsulates the majority of the Terrarium gaming engine that controls the creatures, updates of the world data, manipulation of events, and other common engine features. To see the basic game logic, look at the ProcessTurn() function. This is what controls the flow of the game.
Beispiel #1
0
        /// <summary>
        /// Creates the scheduler in the same appdomain as the rest of the game
        /// </summary>
        /// <param name="engine"></param>
        /// <returns></returns>
        internal static IGameScheduler CreateSameDomainScheduler(GameEngine engine)
        {
            if (_theScheduler == null)
            {
                _theScheduler = new GameScheduler();
            }
            else
            {
                throw new ApplicationException("A Scheduler already exists.");
            }

            _theScheduler.CurrentGameEngine = engine;

            return _theScheduler;
        }
Beispiel #2
0
        /// <summary>
        ///  Stops the game and determines if the final tick of data should be serialized.
        /// </summary>
        /// <param name="serializeState">Controls if the state is serialized.</param>
        public void StopGame(Boolean serializeState)
        {
            // This needs to be the first call in stop game because if it fails, the game needs to be able
            // to continue.  In addition, it may jump the engine ahead a few phases, and if the engine isn't
            // in the normal running state this could cause things to fail since the engine phases are expecting
            // things to be in a normal state.
            if (serializeState)
            {
                this.serializeState(_currentStateFileName);
            }

            if (_usingNetwork && _networkEngine != null)
            {
                _networkEngine.ShutdownNetwork();
                _networkEngine = null;
                _usingNetwork = false;
            }

            // Shut down populationData after serializing since serializing
            // may advance to the end of the tick
            if (_populationData != null)
            {
                _populationData.Close();
                _populationData = null;
            }

            AppMgr.DestroyScheduler();
            _pac.Close();
            _ledIndicators = null;
            _engine = null;
        }
Beispiel #3
0
        /// <summary>
        ///  Creates a new game engine that can be used for a Terrarium game.  Terrarium
        ///  games aren't networked and can load any creatures.
        /// </summary>
        /// <param name="dataPath">The path where the Terrarium game will be stored.</param>
        /// <param name="fileName">The path to the serialized Terrarium.</param>
        /// <param name="leds">A series of leds to be used for state reporting.</param>
        public static void NewTerrariumGame(string dataPath, string fileName, TerrariumLed[] leds)
        {
            if (_engine != null)
            {
                _engine.StopGame(false);
            }

            _engine = new GameEngine(dataPath, false, false, fileName, false, leds, true);
        }
Beispiel #4
0
        /// <summary>
        ///  Creates a new game engine that can be used to play an EcoSystem game.
        /// </summary>
        /// <param name="dataPath">The path where the Terrarium game will be stored.</param>
        /// <param name="fileName">The path to the serialized Terrarium.</param>
        /// <param name="leds">A series of leds to be used for state reporting.</param>
        public static void NewEcosystemGame(string dataPath, string fileName, TerrariumLed[] leds)
        {
            if (_engine != null)
            {
                _engine.StopGame(false);
            }

            _engine = new GameEngine(dataPath, true, false, dataPath + fileName, true, leds, true);

            // Start the network after Current is set on GameEngine because the network
            // needs a current gameengine to receive teleportations
            if (_engine._usingNetwork)
            {
                _engine._networkEngine.InitializeNetwork("EcoSystem", leds);
            }

            _engine._ecosystemMode = true;
        }