Question: This code seems to be working but buttons dont do much for the game could i have some help. Thanks for the help in advance!

This code seems to be working but buttons dont do much for the game could i have some help. Thanks for the help in advance! Time
Score: 010
checkBoxDebug
public partial class Game : Form
{
private TimeSpan gameTime;
private bool gamePaused;
private int score;
private const int MaxScore =10; // Maximum score required to win
public Game()
{
InitializeComponent();
// Initialize TimeSpan for game time
gameTime = TimeSpan.FromSeconds(30); //30 seconds game time
// Initialize game state
gamePaused = true;
score =0;
// Set up UI initial state
UpdateGameUI();
}
private void buttonStart_Click(object sender, EventArgs e)
{
gamePaused = false;
StartGame();
}
private void buttonPause_Click(object sender, EventArgs e)
{
gamePaused = true;
PauseGame();
}
private void buttonReset_Click(object sender, EventArgs e)
{
gamePaused = true;
DialogResult result = MessageBox.Show("Are you sure you want to reset the game?", "Reset Game", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
ResetGame();
}
}
private void StartGame()
{
// Reset score
score =0;
UpdateGameUI();
// Start game timer
timerGame.Start();
}
private void PauseGame()
{
// Pause game timer
timerGame.Stop();
UpdateGameUI();
}
private void ResetGame()
{
// Stop game timer
timerGame.Stop();
// Reset game time and score
gameTime = TimeSpan.FromSeconds(30);
score =0;
gamePaused = true;
// Update UI
UpdateGameUI();
}
private void timerGame_Tick(object sender, EventArgs e)
{
if (!gamePaused)
{
// Decrease gameTime by the elapsed time
gameTime = gameTime.Subtract(TimeSpan.FromSeconds(1));
// Update UI to show remaining time
UpdateGameUI();
// Check for game over condition
if (gameTime.TotalSeconds =0|| score >= MaxScore)
{
gamePaused = true;
timerGame.Stop();
if (score >= MaxScore)
MessageBox.Show("Congratulations! You won the game!");
else
MessageBox.Show("Game Over. You ran out of time!");
}
}
}
private void buttonClickMe_Click(object sender, EventArgs e)
{
// Perform action when the button is clicked during the game
if (!gamePaused)
{
score++;
UpdateGameUI();
}
}
private void UpdateGameUI()
{
// Update UI components based on game state
labelTime.Text = $"Time: {gameTime:mm\\:ss}";
labelScore.Text = $"Score: {score}/{MaxScore}";
// Enable/disable buttons based on game state
buttonStart.Enabled = gamePaused;
buttonPause.Enabled =!gamePaused;
buttonReset.Enabled = gamePaused;
// Enable/disable game interaction elements based on game state
buttonClickMe.Enabled =!gamePaused && gameTime.TotalSeconds >0;
}
private void checkBoxDebug_CheckedChanged(object sender, EventArgs e)
{
// Toggle debugging features
if (checkBoxDebug.Checked)
{
// Enable breakpoint or other debugging actions
// For simplicity, let's simulate a breakpoint
MessageBox.Show("Breakpoint enabled!");
// Place breakpoint logic here
}
else
{
// Disable breakpoint or other debugging actions
MessageBox.Show("Breakpoint disabled!");
// Remove breakpoint logic here
}
}
private void comboBoxOptions_SelectedIndexChanged(object sender, EventArgs e)
{
// Respond to ComboBox selection change event
string selectedOption = comboBoxOptions.SelectedItem.ToString();
MessageBox.Show($"Selected option: {selectedOption}");
}
}
}
 This code seems to be working but buttons dont do much

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!