public static void PopulateTable(CivilizationDbContext _db) { Random random = new Random(); for (var i = 1; i < 101; i++) { BoardPiece newLand = new BoardPiece { BaseHere = false }; var resource = random.Next(0, 100); if (resource < 20) { newLand.ResourceHere = true; newLand.ResourceType = "Wood"; } else if (resource < 30) { newLand.ResourceHere = true; newLand.ResourceType = "Metal"; } else if (resource < 45) { newLand.ResourceHere = true; newLand.ResourceType = "Stone"; } else if (resource < 50) { newLand.ResourceHere = true; newLand.ResourceType = "Gold"; } else { newLand.ResourceHere = false; newLand.ResourceType = "None"; } //Set Player to starting piece if (i == 55) { newLand.ResourceHere = false; newLand.ResourceType = "None"; newLand.PlayerHere = true; } else { newLand.PlayerHere = false; } _db.BoardPieces.Add(newLand); _db.SaveChanges(); } }
public static void PopulateTech(CivilizationDbContext db) { GamePiece inventFire = new GamePiece { Name = "Discover Fire", Type = "Tech", Count = 1, TurnCost = 2 }; Resource fireResource1 = new Resource { Name = "Wood", Cost = 2, GamePiece = inventFire }; Resource fireResource2 = new Resource { Name = "Stone", Cost = 1, GamePiece = inventFire }; db.GamePieces.Add(inventFire); db.Resources.Add(fireResource1); db.Resources.Add(fireResource2); db.SaveChanges(); }
public static bool RemoveResourcesFromPlayer(Resource[] resources, Player player, CivilizationDbContext db) { bool success = true; var woodCost = 0; var stoneCost = 0; var metalCost = 0; var goldCost = 0; for (var i = 0; i < resources.Length; i++) { if (resources[i].Name == "Wood") { if ((player.Wood - resources[i].Cost) >= 0) { woodCost = resources[i].Cost; } else { success = false; } } else if (resources[i].Name == "Stone") { if ((player.Stone - resources[i].Cost) >= 0) { stoneCost = resources[i].Cost; } else { success = false; } } else if (resources[i].Name == "Metal") { if ((player.Metal - resources[i].Cost) >= 0) { metalCost = resources[i].Cost; } else { success = false; } } else if (resources[i].Name == "Gold") { if ((player.Gold - resources[i].Cost) >= 0) { goldCost = resources[i].Cost; } else { success = false; } } } if (success == true) { player.Wood -= woodCost; player.Stone -= stoneCost; player.Metal -= metalCost; player.Gold -= goldCost; db.Entry(player).State = EntityState.Modified; db.SaveChanges(); } return(success); }