public GameUnit(MatchUnit matchUnit) { Id = matchUnit.Id; UnitId = matchUnit.UnitId; PlayerId = matchUnit.PlayerId; MatchId = matchUnit.MatchId; Name = matchUnit.Name; MaxHealth = matchUnit.MaxHealth; Health = matchUnit.Health; Row = matchUnit.Row; Column = matchUnit.Col; }
/// <summary> /// Instantiate a match in the DB /// </summary> /// <param name="player1">Player1 is rebels</param> /// <param name="player2">Player2 is empire</param> public static Guid CreateMatch(Guid player1, Guid player2) { Match m = new Match { Id = Guid.NewGuid(), Player1 = player1, Player2 = player2, Turn = player1 }; CloudWarsDB.Matches.Insert(m); //create the match units MatchUnit mu; var rebels = CloudWarsDB.VanillaUnits.Where(v=> v.IsRebel); var empire = CloudWarsDB.VanillaUnits.Where(v=> !v.IsRebel); foreach (var v in rebels) { mu = new MatchUnit { MatchId = m.Id, PlayerId = player1, UnitId = v.Id, MaxHealth = v.MaxHealth, Health = v.MaxHealth, Name = v.Name, Id = Guid.NewGuid(), Col = 0, Row = 0 }; CloudWarsDB.MatchUnits.Insert(mu); } foreach (var v in empire) { mu = new MatchUnit { MatchId = m.Id, PlayerId = player2, UnitId = v.Id, MaxHealth = v.MaxHealth, Health = v.MaxHealth, Name = v.Name, Id = Guid.NewGuid(), Col = 0, Row = 0 }; CloudWarsDB.MatchUnits.Insert(mu); } return m.Id; }