// Game clock. The timer will be used to help move the game and calculate points private void gameTimer_Tick(object sender, EventArgs e) { // Create new objects for game logic CarAI carAI = new CarAI(playerCar, aiCar1, aiCar2, aiCar3); GameReset game = new GameReset(playerCar, aiCar1, aiCar2, aiCar3, road1, road2, gameTimer); Road road = new Road(road1, road2); double regScore; double bestScore; // Increase points by 0.06 instead of every millisecond. Prevents score from being too high score.RawPoints += 0.06f; regScore = score.IncreaseScore(); bestScore = score.IncreaseBestScore(); // Display score as text scoreText.Text = regScore.ToString(); bestScoreText.Text = bestScore.ToString(); Difficulty diff = new Difficulty(aiCar1, aiCar2, aiCar3, road1, road2); diff.IncreaseSpeed(regScore); // Move road road.Run(); // Move car carAI carAI.Run(); // Save score into static variable best = regScore; // If cars collide end game if (carAI.Collide()) { gameTimer.Stop(); startBtn.Enabled = true; pauseBtn.Enabled = false; viewScoresBtn.Enabled = true; // If score is top 10 of all scores, show window // If not show message box HighScoreQuery query = new HighScoreQuery(); if (query.IsTopTen(best)) { HighScoreForm highScoreForm = new HighScoreForm(); highScoreForm.ShowDialog(); } else { MessageBox.Show("Game over!" + Environment.NewLine + $"High Score: {score.BestScore}", "Game Over!", MessageBoxButtons.OK, MessageBoxIcon.Information); } // Reset game to default varialbes game.Reset(); score.RawPoints = game.RawPoints; score.Points = game.Points; } }
// Dispaly database contents to data grid view private void HighScoresReadOnly_Load(object sender, EventArgs e) { HighScoreQuery query = new HighScoreQuery(); highScoresBindingSource.DataSource = query.ShowTableData(); dgv.DataSource = highScoresBindingSource; }