private void AddUnits(int numUnits, string faction) { for (int i = 0; i < numUnits; i++) { int x = random.Next(0, map.width); int y = random.Next(0, map.height); Unit unit; if (faction != WIZARDS) { int unitType = random.Next(0, 2); if (unitType == 0) { unit = new MeleeUnit(x, y, faction); } else { unit = new RangedUnit(x, y, faction); } } else { unit = new WizardUnit(x, y, faction); } manager.AddUnit(unit); } }
/// public void InitializeUnits() { units = new Unit[randomNumberOfUnits]; for (int i = 0; i < units.Length; i++) //for assigning random positions { int x = GameEngine.random.Next(0, mapSize); //generate x and y values int y = GameEngine.random.Next(0, mapSize); int factionIndex = GameEngine.random.Next(0, 2); //decides blue or red team int nameIndex = GameEngine.random.Next(0, 2); //CHANGED from 5 to 2 int unitType = GameEngine.random.Next(0, 3); //decides ranged or melee while (map[x, y] != null) { x = GameEngine.random.Next(0, mapSize); y = GameEngine.random.Next(0, mapSize); //makes sure map is unoccupied } if (unitType == 0) { units[i] = new MeleeUnit(x, y, factions[factionIndex] /*nameUnits1[nameIndex]*/); } else if (unitType == 1) { units[i] = new RangedUnit(x, y, factions[factionIndex] /*nameUnits2[nameIndex]*/); } else { units[i] = new WizardUnit(x, y, factions[2]); } map[x, y] = units[i].Faction[0] + "/" + units[i].Symbol; //returns the team and the unit type } }