private void AddUnit(Team team, int worldX, int worldY) { if (World.Army.GetUnit(worldY, worldX) == null) { if (radioButtonUnitSwords.Checked) { WorldGen.CreateUnit(UnitType.SwordsMan, team, worldY, worldX); } if (radioButtonUnitHorse.Checked) { WorldGen.CreateUnit(UnitType.HorseMan, team, worldY, worldX); } if (radioButtonUnitArcher.Checked) { WorldGen.CreateUnit(UnitType.Archer, team, worldY, worldX); } } }
public static void LoadUnitsFromFile(this WorldsGenerator worldGen, string fname, bool android = false) { if (android) { var path = Environment.GetFolderPath(Environment.SpecialFolder.Personal); fname = Path.Combine(path, fname); } var lines = File.ReadAllLines(fname, Encoding.Unicode); if (lines.Length < 0) { return; } var world = worldGen.GetWorld(); world.Army.Clear(); int y = 0; foreach (var line in lines) { int x = 0; if (y >= world.Length) { break; } foreach (var c in line) { if (x >= world.Width) { break; } switch (c) { case 'a': worldGen.CreateUnit(UnitType.Archer, Team.Blue, y, x); break; case 's': worldGen.CreateUnit(UnitType.SwordsMan, Team.Blue, y, x); break; case 'h': worldGen.CreateUnit(UnitType.HorseMan, Team.Blue, y, x); break; case 'A': worldGen.CreateUnit(UnitType.Archer, Team.Red, y, x); break; case 'S': worldGen.CreateUnit(UnitType.SwordsMan, Team.Red, y, x); break; case 'H': worldGen.CreateUnit(UnitType.HorseMan, Team.Red, y, x); break; case ' ': break; default: throw new InvalidOperationException("Unknown unit type " + c); } x++; } y++; } }