示例#1
0
        public Breakout(IGameLoop gameLoop, IGraphics graphics, IAudio audio, IKeyboard keyboard, IFileSystem fileSystem) : base(nameof(Breakout), gameLoop, graphics, audio, keyboard, null, fileSystem)
        {
            Keyboard = new StatefulKeyboard(keyboard);

            // the state machine we'll be using to transition between various states
            // in our game instead of clumping them together in our update and draw
            // methods
            //
            // our current game state can be any of the following:
            // 1. 'start' (the beginning of the game, where we're told to press Enter)
            // 2. 'paddle-select' (where we get to choose the color of our paddle)
            // 3. 'serve' (waiting on a key press to serve the ball)
            // 4. 'play' (the ball is in play, bouncing between paddles)
            // 5. 'victory' (the current level is over, with a victory jingle)
            // 6. 'game-over' (the player has lost; display score and allow restart)
            StateMachine = new StateMachine(new Dictionary <string, State>
            {
                ["start"]            = new StartState(),
                ["play"]             = new PlayState(),
                ["serve"]            = new ServeState(),
                ["game-over"]        = new GameOverState(),
                ["victory"]          = new VictoryState(),
                ["high-scores"]      = new HighScoreState(),
                ["enter-high-score"] = new EnterHighScoreState(),
                ["paddle-select"]    = new PaddleSelectState(),
            });

            Instance = this;
        }
示例#2
0
        public void StartGame(IGameLoop gameLoop, IGame game)
        {
            do
            {
                string key;
                do
                {
                    Console.WriteLine("1. New game");
                    Console.WriteLine("2. Quit");
                    key = Console.ReadLine();
                    Console.Clear();
                } while (key != "1" && key != "2");
                switch (key)
                {
                case "1":
                    game.Initialize();
                    gameLoop.Run(game);
                    break;

                case "2":
                    Environment.Exit(0);
                    break;
                }
                Console.Clear();
            } while (true);
        }
示例#3
0
        public Game CreateGame(string gameName, IGameLoop gameLoop, IGraphics graphics, IAudio audio, IKeyboard keyboard, IMouse mouse, IFileSystem fileSystem)
        {
            var gameType = typeof(Game);

            var game = AppDomain.CurrentDomain.GetAssemblies()
                       .SelectMany(assembly => assembly.GetTypes())
                       .SingleOrDefault(type => type.Name == gameName &&
                                        type.IsSubclassOf(gameType) &&
                                        !type.IsAbstract);

            var constructors = game.GetConstructors();
            var constructor  = constructors.FirstOrDefault();
            var parameters   = constructor.GetParameters();

            var arguments = new List <object>();

            arguments.Add(gameLoop);
            arguments.Add(graphics);
            arguments.Add(audio);
            arguments.Add(keyboard);
            if (parameters.Any(p => p.Name == nameof(mouse)))
            {
                arguments.Add(mouse);
            }
            if (parameters.Any(p => p.Name == nameof(fileSystem)))
            {
                arguments.Add(fileSystem);
            }

            var gameInstance = (Game)Activator.CreateInstance(game, arguments.ToArray());

            return(gameInstance);
        }
示例#4
0
 protected ActorCommandBase(IGameLoop gameLoop,
                            ISectorManager sectorManager,
                            ISectorUiState playerState) : base(gameLoop)
 {
     SectorManager = sectorManager;
     PlayerState   = playerState;
 }
示例#5
0
 public MoveCommand(IGameLoop gameLoop,
                    ISectorManager sectorManager,
                    IPlayerState playerState) :
     base(gameLoop, sectorManager, playerState)
 {
     _path = new List <IMapNode>();
 }
示例#6
0
        /// <inheritdoc />
        public void MainLoop()
        {
            if (_mainLoop == null)
            {
                _mainLoop = new GameLoop(_time)
                {
                    SleepMode      = SleepMode.Delay,
                    DetectSoftLock = true
                };
            }

            _uptimeStopwatch.Start();

            _mainLoop.Tick += (sender, args) => Update(args);

            _mainLoop.Update += (sender, args) =>
            {
                ServerUpTime.Set(_uptimeStopwatch.Elapsed.TotalSeconds);
            };

            // set GameLoop.Running to false to return from this function.
            _mainLoop.Run();

            _time.InSimulation = true;
            Cleanup();

            _shutdownEvent.Set();
        }
示例#7
0
 public void OnHostClick()
 {
     if (m_GameLoop == null)
     {
         m_GameLoop = new ServerLoop();
     }
     m_GameLoop.Start();
 }
示例#8
0
 public static T GetPresenter <T>(this IGameLoop gameLoop)
     where T : IPresenter
 {
     // HACK. 面倒なので全オブジェクト拾ってきてinterfaceを対象に初期化していく.
     return(Object.FindObjectsOfType <GameObject>()
            .First(_ => _.GetComponent <T>() != null)
            .GetComponent <T>());
 }
