private void AddRoundsToGame(ScoreTrackerDatabase database) { for (var i = 1; i <= Game.TotalRounds; i++) { var round = new Round { RoundCount = i, IsCurrent = i == 1, Game = Game, GameId = Game.Id }; database.Insert(round); foreach (var player in Game.Players) { var turn = new Turn { Player = player, Round = round, RoundId = round.Id, PlayerId = player.Id, CurrentRange = round.IsCurrent ? 10 : 0 }; round.Turns.Add(turn); database.Insert(turn); } Game.Rounds.Add(round); } }
private void StartScoreTrackerGame_OnClicked(object sender, EventArgs e) { var count = int.Parse(PlayerCount.Text); var game = new Game(); var database = new ScoreTrackerDatabase(); var defaultPlayer = database.GetDefaultPlayer() ?? new Player { NickName = "Player1", IsDefault = true }; database.Insert(defaultPlayer); game.Players.Add(defaultPlayer); for (var i = 1; i < count; i++) { var name = "Player" + (i + 1); var player = new Player { NickName = name }; game.Players.Add(player); database.Insert(player); } game.IsCurrent = true; game.TotalRounds = int.Parse(RoundCount.Text); var addPlayerPage = new AddPlayersX { BindingContext = game }; Navigation.PushModalAsync(addPlayerPage); }
private void StartButton_OnClicked(object sender, EventArgs e) { var database = new ScoreTrackerDatabase(); if (Game.Id <= 0) { database.Insert(Game); } if (!Game.Rounds.Any()) { AddRoundsToGame(database); } database.Save(Game); var firstRound = Game.Rounds.FirstOrDefault(r => r.IsCurrent); var gameRounds = new GameRoundsX { BindingContext = firstRound }; Navigation.PushModalAsync(gameRounds); }