Hi all,
I'm having a little issue working with this Guessing Game I'm trying to make, I've already mad it in a console on C++ but im finding Windows forms a bit tedious =/
What issues am I having?
Well, Im ussing combo boxes for generating a random number, so user gets to choose from the combobox whether he/she'd like to generate a random number between 1-5, 1-10 or 1-20 I also have another combobox for the number of guesses (1,3,5).
I also have a test program where a user ticks the test box and he/she gets to choose whether to enter the guess number or not, here's what I have so far:
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;
using System.IO;
namespace NumberGuessingGame_08029490
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
testNumberTextBox.Visible = false;
enterGuessNumberLabel.Visible = false;
}
//Declare the variables.
int testDecimal, guessDecimal;
private void testCheckBox_CheckedChanged(object sender, EventArgs e)
{
testNumberTextBox.Visible = true;
enterGuessNumberLabel.Visible = true;
if (testCheckBox.Checked == true)
{
testDecimal = int.Parse(testNumberTextBox.Text);
}
else
{
testDecimal = rangeNumbersComboBox.SelectedIndex;
}
}
private void guessButton_Click(object sender, EventArgs e)
{
//Convert inputs to values.
guessDecimal = int.Parse(guessNumberTextBox.Text);
//Actions (test).
if (guessDecimal < testDecimal)
{
guessResultTextBox.Text = "Your Guess is too low, try again";
}
if (guessDecimal > testDecimal)
{
guessResultTextBox.Text = "Your Guess is too high, try again";
}
if (guessDecimal == testDecimal)
{
guessResultTextBox.Text = "Correct!!!";
}
}
private void rangeNumbersComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
if (rangeNumbersComboBox.SelectedIndex == 0)
{
Random randomNum = new Random();
int randomNumFive = randomNum.Next(1, 5);
}
if (rangeNumbersComboBox.SelectedIndex == 1)
{
Random randomNum = new Random();
int randomNumTen = randomNum.Next(1, 10);
}
if (rangeNumbersComboBox.SelectedIndex == 2)
{
Random randomNum = new Random();
int randomNumTwenty = randomNum.Next(1, 20);
}
}
Im getting errors when I tick the check box saying: "Input string was not in correct format"
and whenever I choose a value from the range combobox its always 0!!! :O
I'm wondering if I'm going to have to data bind the values for each combobox value, if so how do i do this? Ive looked on the web, nothing.
Help!!! xxxx