示例#9
0
 public void OnLogin()
 {
     if (m_GameLoop == null)
     {
         m_GameLoop = new ClientLoop();
     }
     m_GameLoop.Start();
 }
示例#10
0
 public NextTurnCommand(IGameLoop gameLoop,
                        ISectorManager sectorManager,
                        IPlayerState playerState,
                        IDecisionSource decisionSource) :
     base(gameLoop, sectorManager, playerState)
 {
     _decisionSource = decisionSource;
 }
示例#11
0
 public UseSelfCommand(IGameLoop gameLoop,
                       ISectorManager sectorManager,
                       IPlayerState playerState,
                       IInventoryState inventoryState) :
     base(gameLoop, sectorManager, playerState)
 {
     _inventoryState = inventoryState;
 }
示例#12
0
 public AttackCommand(IGameLoop gameLoop,
                      ISectorManager sectorManager,
                      ISectorUiState playerState,
                      ITacticalActUsageService tacticalActUsageService) :
     base(gameLoop, sectorManager, playerState)
 {
     _tacticalActUsageService = tacticalActUsageService;
 }
示例#13
0
 public EquipCommand(IGameLoop gameLoop,
                     ISectorManager sectorManager,
                     ISectorUiState playerState,
                     IInventoryState inventoryState) :
     base(gameLoop, sectorManager, playerState)
 {
     _inventoryState = inventoryState;
 }
示例#14
0
        public CockpitPanel(IGameLoop loop)
        {
            _loop = loop;
            _loop.RegisterHandler(LoopUpdate);
            var container = Resolver.Bootstrap();

            FuelSystem = container.Resolve <IFuelSystem>();
            Alarms     = container.Resolve <IAlarms>();
        }
示例#15
0
        protected GameBase(Options options, IGamePlatformFactory gamePlatformFactory, IGraphicsFactory graphicsFactory, IInputFactory inputFactory)
        {
            _options             = options;
            _gamePlatformFactory = gamePlatformFactory;
            GraphicsFactory      = graphicsFactory;
            _inputFactory        = inputFactory;
            _inputMapper         = new InputMapper(_inputFactory);

            _gameLoop = _gamePlatformFactory.CreateGameLoop();
        }
示例#16
0
        public async void SetLoop(GameLoopType type)
        {
            _currentLoop?.LoopOut();

            _isUpdatable = false;
            _currentLoop = _gameLoops[(int)type];
            await _currentLoop.LoopIn();

            _isUpdatable = true;
        }
示例#17
0
        public MoveCommand(IGameLoop gameLoop,
                           ISectorManager sectorManager,
                           ISectorUiState playerState,
                           IActorManager actorManager) :
            base(gameLoop, sectorManager, playerState)
        {
            _actorManager = actorManager;

            Path = new List <IMapNode>();
        }
示例#18
0
        public Engine(
            Configuration configuration,
            IAudioBackend audioBackend,
            IInputBackend inputBackend,
            IRenderingBackend renderingBackend,
            IGame game)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }
            if (audioBackend == null)
            {
                throw new ArgumentNullException(nameof(audioBackend));
            }
            if (inputBackend == null)
            {
                throw new ArgumentNullException(nameof(inputBackend));
            }
            if (renderingBackend == null)
            {
                throw new ArgumentNullException(nameof(renderingBackend));
            }
            if (game == null)
            {
                throw new ArgumentNullException(nameof(game));
            }

            Log.Info("Initializing engine components.");
            var containerBuilder = new ContainerBuilder();

            CommonModules.RegisterAll(containerBuilder);
            EngineModules.RegisterAll(containerBuilder);

            containerBuilder.RegisterInstance(configuration.Core).As <CoreConfiguration>().SingleInstance();
            containerBuilder.RegisterInstance(configuration.Physics).As <PhysicsConfiguration>().SingleInstance();
            containerBuilder.RegisterInstance(configuration.Rendering).As <RenderingConfiguration>().SingleInstance();

            containerBuilder.RegisterInstance(audioBackend).As <IAudioBackend>().SingleInstance();
            containerBuilder.RegisterInstance(inputBackend).As <IInputBackend>().SingleInstance();
            containerBuilder.RegisterInstance(renderingBackend).As <IRenderingBackend>().SingleInstance();

            var componentsRegistry = new ComponentsRegistry(containerBuilder);

            game.RegisterComponents(componentsRegistry);

            _container     = containerBuilder.Build();
            _lifetimeScope = _container.BeginLifetimeScope();

            RunStartUpTasks();

            _gameLoop      = _lifetimeScope.Resolve <IGameLoop>();
            _engineManager = _lifetimeScope.Resolve <IEngineManager>();
            Log.Info("Engine components initialized.");
        }
