public Views.Game.Game LoadGame(MainVM vm, string fileName) { var ret = new Views.Game.Game(vm); ret.UpdateWithLogs(JsonConvert.DeserializeObject <GameEvent[]>(File.ReadAllText(fileName))); return(ret); }
public void ToggleTimer(Views.Game.Game g) { var ev = new GameEvent() { Type = g.IsGameRunning?GameEventType.TimerStop:GameEventType.TimerStart, Timestamp = DateTime.UtcNow, Gametime = g.TimeElapsed, }; g.UpdateWithLogs(ev); }
public void SetObjective(Views.Game.Game g, string objectiveName) { var ev = new GameEvent() { Type = GameEventType.SetObjective, Timestamp = DateTime.UtcNow, Gametime = g.TimeElapsed, Parameters = JToken.FromObject(objectiveName) }; g.UpdateWithLogs(ev); }
public void ExhaustPlanets(Views.Game.Game g) { var models = g.SelectedUser.Planets.AllItems.Where(e => e.IsSelected).ToArray(); if (!models.Any()) { return; } var ev = new GameEvent() { Type = GameEventType.ExhaustPlanets, Timestamp = DateTime.UtcNow, Gametime = g.TimeElapsed, Parameters = JToken.FromObject(models.Select(e => e.Model.Name)) }; g.UpdateWithLogs(ev); }
public Views.Game.Game NewGame(string[] userNames) { var ret = new Views.Game.Game(); var ev = new GameEvent() { Type = GameEventType.GameStart, Timestamp = DateTime.UtcNow, Gametime = TimeSpan.Zero, Parameters = JObject.FromObject(new GameStartParameter() { PlanetCards = PlanetCards, ObjectiveCards = ObjectiveCards, UserNames = userNames }) }; ret.UpdateWithLogs(ev); return(ret); }
public void RefreshPlanets(Views.Game.Game g) { var window = new PlanetSelectorWindow(new PlanetSelectorVM(g, true, true, new List <PlanetVM>())); window.ShowDialog(); if (window.ReturnCards?.Any() != true) { return; } var ev = new GameEvent() { Type = GameEventType.RefreshPlanets, Timestamp = DateTime.UtcNow, Gametime = g.TimeElapsed, Parameters = JToken.FromObject(window.ReturnCards.Select(e => e.Name)) }; g.UpdateWithLogs(ev); }
public void AssignPlanets(Views.Game.Game g) { var window = new PlanetSelectorWindow(new PlanetSelectorVM(g, false, false, g.SelectedUser.Planets.AllItems.ToList())); window.ShowDialog(); if (window.ReturnCards == null) { return; } var allUserPlanets = g.Users.SelectMany(e => e.Planets.AllItems).ToList(); var existingOccupations = window.ReturnCards.Where(e => allUserPlanets.Exists(u => u.Model.Name.Equals(e.Name, StringComparison.CurrentCultureIgnoreCase))) .ToList(); if (existingOccupations.Any()) { if (MessageBox.Show( string.Join("\r\n", existingOccupations.Select(e => $"{e.Name} belongs to {g.Users.First(u => u.Planets.AllItems.Any(p => p.Model.Name.Equals(e.Name, StringComparison.InvariantCultureIgnoreCase))).Name}")) + "\r\nAre you sure to continue?", "The following planets are already occupied.", MessageBoxButton.YesNo) == MessageBoxResult.No) { return; } } var ev = new GameEvent() { Type = GameEventType.AssignPlanets, Timestamp = DateTime.UtcNow, Gametime = g.TimeElapsed, Parameters = JToken.FromObject(new AssignPlanetsParameter() { TargetUser = g.SelectedUser.Name, TargetPlanets = window.ReturnCards.Select(e => e.Name).ToArray() }) }; g.UpdateWithLogs(ev); }
public Views.Game.Game NewGame(MainVM vm, string[] userNames) { var ret = new Views.Game.Game(vm); var ev = new GameEvent() { Type = GameEventType.GameStart, Timestamp = DateTime.UtcNow, Gametime = TimeSpan.Zero, Parameters = JObject.FromObject(new GameStartParameter() { PlanetCards = PlanetCards, ObjectiveCards = ObjectiveCards, Users = vm.Usernames.Select(e => new GameStartUser() { Color = e.Color.Color, UserName = e.UserName }).ToArray() }) }; ret.UpdateWithLogs(ev); return(ret); }
public void AssignObjectives(Views.Game.Game g) { var window = new ObjectiveSelectorWindow(new ObjectiveSelectorVM(g, g.SelectedUser.FinishedObjectives.ToList(), g.Objectives.ToList())); window.ShowDialog(); if (window.ReturnCards == null) { return; } var ev = new GameEvent() { Type = GameEventType.CompleteObjective, Timestamp = DateTime.UtcNow, Gametime = g.TimeElapsed, Parameters = JToken.FromObject(new CompleteObjectiveParameter() { UserName = g.SelectedUser.Name, Objectives = window.ReturnCards.Select(e => e.Name).ToArray() }) }; g.UpdateWithLogs(ev); }