static void Main() { DrawPlayfield(); StarShip myStarShip = new StarShip(); List <Meteors> meteors = new List <Meteors>(); Random randomGenerator = new Random(); Player newPlayer = new Player(); Game newGame = new Game(); myStarShip.DrawShip(); newPlayer.UpdateLives(0); while (true) { myStarShip.Move(); //add a new meteor to the playfield depending on the frequency (lower value = higher freq) if (randomGenerator.Next(0, newGame.Frequency) == 0) { Meteors newMeteor = new Meteors(randomGenerator.Next(0, Console.WindowWidth - 3), '@', ConsoleColor.Red); meteors.Add(newMeteor); } if (randomGenerator.Next(0, 70) == 5) { Meteors newMeteor = new Meteors(randomGenerator.Next(0, Console.WindowWidth - 3), '+', ConsoleColor.Green); meteors.Add(newMeteor); } if (randomGenerator.Next(0, 70) == 5) { Meteors newMeteor = new Meteors(randomGenerator.Next(0, Console.WindowWidth - 3), '$', ConsoleColor.Yellow); meteors.Add(newMeteor); } if (randomGenerator.Next(0, 80) == 5) { Meteors newMeteor = new Meteors(randomGenerator.Next(0, Console.WindowWidth - 3), '#', ConsoleColor.White); meteors.Add(newMeteor); } for (int i = 0; i < meteors.Count; i++) { if (meteors[i].Y + 12 >= Console.WindowHeight) { meteors[i].ClearMeteorite(); meteors.Remove(meteors[i]); newPlayer.Score += 1; newPlayer.UpdateScore(); } meteors[i].Move(); //collision detection for (int j = 0; j < meteors[i].Shape.GetLength(0); j++) { for (int k = 0; k < myStarShip.Shape.GetLength(0); k++) { if (meteors[i].Shape[j, 0] == myStarShip.Shape[k, 0] && meteors[i].Shape[j, 1] == myStarShip.Shape[k, 1]) { if (meteors[i].Color == ConsoleColor.Red) { Console.Beep(); meteors[i].ClearMeteorite(); meteors.Remove(meteors[i]); newPlayer.UpdateLives(-1); } else if (meteors[i].Color == ConsoleColor.Green) { newPlayer.UpdateLives(1); meteors[i].ClearMeteorite(); meteors.Remove(meteors[i]); } else if (meteors[i].Color == ConsoleColor.Yellow) { newPlayer.Score += 50; meteors[i].ClearMeteorite(); meteors.Remove(meteors[i]); } else if (meteors[i].Color == ConsoleColor.White) { newGame.GameSpeed += 10; newGame.Frequency += 1; meteors[i].ClearMeteorite(); meteors.Remove(meteors[i]); } } } } } Thread.Sleep(newGame.GameSpeed); if (newPlayer.Lives == 0) { newPlayer.GameOver(); } } }
static void Main() { DrawPlayfield(); StarShip myStarShip = new StarShip(); List<Meteors> meteors = new List<Meteors>(); Random randomGenerator = new Random(); Player newPlayer = new Player(); Game newGame = new Game(); myStarShip.DrawShip(); newPlayer.UpdateLives(0); while (true) { myStarShip.Move(); //add a new meteor to the playfield depending on the frequency (lower value = higher freq) if (randomGenerator.Next(0, newGame.Frequency) == 0) { Meteors newMeteor = new Meteors(randomGenerator.Next(0, Console.WindowWidth - 3),'@',ConsoleColor.Red); meteors.Add(newMeteor); } if (randomGenerator.Next(0, 70) == 5) { Meteors newMeteor = new Meteors(randomGenerator.Next(0, Console.WindowWidth - 3),'+',ConsoleColor.Green); meteors.Add(newMeteor); } if (randomGenerator.Next(0, 70) == 5) { Meteors newMeteor = new Meteors(randomGenerator.Next(0, Console.WindowWidth - 3), '$', ConsoleColor.Yellow); meteors.Add(newMeteor); } if (randomGenerator.Next(0, 80) == 5) { Meteors newMeteor = new Meteors(randomGenerator.Next(0, Console.WindowWidth - 3), '#', ConsoleColor.White); meteors.Add(newMeteor); } for (int i = 0; i < meteors.Count; i++) { if (meteors[i].Y + 12 >= Console.WindowHeight) { meteors[i].ClearMeteorite(); meteors.Remove(meteors[i]); newPlayer.Score += 1; newPlayer.UpdateScore(); } meteors[i].Move(); //collision detection for (int j = 0; j < meteors[i].Shape.GetLength(0); j++) { for (int k = 0; k < myStarShip.Shape.GetLength(0); k++) { if (meteors[i].Shape[j, 0] == myStarShip.Shape[k, 0] && meteors[i].Shape[j, 1] == myStarShip.Shape[k, 1]) { if (meteors[i].Color == ConsoleColor.Red) { Console.Beep(); meteors[i].ClearMeteorite(); meteors.Remove(meteors[i]); newPlayer.UpdateLives(-1); } else if (meteors[i].Color == ConsoleColor.Green) { newPlayer.UpdateLives(1); meteors[i].ClearMeteorite(); meteors.Remove(meteors[i]); } else if (meteors[i].Color == ConsoleColor.Yellow) { newPlayer.Score += 50; meteors[i].ClearMeteorite(); meteors.Remove(meteors[i]); } else if (meteors[i].Color == ConsoleColor.White) { newGame.GameSpeed += 10; newGame.Frequency += 1; meteors[i].ClearMeteorite(); meteors.Remove(meteors[i]); } } } } } Thread.Sleep(newGame.GameSpeed); if (newPlayer.Lives == 0) { newPlayer.GameOver(); } } }