Question 2008 Edition: Making a Trivia Game - Classes

Zip

Member
Joined
Mar 25, 2011
Messages
14
Programming Experience
Beginner
I am taking a Programming class in my school and for one of my summative assignments I've been asking to write a Trivia Game. Here is a link to the assignment sheet http://www.swaine.ca/teaching/2011S2_SYDHS/courses/ics3cu/ICS3CU - Trivia Summative.doc

For my project I decided to have a forum load with three buttons, each button would be to a catagory "Cats", "Dogs", and "Horses". When a catagory was selected a new forum would load containing a lable "lblQuestion.text" where a randomly generated question would be displayed, a combobox "cbxAnswers" where the corresponding answer options would be displayed and a button "btnSubmit" to submit the answer once chosen.
I am having a hard time loading the questions and answers. I was thinking of having the answers in a class but I don't know how to go about doing that, or how to display the correct corresponding asnwers. Here is the code I have so far for 1 catagory. How would I code the class? I really don't quite understand anything I am doing for this, I don't think I even undestand what I already have coded.

Code:

Public Class frmGame
Dim intQuestionNum As Integer
Dim rndRand As New Random
Dim lstCatsQuestions As New List(Of CatQ)
Dim intQuestionNumber As Integer

Private Sub btnCats_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCats.Click

Dim rndRand As New Random

intQuestionNumber = rndRand.Next(0, lstCatsQuestions.Count)
frmQuestions.lblQuestion.Text = lstCatsQuestions(intQuestionNumber).strQ

Dim intRightAnswer As Integer
intRightAnswer = rndRand.Next(1, 5)

If intRightAnswer = 1 Then
frmQuestions.cbxAnswers.Items.Add(lstCatsQuestions(intQuestionNumber).strAnswer)
frmQuestions.cbxAnswers.Items.Add(lstCatsQuestions(intQuestionNumber).strFalseA1)
frmQuestions.cbxAnswers.Items.Add(lstCatsQuestions(intQuestionNumber).strFalseA2)
frmQuestions.cbxAnswers.Items.Add(lstCatsQuestions(intQuestionNumber).strFalseA3)
ElseIf intRightAnswer = 2 Then
frmQuestions.cbxAnswers.Items.Add(lstCatsQuestions(intQuestionNumber).strFalseA1)
frmQuestions.cbxAnswers.Items.Add(lstCatsQuestions(intQuestionNumber).strAnswer)
frmQuestions.cbxAnswers.Items.Add(lstCatsQuestions(intQuestionNumber).strFalseA2)
frmQuestions.cbxAnswers.Items.Add(lstCatsQuestions(intQuestionNumber).strFalseA3)
ElseIf intRightAnswer = 3 Then
frmQuestions.cbxAnswers.Items.Add(lstCatsQuestions(intQuestionNumber).strFalseA1)
frmQuestions.cbxAnswers.Items.Add(lstCatsQuestions(intQuestionNumber).strFalseA2)
frmQuestions.cbxAnswers.Items.Add(lstCatsQuestions(intQuestionNumber).strAnswer)
frmQuestions.cbxAnswers.Items.Add(lstCatsQuestions(intQuestionNumber).strFalseA3)
ElseIf intRightAnswer = 4 Then
frmQuestions.cbxAnswers.Items.Add(lstCatsQuestions(intQuestionNumber).strFalseA1)
frmQuestions.cbxAnswers.Items.Add(lstCatsQuestions(intQuestionNumber).strFalseA2)
frmQuestions.cbxAnswers.Items.Add(lstCatsQuestions(intQuestionNumber).strFalseA3)
frmQuestions.cbxAnswers.Items.Add(lstCatsQuestions(intQuestionNumber).strAnswer)
End If


frmQuestions.Visible = True
Me.Visible = False

End Sub

Private Sub frmQuestions_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim sRead As IO.StreamReader = New IO.StreamReader("Cat_Questions.txt")
Dim strTemp As String
Dim strTempArray() As String

strTemp = sRead.ReadLine
strTempArray = strTemp.Split("/")
lstCatsQuestions.Add(New CatQ(strTempArray(0), strTempArray(1), _
strTempArray(2), strTempArray(3), strTempArray(4)))

Do While (sRead.Peek <> -1)
strTemp = sRead.ReadLine
strTempArray = strTemp.Split("/")
lstCatsQuestions.Add(New CatQ(strTempArray(0), strTempArray(1), _
strTempArray(2), strTempArray(3), strTempArray(4)))
Loop


End Sub

Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
If frmQuestions.cbxAnswers.Text = lstCatsQuestions(intQuestionNumber).strAnswer Then
MsgBox("Right!")
Else
MsgBox("Wrong!")
End If

frmQuestions.cbxAnswers.Items.Clear()
frmQuestions.cbxAnswers.Text = ""


frmQuestions.lblQuestion.ResetText()

End Sub
 
Back
Top