private void KeypressListener() { DateTime lastDrawnProjectile = DateTime.MinValue; ConsoleKey key; do { /* * while (!Console.KeyAvailable) { } */ key = Console.ReadKey(true).Key; switch (key) { case ConsoleKey.LeftArrow: { if (Player.Move(-1)) { Player.Draw(); } break; } case ConsoleKey.RightArrow: { if (Player.Move(1)) { Player.Draw(); } break; } case ConsoleKey.Spacebar: { if (DateTime.Now > lastDrawnProjectile.AddSeconds(1)) { var projectile = new Projectile(Console.WindowHeight - 3, Player.Position, 1); Projectiles.Add(projectile); projectile.Draw(); lastDrawnProjectile = DateTime.Now; } break; } } } while (key != ConsoleKey.Escape); Environment.Exit(0); }
public void Shoot() { Random rnd = new Random(); int r = rnd.Next(Enemies.FindAll(x => x.IsAlive).Count); Enemy randomEnemy = Enemies.FindAll(x => x.IsAlive)[r]; var projectile = new Projectile( FleetPositionY + randomEnemy.RelativePositionY, FleetPositionX + randomEnemy.RelativePositionX, -1 ); Game.Projectiles.Add(projectile); projectile.Draw(); }