public Stars(Rectangle screenBounds, int count) { stars = new Star[count]; for (int i = 0; i < count; i++) { stars[i] = new Star(screenBounds); } }
static void Main() { var stars = new List <Star>(); Console.Title = "Space War"; Console.WindowLeft = Console.WindowTop = 0; Console.WindowHeight = Console.BufferHeight = 50; //60 Console.WindowWidth = Console.BufferWidth = 160; //180 Console.CursorVisible = false; int enemies = 2; int hardness = 4; Console.WriteLine("Choose Your Destiny!\n1) New Game\n2) Exit"); int choice = Convert.ToInt32(Console.ReadLine()); //заполняем рабочую зону if (choice == 1) { Player.Life = 5; Console.Clear(); reset(); for (byte i = 0; i < Console.BufferHeight; i++) { for (byte j = 0; j < Console.BufferWidth; j++) { Buf.Buffer[i, j] = 'v'; } } Console.SetCursorPosition(0, Console.BufferHeight - 1); Console.BackgroundColor = ConsoleColor.Red; Console.Write("TOTAL LIVES: " + Player.Life); for (byte i = 0; i < 15; i++) { stars.Add(new Star()); } CreateSwarm(enemies); Ship.MovePlayer(Player, 90, 38); while (true)//let's go { if (Swarm.Count == 0) { foreach (var pp in Zaps) { PlayerProjectile.Clear(pp); } foreach (var prj in RainOfProjectiles) { Projectile.Clear(prj); } Zaps.Clear(); RainOfProjectiles.Clear(); Player.Life++; Console.SetCursorPosition(0, Console.BufferHeight - 1); Console.BackgroundColor = ConsoleColor.Red; Console.Write("TOTAL LIVES: " + Player.Life); if (hardness > 1) { hardness--; } CreateSwarm(++enemies); } Star.GoStars(stars); if (Player.Life == 0) { break; } foreach (var enemy in Swarm) { Ship.Move(enemy, R.Next(-2, 3), R.Next(-2, 3)); if (R.Next(0, enemy.Life * hardness) == 0 && enemy.Delay == 0) { RainOfProjectiles.Add(new Projectile(R.Next(1, 4), R.Next(1, 4), enemy.Posx + 4, enemy.Posy + 8)); } enemy.Delay++; if (enemy.Delay == 4) { enemy.Delay = 0; } } for (byte i = 0; i < 5 - hardness; i++) { if (Projectile.Fire(RainOfProjectiles))//front impact of projectile and player { Destroyed(); } } int delay = 0; for (byte i = 0; i < 7; i++) { bool destroyed = false; switch (Buf.Reader()) { case 3: for (byte ii = 0; ii < 7; ii++) { if (Buf.Buffer[Player.Posy + ii, Player.Posx + 9] == 'p') { destroyed = true; } } Ship.MovePlayer(Player, 2, 0); break; case 4: for (byte ii = 0; ii < 7; ii++) { if (Buf.Buffer[Player.Posy + ii, Player.Posx - 2] == 'p') { destroyed = true; } } Ship.MovePlayer(Player, -2, 0); break; case 5: if (delay == 0 && Zaps.Count < 2) { Zaps.Add(new PlayerProjectile(1, 3, Player.Posx + 1, Player.Posy - 1)); Zaps.Add(new PlayerProjectile(1, 3, Player.Posx + 5, Player.Posy + 1)); // - 1)); delay++; } break; case 6: //test if (delay == 0 && Zaps.Count < 2) { Zaps.Add(new PlayerProjectile(1, 4, Player.Posx + 3, Player.Posy + 1)); delay++; } break; } if (PlayerProjectile.Fire(Zaps))//or if?! { KillEnemy(); } if (destroyed) { Destroyed(); } if (delay > 0) { delay++; } if (delay == 2000) { delay = 0; } Thread.Sleep(5); } } reset(); const string msg = "Вы храбро сражались, вам было тяжело...настолько тяжело, что вас победили, это печально, но факт...удачи в следующий раз D:"; Console.Clear(); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(); foreach (var c in msg) { Console.Write(c); Thread.Sleep(100); } Console.ReadLine(); Console.Clear(); enemies = 2; Swarm.Clear(); RainOfProjectiles.Clear(); Zaps.Clear(); Ship.MovePlayer(Player, 90, 38); Main(); } if (choice == 2) { Environment.Exit(0); } }