/// <summary> /// Обновление объектов /// </summary> public void Update() { foreach (BaseObject obj in _objs) { obj.Update(); } foreach (Bullet b in _bullets) { b.Update(); } _heal?.Update(); for (var i = 0; i < _asteroids.Count; i++) { if (_asteroids[i] == null) { continue; } _asteroids[i].Update(); if (_ship.Collision(_asteroids[i])) { var rnd = new Random(); _ship.EnergyLow(rnd.Next(1, 10)); WorkData("Корабль столкнулся с астероидом и получил урон", journalRecords.JournalWrite); System.Media.SystemSounds.Asterisk.Play(); } if (_ship.Energy <= 0) { _ship.Die(); } for (int j = 0; j < _bullets.Count; j++) { if (_asteroids[i] != null && _bullets[j].Collision(_asteroids[i])) { WorkData("Уничтожен астероид", journalRecords.JournalWrite); System.Media.SystemSounds.Hand.Play(); _asteroids.RemoveAt(i); _asteroids[j].power--; _bullets.RemoveAt(j); score++; break; } } if (_heal != null && _ship.Collision(_heal)) { WorkData($"Корабль отлечился на {_heal.power} хитов", journalRecords.JournalWrite); _ship.EnergyLow(_heal.power); } if (_asteroids.Count == 0) { AsteroidLoad(++k); } } }
public static void Update() { ConsoleMessage <string> strTarget = new ConsoleMessage <string>(StringTarget); //foreach (BaseObject obj in objs) obj.Update(); bullet?.Update(); heal?.Update(); if (heal != null && heal.Collision(ship)) { if (ship.Energy <= 90) { ship?.EnergyHeal(10); strTarget("Ship is healed"); } else { ship.EnergyClear(); } Random rnd = new Random(); heal = new Heal(new Point(Game.Width, rnd.Next(20, 1000)), new Point(rnd.Next(3, 10), rnd.Next(3, 10)), new Size(5, 5)); } for (var i = 0; i < asteroids.Length; i++) { if (asteroids[i] == null) { continue; } asteroids[i].Update(); if (bullet != null && bullet.Collision(asteroids[i])) { System.Media.SystemSounds.Hand.Play(); asteroids[i] = null; bullet = null; Count++; strTarget("Asteroid is hit"); continue; } if (!ship.Collision(asteroids[i])) { continue; } var rnd = new Random(); ship?.EnergyLow(rnd.Next(1, 10)); strTarget("Ship is hit"); System.Media.SystemSounds.Asterisk.Play(); if (ship.Energy <= 0) { ship?.Die(); } } }