public static void Update() { foreach (BaseObject obj in _objs) { obj.Update(); } foreach (Bullet b in _bullets) { b.Update(); } for (var i = 0; i < _asteroids.Count; i++) { if (_asteroids[i] == null) { continue; } _asteroids[i].Update(); for (int j = 0; j < _bullets.Count; j++) { if (_asteroids[i] != null && _bullets[j].Collision(_asteroids[i])) { System.Media.SystemSounds.Hand.Play(); _asteroids[i] = null; _bullets.RemoveAt(j); j--; } } if (_asteroids[i] == null || !_ship.Collision(_asteroids[i])) { continue; } _ship.HPLow(Rnd.Next(1, 10)); System.Media.SystemSounds.Asterisk.Play(); if (_ship.HP <= 0) { _ship.Die(); } } foreach (MedicalKit a in medkit) { a.Update(); } /*for (var i = 0; i < medkit.Count; i++) * { * medkit[i].Update(); * if (medkit[i] == null) continue; * medkit[i].Update(); * for (int j = 0; j < medkit.Count; j++) * if (medkit[i] != null && _ship.Collision(medkit[i])) * { * System.Media.SystemSounds.Question.Play(); * medkit[i] = null; * } * if (medkit[i] == null || !_ship.Collision(medkit[i])) continue; * _ship.HPRise(Rnd.Next(1, 20)); * System.Media.SystemSounds.Asterisk.Play(); * }*/ }
// Method updates all objects on the gamefield and handle collisions, if it happens, each tick of the timer public static void Update() { foreach (Star star in _stars) { star.Update(); } foreach (Bullet bul in _bullets) { bul.Update(); } if (_asteroids.Count == 0) { CreateAsteroids(); } for (var i = 0; i < _asteroids.Count; i++) { _asteroids[i].Update(); if (_ship.Collision(_asteroids[i])) { _ship.EnergyLow(Rnd.Next(1, 10)); System.Media.SystemSounds.Asterisk.Play(); if (_ship.Energy <= 0) { _ship.Die(); } } for (int j = 0; j < _bullets.Count; j++) { if (_bullets[j].Collision(_asteroids[i])) { System.Media.SystemSounds.Hand.Play(); _asteroids.RemoveAt(i); _bullets.RemoveAt(j); j--; _score++; break; } } } _firstAidKit.Update(); if (_firstAidKit != null && _firstAidKit.Collision(_ship)) { _ship.EnergyHigh(1); } }
/// <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); } } }
static public void Update() { foreach (BaseObject obj in objs) { obj.Update(); } foreach (Bullet b in bullet) { if (b != null) { b.Update(); } } for (int i = 0; i < asteroids.Count; i++) { if (asteroids[i] != null) { asteroids[i].Update(); for (int j = 0; j < bullet.Count; j++) { if (asteroids[i] != null && bullet[j].Collision(asteroids[i])) { score += 1; bullet.RemoveAt(j); buffer.Graphics.DrawString("Score: " + score, SystemFonts.DefaultFont, Brushes.White, new Point(80, 10)); Console.WriteLine("Little asteriod killed. Score: {0}", score); j--; asteroids[i] = null; continue; } } if (asteroids[i] != null && ship.Collision(asteroids[i])) { asteroids[i].Reset(); ship.Reset(); ship.Health -= 10; Console.WriteLine("Collision with little asteroid. Health: {0}", ship.Health); if (ship.Health <= 0) { ship.Die(); Console.WriteLine("Game Over!!"); } } } else { asteroids.RemoveAt(i); i--; Console.WriteLine("Small asteroids left: {0}", asteroids.Count); } } for (int i = 0; i < asteroidsBig.Count; i++) { if (asteroidsBig[i] != null) { asteroidsBig[i].Update(); for (int j = 0; j < bullet.Count; j++) { if (asteroidsBig[i] != null && bullet[j].Collision(asteroidsBig[i])) { asteroidsBig[i].Power -= bullet[j].Damage; bullet.RemoveAt(j); if (asteroidsBig[i].Power == 0) { asteroidsBig[i] = null; score += 3; Console.WriteLine("Big asteriod killed. Score: {0}", score); } buffer.Graphics.DrawString("Score: " + score, SystemFonts.DefaultFont, Brushes.White, new Point(80, 10)); j--; continue; } } if (asteroidsBig[i] != null && ship.Collision(asteroidsBig[i])) { asteroidsBig[i].Reset(); ship.Reset(); ship.Health -= 30; Console.WriteLine("Collision with Big asteroid. Health: {0}", ship.Health); if (ship.Health <= 0) { ship.Die(); Console.WriteLine("Game Over!!"); } } } else { asteroidsBig.RemoveAt(i); i--; Console.WriteLine("Big asteroids left: {0}", asteroidsBig.Count); } } for (int i = 0; i < nebula.Count; i++) { if (nebula[i] != null) { nebula[i].Update(); for (int j = 0; j < bullet.Count; j++) { if (nebula[i] != null && bullet[j].Collision(nebula[i])) { nebula[i].Power -= bullet[j].Damage; bullet.RemoveAt(j); if (nebula[i].Power == 0) { nebula[i] = null; score += 5; Console.WriteLine("Big asteriod killed. Score: {0}", score); } buffer.Graphics.DrawString("Score: " + score, SystemFonts.DefaultFont, Brushes.White, new Point(80, 10)); j--; continue; } } if (nebula[i] != null && ship.Collision(nebula[i])) { nebula[i].Reset(); ship.Reset(); ship.Health -= 50; Console.WriteLine("Collision with Big asteroid. Health: {0}", ship.Health); if (ship.Health <= 0) { ship.Die(); Console.WriteLine("Game Over!!"); } } } else { nebula.RemoveAt(i); i--; Console.WriteLine("Nebula left: {0}", nebula.Count); } } for (int i = 0; i < boss.Count; i++) { if (boss[i] != null) { boss[i].Update(); for (int j = 0; j < bullet.Count; j++) { if (boss[i] != null && bullet[j].Collision(boss[i])) { boss[i].Power -= bullet[j].Damage; bullet.RemoveAt(j); if (boss[i].Power == 0) { boss[i] = null; score += 20; Console.WriteLine("Boss killed. Score: {0}", score); waveCount = 0; } buffer.Graphics.DrawString("Score: " + score, SystemFonts.DefaultFont, Brushes.White, new Point(80, 10)); j--; continue; } } if (boss[i] != null && ship.Collision(boss[i])) { ship.Reset(); boss[i].Reset(); ship.Health -= 70; buffer.Graphics.DrawString("Health: " + ship.Health, SystemFonts.DefaultFont, Brushes.White, new Point(10, 10)); Console.WriteLine("Collision with Boss. Health: {0}", ship.Health); if (ship.Health <= 0) { ship.Die(); Console.WriteLine("Game Over!!"); } } } else { boss.RemoveAt(i); i--; Console.WriteLine("Boss left: {0}", boss.Count); } } if (ship.Collision(medkit)) { ship.Health += medkit.Restore; buffer.Graphics.DrawString("Health: " + ship.Health, SystemFonts.DefaultFont, Brushes.White, new Point(10, 10)); Console.WriteLine("Collected MedKit. Health: {0}", ship.Health); medkit.Reset(); } medkit.Update(); ship.Update(); if (asteroids.Count == 0 && asteroidsBig.Count == 0 && nebula.Count == 0 && boss.Count == 0) { waveCount++; if (waveCount == 3) { BossCreate(); } if (waveCount < 3) { Reload(asteroidsCount, asteroidsBigCount, nebulaCount, waveCount); } } }
public static void Update() { foreach (BaseObject obj in _objs) { obj.Update(); } //foreach (Asteroid a in _asteroids) //{ // a.Update(); // //if (a.Collision(_bullet)) // //{ // // System.Media.SystemSounds.Hand.Play(); // // // регенирируем объекты // // a.Ressurect(); // // _bullet.Ressurect(); // //} //} foreach (Heal a in _heals) { a.Update(); if (a.Collision(_ship)) { System.Media.SystemSounds.Question.Play(); // регенирируем объекты _ship.Heal(25); a.Ressurect(); } } //_bullet?.Update(); foreach (Bullet b in _bullets) { b.Update(); } if (_asteroids.Count == 0) { InitAster(++_aCount); // создание астероидов теперь только тут } bool aster_removed = false; for (var i = 0; i < _asteroids.Count; i++) { if (_asteroids[i] == null) { continue; } _asteroids[i].Update(); aster_removed = false; for (int j = 0; j < _bullets.Count; j++) { if (_asteroids[i] != null && _bullets[j].Collision(_asteroids[i])) { System.Media.SystemSounds.Hand.Play(); _asteroids.RemoveAt(i); _bullets.RemoveAt(j); i--; j--; Score++; aster_removed = true; break; } } if (aster_removed) { continue; } if (_asteroids[i] == null || !_ship.Collision(_asteroids[i])) { continue; } _ship?.EnergyLow(10); System.Media.SystemSounds.Asterisk.Play(); if (_ship.Energy <= 0) { _ship.Die(); } _asteroids.RemoveAt(i); //if (_bullet != null && _bullet.Collision(_asteroids[i])) //{ // System.Media.SystemSounds.Hand.Play(); // _asteroids[i] = null; // _bullet = null; // Score++; // continue; //} //if (!_ship.Collision(_asteroids[i])) continue; ////var rnd = new Random(); //_asteroids[i].Loggin("Ship hit!"); //System.Media.SystemSounds.Asterisk.Play(); //_asteroids[i] = null; //if (_ship.Energy <= 0) _ship?.Die(); } }
/// <summary> /// метод вывода обновленного положения объектов в форму /// </summary> public static void Update() { foreach (BaseObject obj in _objs) { obj.Update(); } foreach (Bullet b in _bullets) { b?.Draw(); } if (pharmacy != null) { if (_ship.Collision(pharmacy)) { System.Media.SystemSounds.Exclamation.Play(); _ship.EnergeUp(rnd.Next(1, 10)); pharmacy = null; i = 0; } } for (int i = 0; i < _asteroids.Count; i++) { if (_asteroids[i] == null) { continue; } _asteroids[i].Update(); for (int j = 0; j < _bullets.Count; j++) { if (_asteroids[i] != null && _bullets[j].Collision(_asteroids[i])) { System.Media.SystemSounds.Hand.Play(); _asteroids[i] = null; _bullets.RemoveAt(j); j--; count++; LogEvent($"{DateTime.Now.ToString()} уничтожен {_asteroids} !!!"); } } if (_asteroids[i] == null || !_ship.Collision(_asteroids[i])) { continue; } else if (_asteroids[i] != null && _ship.Collision(_asteroids[i])) { _ship?.EnergeLow(rnd.Next(1, 10)); System.Media.SystemSounds.Asterisk.Play(); _asteroids.RemoveAt(i); } if (_ship.Energy <= 0) { _ship.Die(); LogEvent($"{DateTime.Now.ToString()} уничтожен {_ship} !!!"); } } if (_asteroids == null) { List_length++; for (int i = 0; i < List_length; i++) { int r = rnd.Next(0, 50); _asteroids.Add(new Asteroid(new Point(1000, rnd.Next(0, maxValue: Height)), new Point(-r / 5, r), new Size(r, r))); } } #region HW3 // 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++; // LogEvent($"{DateTime.Now.ToString()} уничтожен {_asteroids} !!!"); // continue; // } // if (_ship.Collision(_asteroids[i])) // { // _ship?.EnergeLow(rnd.Next(1, 10)); // System.Media.SystemSounds.Asterisk.Play(); // } // if (_ship.Energy <= 0) // { // _ship.Die(); // LogEvent($"{DateTime.Now.ToString()} уничтожен {_ship} !!!"); // } //} #endregion #region HW2 //foreach (Asteroid a in _asteroids) //{ // a.Update(); // if (a.Collision(_bullet)) // { SystemSounds.Hand.Play(); // a.Regeneretion(); // _bullet.Regeneretion(); // } // _bullet.Update(); //} #endregion }
/// <summary> /// Обновление расположения нашего обьекта на экране /// </summary> public static void Update() { int points = 0; int r = rnd.Next(10, 50); foreach (BaseObject obj in _objs) { obj.Update(); } foreach (Bullet b in _bullets) { b.Update(); } foreach (Asteroid a in _asteroids) { a.Update(); } _heal?.Update(); _planets?.Update(); if (_ship.Energy <= 0) { _ship?.Die(); } if (_ship.Collision(_heal)) { BeHealed(); } if (_ship.flag == true) { _ship.EnergyLow(0.05f); } for (int i = 0; i < _asteroids.Count; i++) { if (_asteroids != null && _ship.Collision(_asteroids[i])) { str = "ship"; delLog.Dmg(str); _ship?.EnergyLow(rnd.Next(1, 10)); SystemSounds.Asterisk.Play(); _asteroids.RemoveAt(i); str = "0"; delLog.Del(str); continue; } for (int j = 0; j < _bullets.Count; j++) { if (_bullets[j].Collision(_heal) || _ship.Collision(_heal)) {//РЕДАКТИРОВАТЬ НА УНИЧТОЖЕНИЕ ОБЬЕКТА ПРИ СТРЕЛЬБЕ BeHealed(); _bullets.RemoveAt(j); j--; continue; } try { if (_bullets != null && _asteroids != null && _bullets[j].Collision(_asteroids[i])) { if (_asteroids == null) { continue; } if (_asteroids[i].Power == 0) { points = rnd.Next(1, 30); score += points; delLog.Del(points.ToString()); _bullets.RemoveAt(j); _asteroids.RemoveAt(i); continue; } _bullets.RemoveAt(j); j--; SystemSounds.Hand.Play(); _asteroids[i].Power--; continue; } } catch (Exception ex) { Console.WriteLine(ex); } } continue; } if (_asteroids.Count == 0) { AsteroidsCount++; for (int i = 0; i < AsteroidsCount; i++) { r = rnd.Next(10, 50); _asteroids.Add(new Asteroid(new Point(Width, rnd.Next(0, 800)), new Point(-r / 5, r), new Size(r, r))); str = "Asteroid"; delLog.Do(str); } } }
/// <summary> /// Обновляем объекты на экране /// </summary> public static void Update() { foreach (Bullet b in _bullets) { b.Update(); } for (var i = 0; i < _lasteroids.Count; i++) { if (_lasteroids[i] == null) { continue; } _lasteroids[i].Update(); if (_lasteroids[i].Collision(_ship)) { System.Media.SystemSounds.Asterisk.Play(); var rnd = new Random(); _ship?.EnergyLow(rnd.Next(10, 50)); _lasteroids[i].Pos.X = Width; _lasteroids[i].Pos.Y = Height; _log += ShipHit; if (_ship.Energy <= 0) { _ship?.Die(); } } for (int j = 0; j < _bullets.Count; j++) { if (_lasteroids[i] != null && _bullets[j].Collision(_lasteroids[i])) { System.Media.SystemSounds.Hand.Play(); _bullets.RemoveAt(j); _lasteroids.RemoveAt(i); score++; if (score > CurRec) { CurRec = score; } _log += Hit; j--; if (_lasteroids.Count == 0) { AsterCount++; mspeed++; CreateAsteroid(AsterCount, mspeed); } break; } } if (_medkit.Collision(_ship)) { System.Media.SystemSounds.Exclamation.Play(); _ship?.EnergyHigh(25); _medkit.Pos.X = Game.Width; _medkit.Pos.Y = rnd.Next(0, Game.Height); } } }