Initial commit
This commit is contained in:
commit
c42d5896ea
39 changed files with 6278 additions and 0 deletions
305
StudentForms/RockPaperScissors/frmRPSFight.vb
Normal file
305
StudentForms/RockPaperScissors/frmRPSFight.vb
Normal file
|
@ -0,0 +1,305 @@
|
|||
Imports MySql.Data.MySqlClient
|
||||
|
||||
Public Class frmRPSFight
|
||||
|
||||
'Declares the variables for the timers
|
||||
Dim count As Integer = 100
|
||||
Dim countdown As Integer = 3
|
||||
Dim time As Integer = 0
|
||||
|
||||
'Declares the variables used for storing the winner
|
||||
Dim WinnerName As String
|
||||
Dim Winner As Integer
|
||||
|
||||
'Subroutine runs on form load
|
||||
Private Sub frmRPSFight_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
|
||||
|
||||
'Runs the AccountSection subroutine
|
||||
AccountSection()
|
||||
|
||||
'Runs the Weapons subroutine
|
||||
Weapons()
|
||||
|
||||
'Enables the countdown timer
|
||||
tmrCountdown.Enabled = True
|
||||
End Sub
|
||||
|
||||
'Subroutine runs when called in form load subroutine
|
||||
Sub Weapons()
|
||||
'Sets the images to the players' chosen weapons
|
||||
If LoggedInWeapon = 1 Then
|
||||
picLoggedIn.Image = My.Resources.bigrock
|
||||
ElseIf LoggedInWeapon = 2 Then
|
||||
picLoggedIn.Image = My.Resources.bigpaper
|
||||
ElseIf LoggedInWeapon = 3 Then
|
||||
picLoggedIn.Image = My.Resources.bigscissorsloggedin
|
||||
ElseIf LoggedInWeapon = 0 Then
|
||||
picLoggedIn.Image = My.Resources.bigchickenloggedin
|
||||
End If
|
||||
|
||||
If OppWeapon = 1 Then
|
||||
picOpp.Image = My.Resources.bigrock
|
||||
ElseIf OppWeapon = 2 Then
|
||||
picOpp.Image = My.Resources.bigpaper
|
||||
ElseIf OppWeapon = 3 Then
|
||||
picOpp.Image = My.Resources.bigscissorsopp
|
||||
ElseIf OppWeapon = 0 Then
|
||||
picOpp.Image = My.Resources.bigchickenopp
|
||||
End If
|
||||
End Sub
|
||||
|
||||
'Subroutine runs when called in form load subroutine
|
||||
Sub AccountSection()
|
||||
'Populates the player name labels with data
|
||||
lblLoggedInName.Text = LoggedInStudent.Fname & " " & LoggedInStudent.Lname
|
||||
lblOppName.Text = OppStudent.Fname & " " & OppStudent.Lname
|
||||
End Sub
|
||||
|
||||
'Subroutine runs when countdown timer ticks
|
||||
Private Sub tmrCountdown_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrCountdown.Tick
|
||||
'Decrements count by 10
|
||||
count = count - 10
|
||||
|
||||
'If count reaches 0...
|
||||
If count = 0 Then
|
||||
'Changes the number of the countdown displayed
|
||||
countdown = countdown - 1
|
||||
If countdown > 0 Then
|
||||
lblCountdown.Text = countdown
|
||||
count = 100
|
||||
'If the coundown reaches the end...
|
||||
Else
|
||||
'Disables the timer, displays the weapons
|
||||
picLoggedIn.Visible = True
|
||||
picOpp.Visible = True
|
||||
lblCountdown.Visible = False
|
||||
count = 1000
|
||||
tmrCountdown.Enabled = False
|
||||
tmrAnimate.Enabled = True
|
||||
|
||||
'Plays 3 Inches of Blood - Deady Sinners
|
||||
My.Computer.Audio.Play(My.Resources.deadly, AudioPlayMode.Background)
|
||||
End If
|
||||
End If
|
||||
End Sub
|
||||
|
||||
'Subroutine runs when animation timer ticks
|
||||
Private Sub tmrAnimate_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrAnimate.Tick
|
||||
'Declares the variables used for the coords of the pictures
|
||||
Dim x, y, xx, yy As Integer
|
||||
|
||||
'Decrements count by 1000
|
||||
count = count - 1000
|
||||
|
||||
'Runs the random number generator subroutine
|
||||
Randomize()
|
||||
|
||||
'Gets the random coords of both pictureboxes
|
||||
x = CInt(Int((140) * Rnd() - 20))
|
||||
y = CInt(Int((50) * Rnd()) + 60)
|
||||
xx = CInt(Int((140) * Rnd()) + 390)
|
||||
yy = CInt(Int((50) * Rnd()) + 60)
|
||||
|
||||
'Changes the position of both pictureboxes fast enough to resemble animation
|
||||
If count = 0 Then
|
||||
If time <> 40 Then
|
||||
count = 1000
|
||||
time = time + 1
|
||||
picLoggedIn.Location = New Point(x, y)
|
||||
picOpp.Location = New Point(xx, yy)
|
||||
'If the time has come for the animation to stop...
|
||||
Else
|
||||
'Stops playing the music
|
||||
My.Computer.Audio.Stop()
|
||||
'Runs the CheckWinner subroutine
|
||||
CheckWinner()
|
||||
'Disables the timer
|
||||
tmrAnimate.Enabled = False
|
||||
'Runs the DatabaseDetails subroutine
|
||||
DatabaseDetails()
|
||||
'Runs the ChangeImage subroutine
|
||||
ChangeImage()
|
||||
'Declares the winner
|
||||
MsgBox("Winner: " & WinnerName)
|
||||
'Shows the Rock, Paper, Scissors hotseat game form
|
||||
frmRPSHotseat.Reset()
|
||||
'Closes this form
|
||||
Me.Close()
|
||||
End If
|
||||
End If
|
||||
End Sub
|
||||
|
||||
'Subroutine runs when called in tmrAnimate_Tick subroutine
|
||||
Sub ChangeImage()
|
||||
'Changes the images of the players to reflect the result of the fight
|
||||
If Winner = 1 Then
|
||||
If OppWeapon <> 0 Then
|
||||
If LoggedInWeapon = 1 Then
|
||||
picLoggedIn.Image = My.Resources.bigrockwinner
|
||||
picOpp.Image = My.Resources.bigscissorsdeadopp
|
||||
ElseIf LoggedInWeapon = 2 Then
|
||||
picLoggedIn.Image = My.Resources.bigpaperwinner
|
||||
picOpp.Image = My.Resources.bigrockdead
|
||||
ElseIf LoggedInWeapon = 3 Then
|
||||
picLoggedIn.Image = My.Resources.bigscissorswinloggedin
|
||||
picOpp.Image = My.Resources.bigpaperdead
|
||||
End If
|
||||
Else
|
||||
If LoggedInWeapon = 1 Then
|
||||
picLoggedIn.Image = My.Resources.bigrockwinner
|
||||
picOpp.Image = My.Resources.bigchickendeadopp
|
||||
ElseIf LoggedInWeapon = 2 Then
|
||||
picLoggedIn.Image = My.Resources.bigpaperwinner
|
||||
picOpp.Image = My.Resources.bigchickendeadopp
|
||||
ElseIf LoggedInWeapon = 3 Then
|
||||
picLoggedIn.Image = My.Resources.bigscissorswinloggedin
|
||||
picOpp.Image = My.Resources.bigchickendeadopp
|
||||
End If
|
||||
End If
|
||||
ElseIf Winner = 2 Then
|
||||
If LoggedInWeapon <> 0 Then
|
||||
If LoggedInWeapon = 1 Then
|
||||
picLoggedIn.Image = My.Resources.bigrockdead
|
||||
picOpp.Image = My.Resources.bigpaperwinner
|
||||
ElseIf LoggedInWeapon = 2 Then
|
||||
picLoggedIn.Image = My.Resources.bigpaperdead
|
||||
picOpp.Image = My.Resources.bigscissorswinopp
|
||||
ElseIf LoggedInWeapon = 3 Then
|
||||
picLoggedIn.Image = My.Resources.bigscissorsdeadloggedin
|
||||
picOpp.Image = My.Resources.bigrockwinner
|
||||
End If
|
||||
Else
|
||||
If LoggedInWeapon = 1 Then
|
||||
picLoggedIn.Image = My.Resources.bigrockwinner
|
||||
picOpp.Image = My.Resources.bigchickendeadopp
|
||||
ElseIf LoggedInWeapon = 2 Then
|
||||
picLoggedIn.Image = My.Resources.bigpaperwinner
|
||||
picOpp.Image = My.Resources.bigchickendeadopp
|
||||
ElseIf LoggedInWeapon = 3 Then
|
||||
picLoggedIn.Image = My.Resources.bigscissorswinloggedin
|
||||
picOpp.Image = My.Resources.bigchickendeadopp
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
End Sub
|
||||
|
||||
'Subroutine runs when called in tmrAnimate_Tick subroutine
|
||||
Sub CheckWinner()
|
||||
'Determines the winner of the game
|
||||
If (LoggedInWeapon = 2 And OppWeapon = 1) Or (LoggedInWeapon = 3 And OppWeapon = 2) Or (LoggedInWeapon = 1 And OppWeapon = 3) Or (LoggedInWeapon <> 0 And OppWeapon = 0) Then
|
||||
WinnerName = LoggedInStudent.Fname & " " & LoggedInStudent.Lname
|
||||
Winner = 1
|
||||
End If
|
||||
If (LoggedInWeapon = 1 And OppWeapon = 2) Or (LoggedInWeapon = 2 And OppWeapon = 3) Or (LoggedInWeapon = 3 And OppWeapon = 1) Or (LoggedInWeapon = 0 And OppWeapon <> 0) Then
|
||||
WinnerName = OppStudent.Fname & " " & OppStudent.Lname
|
||||
Winner = 2
|
||||
End If
|
||||
If LoggedInWeapon = OppWeapon Then
|
||||
WinnerName = "No-one, it's a draw"
|
||||
Winner = 0
|
||||
End If
|
||||
End Sub
|
||||
|
||||
'Subroutine runs when called in winner detection subroutine
|
||||
Sub DatabaseDetails()
|
||||
'Declares the StreamWriter used to write to the game breakdown text files
|
||||
Dim writer As System.IO.StreamWriter
|
||||
Dim sql As String
|
||||
Dim dbcomm As MySqlCommand
|
||||
Dim dbread As MySqlDataReader
|
||||
|
||||
'If the O player is the winner...
|
||||
If Winner = 1 Then
|
||||
'Builds SQL query to execute
|
||||
sql = "UPDATE `tblstudents` SET `Wins`=`Wins`+1 WHERE `Username`='" & LoggedInStudent.Username & "';"
|
||||
|
||||
dbcomm = New MySqlCommand(sql, DBConn)
|
||||
dbread = dbcomm.ExecuteReader()
|
||||
dbread.Close()
|
||||
|
||||
'Sets the path to where the log shall be generated, and the filename
|
||||
writer = My.Computer.FileSystem.OpenTextFileWriter(LoggedInStudent.Username & ".txt", True)
|
||||
|
||||
'Writes the relevant data to the log
|
||||
writer.WriteLine(LoggedInStudent.Fname & " " & LoggedInStudent.Lname & " beat " & OppStudent.Fname & " " & OppStudent.Lname & " in Rock, Paper, Scissors - " & TimeOfDay & " " & DateValue(Now))
|
||||
'Saves the log file
|
||||
writer.Close()
|
||||
|
||||
'Builds SQL query to execute
|
||||
sql = "UPDATE `tblstudents` SET `Losses`=`Losses`+1 WHERE `Username`='" & OppStudent.Username & "';"
|
||||
|
||||
dbcomm = New MySqlCommand(sql, DBConn)
|
||||
dbread = dbcomm.ExecuteReader()
|
||||
dbread.Close()
|
||||
|
||||
'Sets the path to where the log shall be generated, and the filename
|
||||
writer = My.Computer.FileSystem.OpenTextFileWriter(OppStudent.Username & ".txt", True)
|
||||
|
||||
'Writes the relevant data to the log
|
||||
writer.WriteLine(OppStudent.Fname & " " & OppStudent.Lname & " was beaten by " & LoggedInStudent.Fname & " " & OppStudent.Lname & " in Rock, Paper, Scissors - " & TimeOfDay & " " & DateValue(Now))
|
||||
'Saves the log file
|
||||
writer.Close()
|
||||
ElseIf Winner = 2 Then
|
||||
'Builds SQL query to execute
|
||||
sql = "UPDATE `tblstudents` SET `Wins`=`Wins`+1 WHERE `Username`='" & OppStudent.Username & "';"
|
||||
|
||||
dbcomm = New MySqlCommand(sql, DBConn)
|
||||
dbread = dbcomm.ExecuteReader()
|
||||
dbread.Close()
|
||||
|
||||
'Sets the path to where the log shall be generated, and the filename
|
||||
writer = My.Computer.FileSystem.OpenTextFileWriter(OppStudent.Username & ".txt", True)
|
||||
|
||||
'Writes the relevant data to the log
|
||||
writer.WriteLine(OppStudent.Fname & " " & OppStudent.Lname & " beat " & LoggedInStudent.Fname & " " & LoggedInStudent.Lname & " in Rock, Paper, Scissors - " & TimeOfDay & " " & DateValue(Now))
|
||||
'Saves the log file
|
||||
writer.Close()
|
||||
|
||||
'Builds SQL query to execute
|
||||
sql = "UPDATE `tblstudents` SET `Losses`=`Losses`+1 WHERE `Username`='" & LoggedInStudent.Username & "';"
|
||||
|
||||
dbcomm = New MySqlCommand(sql, DBConn)
|
||||
dbread = dbcomm.ExecuteReader()
|
||||
dbread.Close()
|
||||
|
||||
'Sets the path to where the log shall be generated, and the filename
|
||||
writer = My.Computer.FileSystem.OpenTextFileWriter(LoggedInStudent.Username & ".txt", True)
|
||||
|
||||
'Writes the relevant data to the log
|
||||
writer.WriteLine(LoggedInStudent.Fname & " " & LoggedInStudent.Lname & " was beaten by " & OppStudent.Fname & " " & LoggedInStudent.Lname & " in Rock, Paper, Scissors - " & TimeOfDay & " " & DateValue(Now))
|
||||
'Saves the log file
|
||||
writer.Close()
|
||||
ElseIf Winner = 0 Then
|
||||
'Builds SQL query to execute
|
||||
sql = "UPDATE `tblstudents` SET `Draws`=`Draws`+1 WHERE `Username`='" & LoggedInStudent.Username & "';"
|
||||
|
||||
dbcomm = New MySqlCommand(sql, DBConn)
|
||||
dbread = dbcomm.ExecuteReader()
|
||||
dbread.Close()
|
||||
|
||||
'Sets the path to where the log shall be generated, and the filename
|
||||
writer = My.Computer.FileSystem.OpenTextFileWriter(LoggedInStudent.Username & ".txt", True)
|
||||
|
||||
'Writes the relevant data to the log
|
||||
writer.WriteLine(LoggedInStudent.Fname & " " & LoggedInStudent.Lname & " drew with " & OppStudent.Fname & " " & OppStudent.Lname & " in Rock, Paper, Scissors - " & TimeOfDay & " " & DateValue(Now))
|
||||
'Saves the log file
|
||||
writer.Close()
|
||||
|
||||
'Builds SQL query to execute
|
||||
sql = "UPDATE `tblstudents` SET `Draws`=`Draws`+1 WHERE `Username`='" & OppStudent.Username & "';"
|
||||
|
||||
dbcomm = New MySqlCommand(sql, DBConn)
|
||||
dbread = dbcomm.ExecuteReader()
|
||||
dbread.Close()
|
||||
|
||||
'Sets the path to where the log shall be generated, and the filename
|
||||
writer = My.Computer.FileSystem.OpenTextFileWriter(OppStudent.Username & ".txt", True)
|
||||
|
||||
'Writes the relevant data to the log
|
||||
writer.WriteLine(OppStudent.Fname & " " & OppStudent.Lname & " drew with " & LoggedInStudent.Fname & " " & OppStudent.Lname & " in Rock, Paper, Scissors - " & TimeOfDay & " " & DateValue(Now))
|
||||
'Saves the log file
|
||||
writer.Close()
|
||||
End If
|
||||
End Sub
|
||||
|
||||
End Class
|
274
StudentForms/RockPaperScissors/frmRPSHotseat.vb
Normal file
274
StudentForms/RockPaperScissors/frmRPSHotseat.vb
Normal file
|
@ -0,0 +1,274 @@
|
|||
Imports MySql.Data.MySqlClient
|
||||
|
||||
Public Class frmRPSHotseat
|
||||
|
||||
'Declares the variable used to store the primary key of the question record in the database
|
||||
Dim QuestionID As Integer
|
||||
'Declares the y-coords for moving the current player label
|
||||
Dim StudentCurrLocationY As Integer = 35
|
||||
Dim OppStudentCurrLocationY As Integer = 140
|
||||
'Declares the variable used to determine if a question was answered correctly
|
||||
Dim QCorrect As Boolean = False
|
||||
'Declares the variable used to determine it both players have chosen their weapons
|
||||
Dim goes As Integer = 0
|
||||
|
||||
'Subroutine runs on form load
|
||||
Private Sub frmRPSHotseat_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
|
||||
'Runs the OpenDB subroutine
|
||||
OpenDB()
|
||||
|
||||
'Sets the players
|
||||
LoggedInStudent.RPSPlayer = 1
|
||||
OppStudent.RPSPlayer = 2
|
||||
|
||||
'Runs the AccountSection subroutine
|
||||
AccountSection()
|
||||
|
||||
'Sets the current player
|
||||
RPSPlayer = 1
|
||||
|
||||
'Runs the Question subroutine
|
||||
Question()
|
||||
End Sub
|
||||
|
||||
'Subroutine runs when called in form load subroutine
|
||||
Sub AccountSection()
|
||||
'Populates the player name labels with data and get a picture of each player
|
||||
lblStudentName.Text = LoggedInStudent.Fname & " " & LoggedInStudent.Lname
|
||||
picStudent.ImageLocation = LoggedInStudent.Username & ".jpg"
|
||||
|
||||
lblOppStudentName.Text = OppStudent.Fname & " " & OppStudent.Lname
|
||||
picOppStudentPic.ImageLocation = OppStudent.Username & ".jpg"
|
||||
End Sub
|
||||
|
||||
'Subroutine runs when called in form load and button click subroutines
|
||||
Sub ChangePlayer()
|
||||
'Increments the number of goes there have been
|
||||
goes = goes + 1
|
||||
'If both players haven't been
|
||||
If goes < 2 Then
|
||||
'Changes the current player
|
||||
If RPSPlayer = 1 Then
|
||||
RPSPlayer = 2
|
||||
CurrPlayer()
|
||||
Else
|
||||
RPSPlayer = 1
|
||||
CurrPlayer()
|
||||
End If
|
||||
|
||||
'Runs the Question subroutine
|
||||
Question()
|
||||
Else
|
||||
'Shows the Rock, Paper, Scissors fight animation form
|
||||
frmRPSFight.Show()
|
||||
End If
|
||||
End Sub
|
||||
|
||||
'Subroutine runs when called in the ChangePlayer subroutine
|
||||
Sub CurrPlayer()
|
||||
If RPSPlayer = 1 Then
|
||||
'Places the current player label pointing to the logged-in student
|
||||
lblCurrPlayer.Top = StudentCurrLocationY
|
||||
Else
|
||||
'Places the current player label pointing to the opponent student
|
||||
lblCurrPlayer.Top = OppStudentCurrLocationY
|
||||
End If
|
||||
End Sub
|
||||
|
||||
'Subroutine runs when called in ChangePlayer subroutine
|
||||
Sub Question()
|
||||
Dim sql As String
|
||||
Dim dbcomm As MySqlCommand
|
||||
Dim dbread As MySqlDataReader
|
||||
|
||||
sql = "SELECT * FROM tblquestions WHERE SubjectID='" & RPSSubject & "' AND Difficulty='" & RPSDifficulty & "' AND Topic='" & RPSTopic & "' ORDER BY RAND() LIMIT 1;"
|
||||
dbcomm = New MySqlCommand(sql, DBConn)
|
||||
dbread = dbcomm.ExecuteReader()
|
||||
|
||||
While dbread.Read
|
||||
'Sets the QuestionID variable to that of the selected question
|
||||
QuestionID = dbread("QuestionID")
|
||||
|
||||
'Makes the question controls visible
|
||||
grpQuestion.Visible = True
|
||||
lblQuestion.Visible = True
|
||||
txtAnswer.Visible = True
|
||||
btnSubmit.Visible = True
|
||||
|
||||
'Displays the selected question
|
||||
lblQuestion.Text = dbread("Question")
|
||||
End While
|
||||
'Closes the recordset
|
||||
dbread.Close()
|
||||
End Sub
|
||||
|
||||
'Subroutine runs then answer submit button is clicked
|
||||
Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
|
||||
Dim sql As String
|
||||
Dim dbcomm As MySqlCommand
|
||||
Dim dbread As MySqlDataReader
|
||||
Dim foob As Integer = 0
|
||||
'Hides the question controls
|
||||
grpQuestion.Visible = False
|
||||
lblQuestion.Visible = False
|
||||
txtAnswer.Visible = False
|
||||
btnSubmit.Visible = False
|
||||
|
||||
sql = "SELECT * FROM tblquestions WHERE QuestionID='" & QuestionID & "';"
|
||||
dbcomm = New MySqlCommand(sql, DBConn)
|
||||
dbread = dbcomm.ExecuteReader()
|
||||
While dbread.Read
|
||||
'If the answer is correct...
|
||||
If txtAnswer.Text = dbread("Answer") Then
|
||||
'Display a message box
|
||||
MsgBox("Correct!")
|
||||
|
||||
'Sets the question correct flag to true
|
||||
QCorrect = True
|
||||
|
||||
'Makes the weapon selection controls visible
|
||||
grpWeapon.Visible = True
|
||||
|
||||
|
||||
'However if the answer if incorrect...
|
||||
Else
|
||||
'Display a message box
|
||||
MsgBox("Incorrect!")
|
||||
|
||||
'Sets the question correct flag to false
|
||||
QCorrect = False
|
||||
|
||||
foob = 1
|
||||
|
||||
'Sets the current player's weapon to the rubber chicken of shame
|
||||
If RPSPlayer = 1 Then
|
||||
LoggedInWeapon = 0
|
||||
Else
|
||||
OppWeapon = 0
|
||||
End If
|
||||
|
||||
End If
|
||||
End While
|
||||
|
||||
dbread.Close()
|
||||
|
||||
'Runs the QDatabase subroutine
|
||||
QDatabase()
|
||||
|
||||
If foob = 1 Then
|
||||
'Runs the ChangePlayer subroutine
|
||||
ChangePlayer()
|
||||
End If
|
||||
|
||||
'Blanks the answer textbox for the next question
|
||||
txtAnswer.Text = ""
|
||||
End Sub
|
||||
|
||||
'Subroutine runs when called in btnSubmit_Click subroutine
|
||||
Sub QDatabase()
|
||||
Dim sql As String
|
||||
Dim dbcomm As MySqlCommand
|
||||
Dim dbread As MySqlDataReader
|
||||
|
||||
If RPSPlayer = 1 Then
|
||||
sql = "INSERT INTO `cl51-ben`.`tblattempted` (`SubjectID`, `QuestionID`, `StudentID`, `When`, `Correct`) VALUES ('" & RPSSubject & "', '" & QuestionID & "', '" & LoggedInStudent.StudentID & "', '" & TimeOfDay & " " & DateValue(Now) & "', "
|
||||
Else
|
||||
sql = "INSERT INTO `cl51-ben`.`tblattempted` (`SubjectID`, `QuestionID`, `StudentID`, `When`, `Correct`) VALUES ('" & RPSSubject & "', '" & QuestionID & "', '" & OppStudent.StudentID & "', '" & TimeOfDay & " " & DateValue(Now) & "', "
|
||||
End If
|
||||
If QCorrect = True Then
|
||||
sql = sql & "'1');"
|
||||
Else
|
||||
sql = sql & "'0');"
|
||||
End If
|
||||
|
||||
dbcomm = New MySqlCommand(sql, DBConn)
|
||||
dbread = dbcomm.ExecuteReader()
|
||||
|
||||
'Resets the question correct flag
|
||||
QCorrect = False
|
||||
|
||||
dbread.Close()
|
||||
End Sub
|
||||
|
||||
'Subroutine runs when view logged-in student's profile button is clicked
|
||||
Private Sub btnViewProfile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnViewProfile.Click
|
||||
'Sets viewed profile to logged-in student's
|
||||
Viewing = 1
|
||||
'Shows the student account form
|
||||
frmStudentAccount.Show()
|
||||
End Sub
|
||||
|
||||
'Subroutine runs when view opponent student's profile button is clicked
|
||||
Private Sub btnOppViewProfile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOppViewProfile.Click
|
||||
'Sets viewed profile to opponent student's
|
||||
Viewing = 2
|
||||
'Shows the student account form
|
||||
frmStudentAccount.Show()
|
||||
End Sub
|
||||
|
||||
'Subroutine runs when back button is clicked
|
||||
Private Sub btnBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBack.Click
|
||||
'Shows the Rock, Paper, Scissors menu
|
||||
frmRockPaperScissorsMenu.Show()
|
||||
'Closes this form
|
||||
Me.Close()
|
||||
End Sub
|
||||
|
||||
'Subroutine runs when the rock button is clicked
|
||||
Private Sub btnRock_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRock.Click
|
||||
'Sets the current player's weapon to rock
|
||||
If RPSPlayer = 1 Then
|
||||
LoggedInWeapon = 1
|
||||
Else
|
||||
OppWeapon = 1
|
||||
End If
|
||||
|
||||
'Hides the weapon selection controls
|
||||
grpWeapon.Visible = False
|
||||
'Runs the ChangePlayer subroutine
|
||||
ChangePlayer()
|
||||
End Sub
|
||||
|
||||
'Subroutine runs when the paper button is clicked
|
||||
Private Sub btnPaper_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPaper.Click
|
||||
'Sets the current player's weapon to paper
|
||||
If RPSPlayer = 1 Then
|
||||
LoggedInWeapon = 2
|
||||
Else
|
||||
OppWeapon = 2
|
||||
End If
|
||||
|
||||
'Hides the weapon selection controls
|
||||
grpWeapon.Visible = False
|
||||
'Runs the ChangePlayer subroutine
|
||||
ChangePlayer()
|
||||
End Sub
|
||||
|
||||
'Subroutine runs when the scissors button is clicked
|
||||
Private Sub btnScissors_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnScissors.Click
|
||||
'Sets the current player's weapon to scissors
|
||||
If RPSPlayer = 1 Then
|
||||
LoggedInWeapon = 3
|
||||
Else
|
||||
OppWeapon = 3
|
||||
End If
|
||||
|
||||
'Hides the weapon selection controls
|
||||
grpWeapon.Visible = False
|
||||
'Runs the ChangePlayer subroutine
|
||||
ChangePlayer()
|
||||
End Sub
|
||||
|
||||
'Subroutine runs when called in frmRPSFight
|
||||
Sub Reset()
|
||||
'Sets both players' weapons to default and resets the current player
|
||||
LoggedInWeapon = 0
|
||||
goes = 0
|
||||
RPSPlayer = 1
|
||||
OppWeapon = 0
|
||||
|
||||
'Runs the Question subroutine
|
||||
Question()
|
||||
End Sub
|
||||
|
||||
End Class
|
74
StudentForms/RockPaperScissors/frmRPSHotseatLogin.vb
Normal file
74
StudentForms/RockPaperScissors/frmRPSHotseatLogin.vb
Normal file
|
@ -0,0 +1,74 @@
|
|||
Imports MySql.Data.MySqlClient
|
||||
|
||||
Public Class frmRPSHotseatLogin
|
||||
|
||||
'Declares the variables used to log in
|
||||
Dim EnteredUsername, EnteredPassword As String
|
||||
|
||||
'Subroutine runs when the form loads
|
||||
Private Sub frmRPSHotseatLogin_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
|
||||
'Runs the OpenDB subroutine
|
||||
OpenDB()
|
||||
End Sub
|
||||
|
||||
'Subroutine runs when the okay button is clicked
|
||||
Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
|
||||
'Runs the Login subroutine
|
||||
Login()
|
||||
End Sub
|
||||
|
||||
'Subroutine runs when called in btnOK_Click subroutine
|
||||
Sub Login()
|
||||
'Sets the EnteredUsername and EnteredPassword variables to the entered username and password
|
||||
EnteredUsername = txtUsername.Text
|
||||
EnteredPassword = txtPassword.Text
|
||||
|
||||
If EnteredUsername <> LoggedInStudent.Username Then
|
||||
Dim sql As String
|
||||
Dim dbcomm As MySqlCommand
|
||||
Dim dbread As MySqlDataReader
|
||||
Dim foo As Integer = 0
|
||||
sql = "SELECT * FROM tblstudents WHERE Username='" & EnteredUsername & "' AND Password='" & EnteredPassword & "';"
|
||||
dbcomm = New MySqlCommand(sql, DBConn)
|
||||
dbread = dbcomm.ExecuteReader()
|
||||
While dbread.Read
|
||||
'Fills the various properties of the OppStudent object with their respective values from the database
|
||||
OppStudent.Fname = dbread("Fname")
|
||||
OppStudent.Lname = dbread("Lname")
|
||||
OppStudent.Form = dbread("FormNum") & dbread("FormLetter")
|
||||
OppStudent.Wins = dbread("Wins")
|
||||
OppStudent.Losses = dbread("Losses")
|
||||
OppStudent.Draws = dbread("Draws")
|
||||
OppStudent.Username = dbread("Username")
|
||||
OppStudent.StudentID = dbread("StudentID")
|
||||
foo = 1
|
||||
End While
|
||||
If foo = 1 Then
|
||||
'Opens the Noughts and Crosses subject selection form
|
||||
frmRPSHotseatSubject.Show()
|
||||
'Closes this form
|
||||
Me.Close()
|
||||
dbread.Close()
|
||||
Exit Sub
|
||||
End If
|
||||
'If the login details were invalid an error message will appear and the username and password textboxes will be blanked out
|
||||
MsgBox("Invalid: Incorrect username or password.")
|
||||
txtUsername.Text = ""
|
||||
txtPassword.Text = ""
|
||||
Else
|
||||
'If the login details where the same as those of the currently logged-in student, an error message will appear and the username and password textboxes will be blanked out
|
||||
MsgBox("Invalid: That's you.")
|
||||
txtUsername.Text = ""
|
||||
txtPassword.Text = ""
|
||||
End If
|
||||
End Sub
|
||||
|
||||
'Subroutine runs when the cancel button is clicked
|
||||
Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
|
||||
'Opens the Rock, Paper, Scissors menu form
|
||||
frmRockPaperScissorsMenu.Show()
|
||||
'Closes this form
|
||||
Me.Close()
|
||||
End Sub
|
||||
|
||||
End Class
|
92
StudentForms/RockPaperScissors/frmRPSHotseatSubject.vb
Normal file
92
StudentForms/RockPaperScissors/frmRPSHotseatSubject.vb
Normal file
|
@ -0,0 +1,92 @@
|
|||
Imports MySql.Data.MySqlClient
|
||||
|
||||
Public Class frmRPSHotseatSubject
|
||||
'Declares the variable used to store the chosen SubjectID
|
||||
Dim SubjectID As Integer
|
||||
|
||||
'Subroutine runs on form load
|
||||
Private Sub frmNaCHotseatSubject_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
|
||||
'Runs the OpenDB subroutine
|
||||
OpenDB()
|
||||
|
||||
'Runs the Populate subroutine
|
||||
Populate()
|
||||
End Sub
|
||||
|
||||
'Subroutine runs then the okay button is clicked
|
||||
Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
|
||||
'If everything has been selected...
|
||||
If (cmboDifficulty.SelectedItem <> "") And (cmboSubject.SelectedItem <> "") And (cmboTopic.SelectedItem <> "") Then
|
||||
|
||||
'Sets the chosen subject, difficulty and topic variables
|
||||
RPSSubject = SubjectID
|
||||
RPSDifficulty = cmboDifficulty.SelectedItem
|
||||
RPSTopic = cmboTopic.SelectedItem
|
||||
|
||||
'Shows the Connect Four hotseat player selection form
|
||||
frmRPSHotseat.Show()
|
||||
'Closes this form
|
||||
Me.Close()
|
||||
Else
|
||||
'Otherwise display an error message
|
||||
MsgBox("Incorrect values")
|
||||
End If
|
||||
End Sub
|
||||
|
||||
'Subroutine runs when called at form load
|
||||
Sub Populate()
|
||||
Dim sql As String
|
||||
Dim dbcomm As MySqlCommand
|
||||
Dim dbread As MySqlDataReader
|
||||
|
||||
sql = "SELECT * FROM tblsubjects;"
|
||||
dbcomm = New MySqlCommand(sql, DBConn)
|
||||
dbread = dbcomm.ExecuteReader()
|
||||
While dbread.Read
|
||||
cmboSubject.Items.Add(dbread("Subject"))
|
||||
End While
|
||||
dbread.Close()
|
||||
End Sub
|
||||
|
||||
'Subroutine runs when the selected item of the subject combobox is changed
|
||||
Private Sub cmboSubject_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmboSubject.SelectedIndexChanged
|
||||
'Declares the StreamReader used to read the topic text file
|
||||
Dim Reader As System.IO.StreamReader
|
||||
|
||||
'Enables the topic combobox and clears it of any data
|
||||
cmboTopic.Enabled = True
|
||||
cmboTopic.Items.Clear()
|
||||
|
||||
'Sets the path to where the file is
|
||||
Reader = My.Computer.FileSystem.OpenTextFileReader(cmboSubject.SelectedItem & "Topics.txt")
|
||||
'Whilst not at the end of the text file...
|
||||
While Not Reader.EndOfStream
|
||||
'Add the topic to the combobox
|
||||
cmboTopic.Items.Add(Reader.ReadLine)
|
||||
End While
|
||||
|
||||
'Closes the streamreader
|
||||
Reader.Close()
|
||||
|
||||
Dim sql As String
|
||||
Dim dbcomm As MySqlCommand
|
||||
Dim dbread As MySqlDataReader
|
||||
|
||||
sql = "SELECT * FROM tblsubjects WHERE Subject='" & cmboSubject.SelectedItem & "';"
|
||||
dbcomm = New MySqlCommand(sql, DBConn)
|
||||
dbread = dbcomm.ExecuteReader()
|
||||
While dbread.Read
|
||||
SubjectID = dbread("SubjectID")
|
||||
End While
|
||||
dbread.Close()
|
||||
End Sub
|
||||
|
||||
'Subroutine runs when the cancel button is clicked
|
||||
Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
|
||||
'Shows the Rock, Paper, Scissors hotseat login form
|
||||
frmRPSHotseatLogin.Show()
|
||||
'Closes this form
|
||||
Me.Close()
|
||||
End Sub
|
||||
|
||||
End Class
|
19
StudentForms/RockPaperScissors/frmRockPaperScissorsMenu.vb
Normal file
19
StudentForms/RockPaperScissors/frmRockPaperScissorsMenu.vb
Normal file
|
@ -0,0 +1,19 @@
|
|||
Public Class frmRockPaperScissorsMenu
|
||||
|
||||
'Subroutine runs when the hotseat game button is clicked
|
||||
Private Sub btnHotseat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHotseat.Click
|
||||
'Shows the Rock, Paper, Scissors hotseat login form
|
||||
frmRPSHotseatLogin.Show()
|
||||
'Closes this form
|
||||
Me.Close()
|
||||
End Sub
|
||||
|
||||
'Subroutine runs when the back button is clicked
|
||||
Private Sub btnBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBack.Click
|
||||
'Shows the student home form
|
||||
frmStudentHome.Show()
|
||||
'Closes this form
|
||||
Me.Close()
|
||||
End Sub
|
||||
|
||||
End Class
|
Reference in a new issue