Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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}");
}
}
}
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

13th Edition Global Edition

1292263350, 978-1292263359

More Books

Students also viewed these Databases questions

Question

b. Did you suppress any of your anger? Explain.

Answered: 1 week ago