示例#19
0
 public void PollEvents(IGameLoop gameLoop)
 {
     while (SDL.SDL_PollEvent(out var @event) != 0)
     {
         OnEvent(@event, gameLoop);
         if (@event.type == SDL.SDL_EventType.SDL_QUIT)
         {
             gameLoop.Stop();
         }
     }
 }
示例#20
0
        public GameLoopManager(
            ILogger <GameLoopManager> logger,
            ISdl2 sdl,
            IGameLoop gameLoop)
        {
            _logger   = logger;
            _sdl      = sdl;
            _gameLoop = gameLoop;

            _thread = new Thread(RunGameLoopInBackground);
            _thread.Start();
        }
示例#21
0
文件: Game.cs 项目: BlazorHub/CS50G
        protected Game(string gameName, IGameLoop gameLoop, IGraphics graphics, IAudio audio, IKeyboard keyboard, IMouse mouse = null, IFileSystem fileSystem = null)
        {
            GameName      = gameName;
            this.gameLoop = gameLoop;
            Graphics      = graphics;
            Audio         = audio;
            Keyboard      = keyboard;
            Mouse         = mouse;
            FileSystem    = fileSystem;

            Sounds = new Dictionary <string, ISource>();
            Random = new Random();

            Instance = this;
        }
示例#22
0
        /// <inheritdoc />
        public void MainLoop()
        {
            if (_mainLoop == null)
            {
                _mainLoop = new GameLoop(_time)
                {
                    SleepMode = SleepMode.Delay
                };
            }

            _mainLoop.Tick += (sender, args) => Update(args.DeltaSeconds);

            // set GameLoop.Running to false to return from this function.
            _mainLoop.Run();
            Cleanup();
        }
示例#23
0
        public FiftyBird(IGameLoop gameLoop, IGraphics graphics, IAudio audio, IKeyboard keyboard, IMouse mouse) : base(nameof(FiftyBird), gameLoop, graphics, audio, keyboard, mouse)
        {
            Keyboard = new StatefulKeyboard(keyboard);
            Mouse    = new StatefulMouse(mouse);

            // initialize state machine with all state - returning functions
            StateMachine = new StateMachine(new Dictionary <string, State>
            {
                ["title"]     = new TitleScreenState(),
                ["countdown"] = new CountdownState(),
                ["play"]      = new PlayState(),
                ["score"]     = new ScoreState()
            });

            Instance = this;
        }
示例#24
0
        public void MainLoop(DisplayMode mode)
        {
            if (_mainLoop == null)
            {
                _mainLoop = new GameLoop(_gameTiming)
                {
                    SleepMode = mode == DisplayMode.Headless ? SleepMode.Delay : SleepMode.None
                };
            }

            _mainLoop.Tick += (sender, args) =>
            {
                if (_mainLoop.Running)
                {
                    Tick(args);
                }
            };

            _mainLoop.Render += (sender, args) =>
            {
                if (_mainLoop.Running)
                {
                    _gameTiming.CurFrame++;
                    _clyde.Render();
                }
            };
            _mainLoop.Input += (sender, args) =>
            {
                if (_mainLoop.Running)
                {
                    Input(args);
                }
            };

            _mainLoop.Update += (sender, args) =>
            {
                if (_mainLoop.Running)
                {
                    Update(args);
                }
            };

            // set GameLoop.Running to false to return from this function.
            _mainLoop.Run();

            Cleanup();
        }
示例#25
0
        public void MainLoop(DisplayMode mode)
        {
            if (_mainLoop == null)
            {
                _mainLoop = new GameLoop(_gameTiming)
                {
                    SleepMode = mode == DisplayMode.Headless ? SleepMode.Delay : SleepMode.None
                };
            }

            _mainLoop.Tick += (sender, args) =>
            {
                if (_mainLoop.Running)
                {
                    Update(args.DeltaSeconds);
                }
            };

            _mainLoop.Render += (sender, args) =>
            {
                if (_mainLoop.Running)
                {
                    _gameTiming.CurFrame++;
                    _clyde.Render(new FrameEventArgs(args.DeltaSeconds));
                }
            };
            _mainLoop.Input += (sender, args) =>
            {
                if (_mainLoop.Running)
                {
                    _clyde.ProcessInput(new FrameEventArgs(args.DeltaSeconds));
                }
            };

            _mainLoop.Update += (sender, args) =>
            {
                if (_mainLoop.Running)
                {
                    _frameProcessMain(args.DeltaSeconds);
                }
            };

            // set GameLoop.Running to false to return from this function.
            _mainLoop.Run();
        }
