private static void OnTimedEvent(Object source, ElapsedEventArgs e) { switch (gameState) { case GameState.Idle: { gameState = GameState.Start; LoadScreen("Start.txt"); break; } case GameState.Playing: { timerValue += 1; var random = new Random(); // Spawn food items var foodCommand = new ConsoleCommand(random.Next(0, 79), random.Next(1, 39), AnsiString.Create(characterBrushes[4].ToString()).Blue()); foodCommand.Execute(); gameBuffer.Add(foodCommand); // Spawn lives if (random.Next(10) == 0) { var liveCommand = new ConsoleCommand(random.Next(0, 79), random.Next(1, 39), AnsiString.Create(characterBrushes[5].ToString()).Red()); liveCommand.Execute(); gameBuffer.Add(liveCommand); } // Spawn enemies if (random.Next(3) == 0) { AnsiString enemy; if (random.Next(1) == 0) { enemy = AnsiString.Create(characterBrushes[random.Next(6, 8)].ToString()).Blue(); } else { enemy = AnsiString.Create(characterBrushes[random.Next(6, 8)].ToString()).Red(); } var enemyCommand = new ConsoleCommand(random.Next(0, 79), random.Next(1, 39), enemy); enemyCommand.Execute(); gameBuffer.Add(enemyCommand); } // Remove items if (gameBuffer.Count > 0 && (timerValue > 5) && (timerValue % 2 == 0)) { var first = gameBuffer.First(); first.Clear(); gameBuffer.Remove(first); } // Increase game speed if (gameSpeed > 100) { gameSpeed -= 1; timer.Interval = gameSpeed; } UpdateHeader(); break; } case GameState.GameOver: { break; } default: break; } }
private static void ConsoleListener_MouseEvent(MOUSE_EVENT_RECORD r) { if (!updatingHeader && r.dwButtonState == 1 && (r.dwMousePosition.X != previousMousePositionX || r.dwMousePosition.Y != previousMousePositionY)) { var gameObjectFound = gameBuffer.FirstOrDefault(cc => cc.X == r.dwMousePosition.X && cc.Y == r.dwMousePosition.Y); if (gameObjectFound != null) { gameObjectFound.Clear(); gameBuffer.Remove(gameObjectFound); if (gameObjectFound.Value.Text[0] == characterBrushes[4]) { score += 1; } else if (gameObjectFound.Value.Text[0] == characterBrushes[5]) { lives += 1; } else if (gameObjectFound.Value.Text[0] == characterBrushes[6] || gameObjectFound.Value.Text[0] == characterBrushes[7] || gameObjectFound.Value.Text[0] == characterBrushes[8]) { lives -= 1; Console.Beep(); if (lives == 0) { LoadScreen("End.txt"); gameState = GameState.GameOver; } } } var newCommand = new ConsoleCommand(r.dwMousePosition.X, r.dwMousePosition.Y, AnsiString.Create(activeBrush.ToString()).Colored(activeColor, ConsoleColor.Black)); newCommand.Execute(); commandBuffer.Add(newCommand); previousMousePositionX = r.dwMousePosition.X; previousMousePositionY = r.dwMousePosition.Y; } }