static void MoveObstacle() { List <Rock> updateObstacles = new List <Rock>(); int sameRowEntries = 0; foreach (var item in ObstacleRow) { Rock oldRock = item; oldRock.y++; if (oldRock.y == Console.WindowHeight - 1) { ObstacleRow.Remove(oldRock); } else { updateObstacles.Add(oldRock); } if (oldRock.y == Console.WindowHeight - 2 && oldRock.x >= player.x && oldRock.x <= player.x + player.form.Length - 1) { Console.SetCursorPosition(Console.WindowWidth / 2 - 5, Console.WindowHeight / 2); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("You Got Hit!!!"); Console.ReadKey(); lives--; } else if (oldRock.y == Console.WindowHeight - 1 && sameRowEntries != oldRock.y) { score++; sameRowEntries = oldRock.y; } } ObstacleRow = updateObstacles; }
static void GenerateObstacle() { for (int i = 0; i < Console.WindowWidth; i++) { int chance = rand.Next(0, 75); if (rand.Next(0, 100) <= 5) { obstacle.x = rand.Next(0, Console.WindowWidth - 2); obstacle.y = 0; obstacle.symbol = rockType[rand.Next(0, rockType.Length)]; obstacle.color = SetRandomColor(); if (chance < 35) { ObstacleRow.Add(obstacle); } else if (chance >= 35 && chance < 70) { if (i < Console.WindowWidth - 2) { ObstacleRow.Add(obstacle); obstacle.x++; ObstacleRow.Add(obstacle); i++; } } else if (chance >= 70 && chance < 100) { if (i < Console.WindowWidth - 3) { ObstacleRow.Add(obstacle); obstacle.x++; ObstacleRow.Add(obstacle); obstacle.x++; ObstacleRow.Add(obstacle); i = i + 2; } } } } }