示例#26
0
 public FuelSystem(IFuelMessaging msg, IGameLoop loop)
 {
     _msg = msg;
     loop.RegisterHandler(IntervalUpdate);
     LeftTank = new FuelTank(msg, loop)
     {
         Capacity = 12,
         Quantity = 12,
         Name     = "Left"
     };
     RightTank = new FuelTank(msg, loop)
     {
         Capacity = 12,
         Quantity = 12,
         Name     = "Right"
     };
     SelectedTank = Tank.Left;
 }
示例#27
0
        public void OnEvent(SDL.SDL_Event @event, IGameLoop gameLoop)
        {
            if ([email protected](SDL.SDL_EventType.SDL_KEYDOWN))
            {
                return;
            }

            if (@event.key.keysym.sym.Equals(SDL.SDL_Keycode.SDLK_ESCAPE))
            {
                Console.WriteLine("Escape pressed.");
                gameLoop.Stop();
            }

            float?simulationSpeed = @event.key.keysym.sym switch
            {
                SDL.SDL_Keycode.SDLK_BACKQUOTE => 10.0f, SDL.SDL_Keycode.SDLK_1 => 1.0f, SDL.SDL_Keycode.SDLK_2 => 0.5f
                , SDL.SDL_Keycode.SDLK_3 => 0.25f, SDL.SDL_Keycode.SDLK_4 => 0.125f, SDL.SDL_Keycode.SDLK_5 => 0.01f
                , SDL.SDL_Keycode.SDLK_6 => 0.0f, _ => null
            };

            if (simulationSpeed.HasValue)
            {
                Console.WriteLine($"Set simulation speed to {simulationSpeed.Value}");
                gameLoop.SetSimulationSpeed(simulationSpeed.Value);
            }

            _cameraX += @event.key.keysym.sym switch
            {
                SDL.SDL_Keycode.SDLK_LEFT => 10, SDL.SDL_Keycode.SDLK_RIGHT => - 10, _ => 0
            };

            _cameraY += @event.key.keysym.sym switch
            {
                SDL.SDL_Keycode.SDLK_UP => 10, SDL.SDL_Keycode.SDLK_DOWN => - 10, _ => 0
            };

            _zoom += @event.key.keysym.sym switch
            {
                SDL.SDL_Keycode.SDLK_HOME => 0.25f, SDL.SDL_Keycode.SDLK_END => - 0.25f, _ => 0.0f
            };

            _zoom = Math.Max(_zoom, 0.25f);
        }
示例#28
0
        /// <inheritdoc />
        public void MainLoop()
        {
            if (_mainLoop == null)
            {
                _mainLoop = new GameLoop(_time)
                {
                    SleepMode      = SleepMode.Delay,
                    DetectSoftLock = true
                };
            }

            _mainLoop.Tick += (sender, args) => Update(args);

            // set GameLoop.Running to false to return from this function.
            _mainLoop.Run();

            _time.InSimulation = true;
            Cleanup();
        }
 public RoomTransitionWorkflow(IRoomTransitions transitions, IWindowInfo window, IRendererLoop rendererLoop,
                               Resolver resolver, IGameEvents events, IGameLoop loop, IAGSRenderPipeline pipeline,
                               IGameSettings settings, IAGSGameState state, IDisplayList displayList, IGLUtils glUtils)
 {
     _glUtils                = glUtils;
     _dummyWindow            = new DummyWindow();
     _transitions            = transitions;
     _transitions.Transition = new RoomTransitionInstant();
     _window                = window;
     _rendererLoop          = rendererLoop;
     _resolver              = resolver;
     _events                = events;
     _loop                  = loop;
     _pipeline              = pipeline;
     _state                 = state;
     _displayList           = displayList;
     _settings              = settings;
     _noAspectRatioSettings = new AGSGameSettings(settings.Title, settings.VirtualResolution, preserveAspectRatio: false);
     state.OnRoomChangeRequired.SubscribeToAsync(onRoomChangeRequired);
 }
示例#30
0
        public void MainLoop(GameController.DisplayMode mode)
        {
            _mainLoop = new GameLoop(_gameTiming);

            _mainLoop.Tick += (sender, args) =>
            {
                if (_mainLoop.Running)
                {
                    ProcessUpdate(args);
                }
            };

            _mainLoop.Render += (sender, args) =>
            {
                if (_mainLoop.Running)
                {
                    _gameTiming.CurFrame++;
                    _clyde.Render();
                }
            };
            _mainLoop.Input += (sender, args) =>
            {
                if (_mainLoop.Running)
                {
                    _clyde.ProcessInput(args);
                }
            };

            _mainLoop.Update += (sender, args) =>
            {
                if (_mainLoop.Running)
                {
                    RenderFrameProcess(args);
                }
            };

            _mainLoop.Run();
        }