/// <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()
        {
            random = new Random();

            //Initialize Other Classes
            DebugShapeRenderer.Initialize(GraphicsDevice);
            MessageBus.Initialize();
            consoleWriter = new ConsoleWriter();
            ShipManager.Initialize();

            //HazardManager.Initialize();
            GenericManager <Hazard> .Initialize();

            Camera.Initialize(GraphicsDevice);
            skybox = new Skybox(Content);
            player1InputManager = new InputManager(Keys.Space, Keys.A, Keys.D, Keys.E, Keys.W, Keys.S, Keys.LeftShift, Keys.F1, Keys.F2);
            CollisionManager.Initialize();
            collidables = new List <ICollidable>();

            ExplosionManager.Initialize();

            ScoreManager.Initialize();

            MessageBus.InsertNewMessage(new ConsoleMessage("Game Initiated!"));

            base.Initialize();
        }
예제 #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello GodSharp.MessageBus!");

            string cmd = null;

            MessageBus.Initialize(x =>
            {
                x.AddMemory();
            });

            MessageBus.Subscribe(MessageHandler10);
            MessageBus.Subscribe(MessageHandler11, "handler1");
            MessageBus.Subscribe(MessageHandler12, "handler2");

            MessageBus.Subscribe <TestMessage>(MessageHandler20);
            MessageBus.Subscribe <TestMessage>(MessageHandler21, "handler1");
            MessageBus.Subscribe <TestMessage>(MessageHandler22, "handler2");

            CancellationTokenSource cts = new CancellationTokenSource();

            Task task = new Task(async() =>
            {
                try
                {
                    Random random = new Random((int)DateTime.Now.Ticks);

                    while (!cts.IsCancellationRequested)
                    {
                        int i = random.Next(1, 7);
                        Console.WriteLine($"send {i}");

                        switch (i)
                        {
                        case 1:
                            MessageBus.Publish();
                            break;

                        case 2:
                            MessageBus.Publish("handler1");
                            break;

                        case 3:
                            MessageBus.Publish("handler2");
                            break;

                        case 4:
                            MessageBus.Publish(new TestMessage());
                            break;

                        case 5:
                            MessageBus.Publish(new TestMessage(), "handler1");
                            break;

                        case 6:
                            MessageBus.Publish(new TestMessage(), "handler2");
                            break;

                        default:
                            continue;
                        }

                        await Task.Delay(20);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }

                Console.WriteLine("task is cancel");
            });

            task.Start();

            do
            {
                cmd = Console.ReadLine();
                if (string.IsNullOrWhiteSpace(cmd))
                {
                    continue;
                }
            } while (cmd?.ToLower() != "q");

            Console.WriteLine("waitting to cancel");
            cts.Cancel();

            Console.ReadLine();
        }