public void ShootAt(Point target) { if (target.Equals(GamePlayer.Location)) { GamePlayer.LoseHealth(); return; } for (int i = 0; i < Terrain.Count; i++) { if (target.Equals(Terrain[i].Location)) { Terrain.RemoveAt(i); Console.SetCursorPosition(target.X, target.Y); Console.Write(' '); return; } } for (int i = 0; i < Monsters.Count; i++) { if (target.Equals(Monsters[i].Location)) { Monsters.RemoveAt(i); Console.SetCursorPosition(target.X, target.Y); Console.Write(' '); return; } } }
public void SpawnMonsters(int nrMonsters) { // Divide game field in sections based on nrMonsters and place a monster randomly in each section int dY = GameWidth / nrMonsters; for (int i = 0; i < nrMonsters; i++) { Monster monster; // Pick a type at random int type = rand.Next(0, 2); if (type == 0) { monster = new Monster(Point.RandomPoint(Margin.X + 1, Margin.X + GameWidth * 2 - 1, Margin.Y + 1 + i * dY, Margin.Y + dY - 1 + i * dY), 'M'); } else { monster = new RockDestroyer(Point.RandomPoint(Margin.X + 1, Margin.X + GameWidth * 2 - 1, Margin.Y + 1 + i * dY, Margin.Y + dY - 1 + i * dY), 'D'); } for (int r = 0; r < Terrain.Count; r++) { if (monster.Location.Equals(Terrain[r].Location)) { Terrain.RemoveAt(r); r--; } } Monsters.Add(monster); } }