Create a Form that contains a guessing game with five RadioButtons numbered 1 th
ID: 3551048 • Letter: C
Question
Create a Form that contains a guessing game with five RadioButtons numbered 1 through 5. Randomly choose one of the RadioButtons as the winning button. When the user clicks a RadioButton, display a message indicating whether the user is correct. Add a Label to the Form that provides a hint. When the user's mouse hovers over the label, notify the user of one RadioButton that is incorrect. After the user makes a selection, disable all theRadioButtons. Title the project GuessANumber.
Here is my code so far: Can someone please help!!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void HINT_MouseHover(object sender, EventArgs e)
{
HoverLocationLabel.Text = "it's an even number";
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
if(Button1CheckBox.Checked)
radioButton1.Text = "incorrect";
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
if (Button2CheckBox.Checked)
radioButton2.Text = "incorrect";
}
private void radioButton3_CheckedChanged(object sender, EventArgs e)
{
if (Button3CheckBox.Checked)
radioButton3.Text = "incorrect";
}
private void radioButton4_CheckedChanged(object sender, EventArgs e)
{
if (Button4CheckBox.Checked)
radioButton4.Text = "incorrect";
}
private void radioButton5_CheckedChanged(object sender, EventArgs e)
{
if (Button5CheckBox.Checked)
radioButton5.Text = "incorrect";
}
}
}
Explanation / Answer
?using System;
using System.Collections.Generic;
using System.Linq; using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace _4chegg_game
{
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
Random RanClass = new Random();
int random = RanClass.Next(1, 3);
label1.Text = Convert.ToString(random);
}
protected void Button1_Click(object sender, EventArgs e)
{
label1.Visible=true;
if(((Convert.ToInt16(label1.Text)==RadioButtonList1.SelectedValue[0])&&(RadioButtonList1.Items[2].Selected)))
Label5.Text="you win its "Rock smashes Scissor"";
if(((Convert.ToInt16(label1.Text)==RadioButtonList1.SelectedValue[2])&&(RadioButtonList1.Items[1].Selected)))
Label5.Text="you win its "Scissor cuts paper"";
if(((Convert.ToInt16(label1.Text)==RadioButtonList1.SelectedValue[1])&&(RadioButtonList1.Items[0].Selected)))
Label5.Text="you win its "Paper covers rock"";
}
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (RadioButtonList1.SelectedIndex == 0)
Label2.Text = "0";
else if (RadioButtonList1.SelectedIndex == 1)
Label2.Text = "1";
else Label2.Text = "2";
}
}
}