Hello, I have been working on a project that's been assigned for me in my intro into gaming/programming class, and here is the code I have so far. I made it so the program asks you what the capital of a random state is, and I can get it to display four different random capitals (with radio buttons), yet the trouble I'm having is with assigning the CORRECT capital as one of the options for the radio buttons.
![Name: statecapitalgame.png
Views: 60
Size: 228.5 KB]()
Code:
Public Class USCapitals
' Declare module level variables.
Private StatesArray() As String = {"Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", "Delaware", "Florida", "Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts", "Michigan", "Minnesota", "Mississippi", "Missouri", "Montana", "Nebraska", "Nevada", "New Hampshire", "New Jersey", "New Mexico", "New York", "North Carolina", "North Dakota", "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota", "Tennessee", "Texas", "Utah", "Vermont", "Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming"}
Private CapitalsArray() As String = {"Montgomery", "Juneau", "Phoenix", "Little Rock", "Sacramento", "Denver", "Hartford", "Dover", "Tallahassee", "Atlanta", "Honolulu", "Boise", "Springfield", "Indianapolis", "Des Moines", "Topeka", "Frankfort", "Baton Rouge", "Augusta", "Annapolis", "Boston", "Lansing", "St. Paul", "Jackson", "Jefferson City", "Helena", "Lincoln", "Carson City", "Concord", "Trenton", "Santa Fe", "Albany", "Raleigh", "Bismarck", "Columbus", "Oklahoma City", "Salem", "Harrisburg", "Providence", "Columbia", "Pierre", "Nashville", "Austin", "Salt Lake City", "Montpelier", "Richmond", "Olympia", "Charleston", "Madison", "Cheyenne"}
' Gain access to random class methods & properties
Private RandomClass As New Random()
Private Correct As Integer
Private Sub doCapitalsStateSelection()
' Generate random number between 0 and 49.
Dim RandomAInteger As Integer
RandomAInteger = RandomClass.Next(50)
Dim RandomBInteger As Integer
RandomBInteger = RandomClass.Next(50)
Dim RandomCInteger As Integer
RandomCInteger = RandomClass.Next(50)
Dim RandomDInteger As Integer
RandomDInteger = RandomClass.Next(50)
Select Case Correct
Case 0 To 0
End Select
' Get values from the arrays.
Dim RandomCapString1 As String = CapitalsArray(RandomAInteger)
Dim RandomCapString2 As String = CapitalsArray(RandomBInteger)
Dim RandomCapString3 As String = CapitalsArray(RandomCInteger)
Dim RandomCapString4 As String = CapitalsArray(RandomDInteger)
'Populate radio buttons.
Option1RadioButton.Text = RandomCapString1
Option2RadioButton.Text = RandomCapString2
Option3RadioButton.Text = RandomCapString3
Option4RadioButton.Text = RandomCapString4
Dim RandomSInteger As Integer
RandomSInteger = RandomClass.Next(50)
Dim RandomStateString As String = StatesArray(RandomSInteger)
QuestionLabel.Text = "What is the capital of" + RandomStateString + "?"
End Sub
Private Sub doStateSelection()
Dim RandomSInteger As Integer
RandomSInteger = RandomClass.Next(50)
Dim RandomStateString As String = StatesArray(RandomSInteger)
QuestionLabel.Text = "What is the capital of" + RandomStateString + "?"
End Sub
Private Sub USCapitals_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
' Call for new set of State and Capital names.
doCapitalsStateSelection()
End Sub