Пример #1
0
        async Task Start(ThreadContext <IGame> startupContext = null)
        {
            MessageBrokerFactory.Instance.Publish(new GameMessage("Starting game."));

            if (!this.IsEnabled)
            {
                await this.Initialize();
            }

            MessageBrokerFactory.Instance.Publish(new GameMessage("Configuring game configuration components."));
            foreach (IAdapter adapter in this.configuredAdapters)
            {
                MessageBrokerFactory.Instance.Publish(new GameMessage($"Initializing {adapter.Name} component."));
                await adapter.Start(this);

                MessageBrokerFactory.Instance.Publish(new GameMessage($"{adapter.Name} initialization completed."));
            }

            this.IsRunning = true;
            MessageBrokerFactory.Instance.Publish(new GameMessage("Game started."));

            if (startupContext != null)
            {
                startupContext.Invoke(this);
                return;
            }

            // Start the game loop.
            await Task.Run(() =>
            {
                while (this.IsRunning)
                {
                    Task.Delay(1).Wait();
                }
            });
        }
Пример #2
0
        async Task Start(ThreadContext<IGame> startupContext = null)
        {
            MessageBrokerFactory.Instance.Publish(new GameMessage("Starting game."));

            if (!this.IsEnabled)
            {
                await this.Initialize();
            }

            MessageBrokerFactory.Instance.Publish(new GameMessage("Configuring game configuration components."));
            foreach (IAdapter adapter in this.configuredAdapters)
            {
                MessageBrokerFactory.Instance.Publish(new GameMessage($"Initializing {adapter.Name} component."));
                await adapter.Start(this);
                MessageBrokerFactory.Instance.Publish(new GameMessage($"{adapter.Name} initialization completed."));
            }

            this.IsRunning = true;
            MessageBrokerFactory.Instance.Publish(new GameMessage("Game started."));

            if (startupContext != null)
            {
                startupContext.Invoke(this);
                return;
            }

            // Start the game loop.
            await Task.Run(() =>
            {
                while (this.IsRunning)
                {
                    Task.Delay(1).Wait();
                }
            });
        }