예제 #1
0
        public void Run(IGame game)
        {
            if (_game != null)
                throw new InvalidOperationException("A game is already running.");

            if (_device == null)
                throw new InvalidOperationException("Setup must be called before Run.");

            Current = this;

            Show();
            _game = game;

            try
            {
                var sw = Stopwatch.StartNew();
                _game.Setup(_device, this);

                while (_game != null)
                {
                    Application.DoEvents();
                    if (!IsDeviceLost())
                    {
                        var deltaTime = sw.Elapsed;
                        sw.Restart();
                        if (game.Process(_device, deltaTime))
                            game.Paint(_device);
                        else
                        {
                            Close();
                            break;
                        }
                    }
                }
            }
            catch
            {
                Close();
                throw;
            }
            game.ShutDown(_device);

            Current = null;
        }
예제 #2
0
파일: GameCore.cs 프로젝트: ricklove/ToldEm
        public void Setup(IHost host, IGame game)
        {
            IsDebugEnabled = true;

            _host = host;
            _game = game;

            _host.SetGameCore(this);

            _game.Setup();

            // Create assets
            var drawables = _game.Entities.Cast<Entity>().Where(e => e.IsDrawable).OrderBy(d => d.ZIndex).Cast<IDrawable>().ToList();
            drawables.ForEach(d =>
            {
                _host.GraphicsProvider.RegisterImageResource(d.ResourceUrl, d.ResourceUrl);
                _host.GraphicsProvider.LoadImageResource(d.ResourceUrl);
            });
        }