/// <summary> /// Starts a game and attempts to run it a specified number of generations. Will call the connected /// clients on completion or error. /// </summary> /// <param name="settings">Settings to start the game with.</param> public void StartGame(GameSettingsModel settings) { if (settings == null) { throw new ArgumentNullException("settings"); } try { var rules = RuleFactory.Build(settings.Rules); var lifeForm = LifeFormFactory.Build(settings.LifeForm); var game = bootstrapper.Boot <LinqGame>(rules); game.InitializeFrom(lifeForm.GetPattern()); game.GameStepEvent += OnGameStepEvent; game.RunThrough(settings.NumberOfGenerations); Clients.All.DisplayResults(game); } catch (BootFailedException) { var message = "Booting the game failed."; Clients.All.DisplayError(message); } }
void Start() { using (gameManager = new GameManager()) { gameManager.CreateStorageFile(); settingsModel = gameManager.GetGameSettingsAndHighScores(); if (settingsModel != null) { var panel = GameObject.Find("HighScorePanel"); if (panel != null) { settingsModel.HighScores = settingsModel.HighScores.OrderByDescending(x => x.Score).ThenByDescending(x => x.Level).ToList(); foreach (var item in settingsModel.HighScores) { var positionofpanel = panel.transform; Button newButtonInstance = MonoBehaviour.Instantiate(m_testText, positionofpanel) as Button; Text textObject = newButtonInstance.GetComponentInChildren <Text>(); textObject.text = "Score: " + item.Score + " Level: " + item.Level; textObject.gameObject.SetActive(true); newButtonInstance.transform.SetParent(positionofpanel); newButtonInstance.gameObject.SetActive(true); } } } } }
private void Start() { try { Advertisement.Initialize(gameId, false); using (gameManager = new GameManager()) { gameManager.CreateStorageFile(); settingsModel = gameManager.GetGameSettingsAndHighScores(); if (settingsModel == null) { settingsModel = new GameSettingsModel(); settingsModel.Exploded = false; settingsModel.DateEntered = DateTime.UtcNow.ToString(); settingsModel.HighScores = new List <HighScoreModel>(); settingsModel.Id = 1; settingsModel.platformSpeed = 2f; settingsModel.spawnSpeed = 2f; settingsModel.Volume = 1; } else { Level = 1; LevelString = "Level: " + Level; Score = 0; ScoreString = "Score: 0"; } } } catch (Exception ex) { throw ex; } }
public List <HighScoreModel> CalculateTop5HighScore(int NewGameScore) { List <HighScoreModel> modelList = new List <HighScoreModel>(); using (gameManager = new GameManager()) { GameSettingsModel model = gameManager.GetGameSettingsAndHighScores(); if (model != null && model.HighScores != null && model.HighScores.Count > 0) { model.HighScores = model.HighScores.OrderByDescending(x => x.Score).ThenByDescending(y => y.ScoreDate).ToList(); HighScoreModel newHighScore = new HighScoreModel() { Id = model.HighScores.Max(x => x.Id) + 1, Level = Level, Score = NewGameScore, ScoreDate = DateTime.UtcNow.ToString() }; model.HighScores.Add(newHighScore); if (model.HighScores.Count > 5) { model.HighScores = model.HighScores.OrderByDescending(x => x.Score).ThenByDescending(y => y.ScoreDate).ToList(); model.HighScores.RemoveRange(5, 1); } modelList.AddRange(model.HighScores); } else { HighScoreModel item = new HighScoreModel(); item.Id = 1; item.Level = Level; item.Score = NewGameScore; item.ScoreDate = DateTime.UtcNow.ToString(); modelList.Add(item); } } return(modelList); }
/// <summary> /// Starts a game and attempts to run it a specified number of generations. Will call the connected /// clients on completion or error. /// </summary> /// <param name="settings">Settings to start the game with.</param> public void StartGame(GameSettingsModel settings) { if (settings == null) { throw new ArgumentNullException("settings"); } try { var rules = RuleFactory.Build(settings.Rules); var lifeForm = LifeFormFactory.Build(settings.LifeForm); var game = bootstrapper.Boot<LinqGame>(rules); game.InitializeFrom(lifeForm.GetPattern()); game.GameStepEvent += OnGameStepEvent; game.RunThrough(settings.NumberOfGenerations); Clients.All.DisplayResults(game); } catch (BootFailedException) { var message = "Booting the game failed."; Clients.All.DisplayError(message); } }
public void VolumeChanged(float sliderComponent) { GameObject mainCamera = GameObject.FindGameObjectWithTag("MainCamera"); AudioSource source = mainCamera.GetComponent <AudioSource>(); source.volume = sliderComponent * 0.10f; using (gameManager = new GameManager()) { gameManager.CreateStorageFile(); var settingsModel = gameManager.GetGameSettingsAndHighScores(); if (settingsModel == null) { settingsModel = new GameSettingsModel(); settingsModel.Exploded = false; settingsModel.DateEntered = System.DateTime.UtcNow.ToString(); settingsModel.HighScores = new List <HighScoreModel>(); settingsModel.Id = 1; settingsModel.platformSpeed = 2f; settingsModel.spawnSpeed = 2f; settingsModel.Volume = (decimal)sliderComponent; } else { settingsModel.Volume = (decimal)sliderComponent; } gameManager.SaveItem(settingsModel); } }
public ActionResult WaitForConnection(GameSettingsModel game) { GamesManager.Instance.AddPlayerToMap(User.Identity.GetUserId(), game.Map); if (game.WithAI == "true") { GamesManager.Instance.BeginSinglePlayerGame(User.Identity.GetUserId()); return(RedirectToAction("Index")); } return(View()); }
public ActionResult NewGame(GameSettingsModel gsModel) { var saveGame = new GameStorage(); saveGame.gameSettingsModel = gsModel; var store = new Store(); return(RedirectToAction("Index", "Game", null)); }
public IEnumerator Setup() { _managerGO = new GameObject(); yield return(null); IGameSettingsModel gameSettingsModel = new GameSettingsModel(); TypeGame typeGame = TypeGame.GameWithBuffs; Dictionary <int, PlayerEntity> dictionary = new Dictionary <int, PlayerEntity>(); IGameController gameController = new GameController(gameSettingsModel, typeGame); _controller = new PlayerController(dictionary, gameController); }
private void Start() { try { Advertisement.Initialize(gameId, false); #if UNITY_IOS Application.targetFrameRate = 60; #endif using (gameManager = new GameManager()) { gameManager.CreateStorageFile(); settingsModel = gameManager.GetGameSettingsAndHighScores(); if (settingsModel == null) { settingsModel = new GameSettingsModel(); settingsModel.Exploded = false; settingsModel.DateEntered = DateTime.UtcNow.ToString(); settingsModel.HighScores = new List <HighScoreModel>(); settingsModel.Id = 1; settingsModel.platformSpeed = 120f; settingsModel.spawnSpeed = 2f; settingsModel.Volume = 1; settingsModel.Died = 0; } else { Level = 1; LevelString = "Level: " + Level; Score = 0; ScoreString = "Score: 0"; settingsModel.platformSpeed = 120f; } float height = Camera.main.orthographicSize * 2; float minWidth = Camera.main.orthographicSize * -1; float maxWidth = Camera.main.orthographicSize; float minheight = height * Camera.main.aspect * -1; float maxHeight = height * Camera.main.aspect; float x = UnityEngine.Random.Range((float)minWidth + (float)0.64, (float)maxWidth - (float)0.64); float y = UnityEngine.Random.Range((float)minheight + (float)0.64, (float)maxHeight - (float)0.64); GameObject selfGameObject = GameObject.FindGameObjectWithTag("Coin"); selfGameObject.transform.SetPositionAndRotation(new Vector3(x, y, 0), Quaternion.identity); // at the desired position... } } catch (Exception ex) { throw ex; } }
private void SetGameSettings() { if (GameController.Instance != null) { if (GameController.Instance.GameSettings != null) { _gameSettings = GameController.Instance.GameSettings; } else { Debug.LogError("There is not game settings reference set in the GameController!"); } } else { Debug.LogError("There is no GameController instance available!"); } }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); // In production, the Angular files will be served from this directory services.AddSpaStaticFiles(configuration => { configuration.RootPath = "ClientApp/dist"; }); //Inject Our Custom Services services.Configure <GameSettingsModel>(Configuration.GetSection("GameSettings")); var gameSettings = new GameSettingsModel( Configuration["GameSettings:NumberOfCards"], Configuration["GameSettings:MinimumNumberOfPlayers"] ); services.AddScoped <IGameServices, GameServices>(serviceProvider => { return(new GameServices(gameSettings)); }); }
public void StartGame_WhenBootstrappingFails_CallsErrorCallback() { // arrange mockBoot .Setup(x => x.Boot <LinqGame>(It.IsAny <RulesBase>())) .Throws(new BootFailedException()); var settings = new GameSettingsModel { LifeForm = LifeForm.Empty, NumberOfGenerations = 30, Rules = Rule.Standard }; // act:ish hub.StartGame(settings); // assert clients.Verify( x => x.DisplayError(It.IsAny <string>()), Times.Once()); }
public void ApplyBuffsOnPlayer_True_AppliesBuffsOnPlayer() { // Assign Dictionary <int, PlayerEntity> dictionary = new Dictionary <int, PlayerEntity>(); TypeGame typeGame = TypeGame.GameWithBuffs; IGameSettingsModel gameSettingsModel = new GameSettingsModel(); IGameController gameController = new GameController(gameSettingsModel, typeGame); IBuffCollector BuffCollector = new BuffCollector(gameController); IPlayerModel playerModel = new PlayerModel() { PlayerPanelHierarchy = new GameObject().AddComponent <PlayerPanelHierarchyBehaviour>(), PlayerId = 1 }; PlayerController playerController = new PlayerController(dictionary, gameController); Dictionary <TypeCharacteristic, float> buffs = new Dictionary <TypeCharacteristic, float>(); Action <Dictionary <TypeCharacteristic, float>, IPlayerModel> callback = new Action <Dictionary <TypeCharacteristic, float>, IPlayerModel>(playerController.IncreasePlayerCharacteristicsValue); // Act BuffCollector.ApplyBuffsOnPlayer(playerModel, callback); // Assert }
public IActionResult Start(GameSettingsModel model) { if (!Session.TryLobbyController(out var host)) { return(View("Join")); } var lobby = host.Lobby; if (host.Id != lobby.Host.Id) { return(Lobby()); } if (!Lobbies.TryRemove(lobby.Id, out lobby)) { return(View("Join")); } lobby.Setup.Roles.Selectors = model.RoleEntries(); var match = lobby.Start(); Matches.Add(match); foreach (var controller in lobby.Controllers) { SessionExtensions.LobbyControllers.TryRemove(controller.Id, out _); } foreach (var player in match.AllPlayers) { SessionExtensions.PlayerControllers[player.Id] = player.Controller; } return(Play()); }
public void StartGame_WhenGameRunsThrough_ReturnsGameState() { // arrange var mockGame = BuildMockGame(); mockBoot .Setup(x => x.Boot <LinqGame>(It.IsAny <RulesBase>())) .Returns(mockGame.Object); var settings = new GameSettingsModel { LifeForm = LifeForm.Empty, NumberOfGenerations = 30, Rules = Rule.Standard }; // act hub.StartGame(settings); // assert mockBoot.Verify( x => x.Boot <LinqGame>(It.IsAny <RulesBase>()), Times.Once()); mockGame.Verify( x => x.InitializeFrom(It.IsAny <int[][]>()), Times.Once()); mockGame.Verify( x => x.RunThrough(It.IsAny <int>()), Times.Once()); clients.Verify( x => x.DisplayResults(It.Is <GameBase>(r => r == mockGame.Object)), Times.Once()); }
public void StartGame_WhenBootstrappingFails_CallsErrorCallback() { // arrange mockBoot .Setup(x => x.Boot<LinqGame>(It.IsAny<RulesBase>())) .Throws(new BootFailedException()); var settings = new GameSettingsModel { LifeForm = LifeForm.Empty, NumberOfGenerations = 30, Rules = Rule.Standard }; // act:ish hub.StartGame(settings); // assert clients.Verify( x => x.DisplayError(It.IsAny<string>()), Times.Once()); }
public void StartGame_WhenGameRunsThrough_ReturnsGameState() { // arrange var mockGame = BuildMockGame(); mockBoot .Setup(x => x.Boot<LinqGame>(It.IsAny<RulesBase>())) .Returns(mockGame.Object); var settings = new GameSettingsModel { LifeForm = LifeForm.Empty, NumberOfGenerations = 30, Rules = Rule.Standard }; // act hub.StartGame(settings); // assert mockBoot.Verify( x => x.Boot<LinqGame>(It.IsAny<RulesBase>()), Times.Once()); mockGame.Verify( x => x.InitializeFrom(It.IsAny<int[][]>()), Times.Once()); mockGame.Verify( x => x.RunThrough(It.IsAny<int>()), Times.Once()); clients.Verify( x => x.DisplayResults(It.Is<GameBase>(r => r == mockGame.Object)), Times.Once()); }
private static void InitGameSettings() { gameSettings = new GameSettingsModel(GetPlayerSettingsFloatList("GameSettings", 6)); }
public GameServices() { GameSettings = new GameSettingsModel(); }
public GameServices(GameSettingsModel gameSettings) { GameSettings = gameSettings; }