Instructions
Create a form with the features shown below. We will have a form with no textboxes.
We will play the number guessing game. The user picks the range for the number to be guessed from a combobox. Then based on the range, the logic decides how many chances they get to guess the correct number according to the following:
Range between 0 and 10, number of guesses is 3. User gets 1 point for guessing.
Range between 0 and 50, number of guesses is 5. User gets 5 points for guessing.
Range between 0 and 100, number of guesses is 8. User gets 50 points for guessing.
Allow the user to play multiple games and for each one you must:
Add the points for a total score. You will need a form-level variable to add scores. This variable is only reset to 0 under the Reset button handler.
Use CInt(Rnd() * MaxRange) where MaxRange is the max possible guess.
For example, for range between 0 and 50, the computerGuess = CInt( Rnd() * 50)
Allow the user to change their game setting by changing the value of the combo without resetting the score to 0.
Your form and logic should include the following buttons:
Buttons : New Game, Reset, Quit.
One combobox showing options of 0-10, 0-50, 0-100. 0-10 is the default.
When the user clicks New Game, a new guess is generated based on the range of the combo.
A numberOfTries variable is set to the allowed chances based on the choice of the combo.
The computerGuess is generated as shown above.
To check which combo item the user selected use the SelectedIndex which is 0 for the first item. Note a combobox control works just like a listbox control.
A loop will run as long as the user is within their number of guesses and has not guessed the correct answer. You may check if the numberOfTries is within the allowed range, then decrease this variable by one inside the loop for each entry the user makes.
Inside the loop get a new guess from the user and compare it to the current guess.
Use Inputbox to get a new guess from the user. Recall Inputbox returns a String.
If they are equal the game ends and you must add the current score to the total score.
The loop should stop.
If they are not equal, the loop continues as long as the number of tries are not exhausted.
If the number of tries has been exhausted, the game ends.
Reset, restarts the score back from 0.
Missing top level comments or empty handlers cause a 5 points loss each.
Note that Rnd() always starts at one particular value. To make Rnd start at a different value at runtime, use Randomize under Form Load.

New Topic/Question
Reply



MultiQuote






|