Initial commit
This commit is contained in:
commit
c42d5896ea
39 changed files with 6278 additions and 0 deletions
145
FirstTimeSetup/frmAddStudent.vb
Normal file
145
FirstTimeSetup/frmAddStudent.vb
Normal file
|
@ -0,0 +1,145 @@
|
||||||
|
Imports MySql.Data.MySqlClient
|
||||||
|
|
||||||
|
Public Class frmAddStudent
|
||||||
|
|
||||||
|
'Declares the variable used for generating the username of the new student
|
||||||
|
Dim Uname As String
|
||||||
|
'Declares the variable used for getting the image of the new student
|
||||||
|
Dim Filepath As String
|
||||||
|
|
||||||
|
'Subroutine runs when the form loads
|
||||||
|
Private Sub frmAddStudent_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
|
||||||
|
'Establishes the connection to the database
|
||||||
|
OpenDB()
|
||||||
|
|
||||||
|
'Indicates that no picture has been selected
|
||||||
|
picPic.Tag = 0
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when the student first name text box is clicked
|
||||||
|
Private Sub txtStudentFirstName_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtStudentFirstName.Click
|
||||||
|
'Blanks out the text box
|
||||||
|
txtStudentFirstName.Text = ""
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when the student last name text box is clicked
|
||||||
|
Private Sub txtStudentLastName_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtStudentLastName.Click
|
||||||
|
'Blanks out the text box
|
||||||
|
txtStudentLastName.Text = ""
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when the add student button is clicked
|
||||||
|
Private Sub btnAddStudent_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddStudent.Click
|
||||||
|
'Declares the variable used for getting the result of the message box
|
||||||
|
Dim Result As MsgBoxResult
|
||||||
|
'Declares the variable used for detecting invalid data entry
|
||||||
|
Dim Errors As String = ""
|
||||||
|
|
||||||
|
'Assembles an error report if any invalid data entry detected
|
||||||
|
If txtStudentFirstName.Text = "" Then
|
||||||
|
Errors = Errors & "No first name input" & vbCrLf
|
||||||
|
End If
|
||||||
|
If txtStudentLastName.Text = "" Then
|
||||||
|
Errors = Errors & "No last name input" & vbCrLf
|
||||||
|
End If
|
||||||
|
If cmboYear.Text = "" Then
|
||||||
|
Errors = Errors & "No year selected" & vbCrLf
|
||||||
|
End If
|
||||||
|
If cmboForm.Text = "" Then
|
||||||
|
Errors = Errors & "No form selected" & vbCrLf
|
||||||
|
End If
|
||||||
|
If picPic.Tag = 0 Then
|
||||||
|
Errors = Errors & "No picture input" & vbCrLf
|
||||||
|
End If
|
||||||
|
|
||||||
|
|
||||||
|
Dim sql As String
|
||||||
|
Dim dbcomm As MySqlCommand
|
||||||
|
Dim dbread As MySqlDataReader
|
||||||
|
|
||||||
|
'If no invalid data entry is detected...
|
||||||
|
If Errors = "" Then
|
||||||
|
'Runs the username generation subroutine
|
||||||
|
Username()
|
||||||
|
'Displays a validation message box before saving the data to the database
|
||||||
|
Result = MsgBox("Are you sure all these details are correct? Remember, spelling is vital." & vbCrLf & vbCrLf & "Details:" & vbCrLf & txtStudentFirstName.Text & " " & txtStudentLastName.Text & vbCrLf & cmboYear.SelectedItem & cmboForm.SelectedItem, MsgBoxStyle.YesNo)
|
||||||
|
'If the data is approved by the user...
|
||||||
|
If Result = MsgBoxResult.Yes Then
|
||||||
|
'Builds SQL query to execute
|
||||||
|
sql = "INSERT INTO `cl51-ben`.`tblstudents` (`Fname`, `Lname`, `Username`, `Password`, `FormNum`, `FormLetter`) VALUES ('" & txtStudentFirstName.Text & "', '" & txtStudentLastName.Text & "', '" & Uname & "', 'password', '" & cmboYear.SelectedItem & "', '" & cmboForm.SelectedItem & "');"
|
||||||
|
|
||||||
|
dbcomm = New MySqlCommand(sql, DBConn)
|
||||||
|
dbread = dbcomm.ExecuteReader()
|
||||||
|
dbread.Close()
|
||||||
|
|
||||||
|
'Creates the wins and losses text file for the student
|
||||||
|
Dim file As System.IO.FileStream
|
||||||
|
file = System.IO.File.Create(Uname & ".txt")
|
||||||
|
|
||||||
|
'Copies the image to the folder for student images and renames it to the new student's username
|
||||||
|
My.Computer.FileSystem.CopyFile(Filepath, Uname & ".jpg", FileIO.UIOption.AllDialogs, FileIO.UICancelOption.DoNothing)
|
||||||
|
End If
|
||||||
|
'If any invalid data entry is detected...
|
||||||
|
Else
|
||||||
|
'Displays a message box with any detected invalid data entry
|
||||||
|
MsgBox("Invalid input:" & vbCrLf & vbCrLf & Errors)
|
||||||
|
End If
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when called in the add teacher button sub
|
||||||
|
Sub Username()
|
||||||
|
|
||||||
|
'Declares the variable used to get the first letter of the new teacher's first name
|
||||||
|
Dim L1 As String = Mid(txtStudentFirstName.Text, 1, 1)
|
||||||
|
'Declares the variable used to get the first letter of the new teacher's last name
|
||||||
|
Dim L2 As String = Mid(txtStudentLastName.Text, 1, 1)
|
||||||
|
'Declares the variable used to get the numbers at the end of the new teacher's username
|
||||||
|
Dim Numbers As Integer = 11
|
||||||
|
Dim sql As String
|
||||||
|
Dim dbcomm As MySqlCommand
|
||||||
|
Dim dbread As MySqlDataReader
|
||||||
|
'Assembles the beginning and middle of the username
|
||||||
|
Uname = "95" & L1 & L2
|
||||||
|
|
||||||
|
'Builds SQL query to execute
|
||||||
|
sql = "SELECT * FROM tblstudents WHERE Username='" & Uname & Numbers & "'"
|
||||||
|
|
||||||
|
dbcomm = New MySqlCommand(sql, DBConn)
|
||||||
|
dbread = dbcomm.ExecuteReader()
|
||||||
|
'Fills the various properties of the LoggedInStudent object with their respective values from the database
|
||||||
|
While dbread.Read
|
||||||
|
dbread.Close()
|
||||||
|
'Increases the numbers on the end of the username
|
||||||
|
Numbers = Numbers + 1
|
||||||
|
'Opens a new recordset to check if the new username isn't taken
|
||||||
|
sql = "SELECT * FROM tblstudents WHERE Username='" & Uname & Numbers & "'"
|
||||||
|
dbcomm = New MySqlCommand(sql, DBConn)
|
||||||
|
dbread = dbcomm.ExecuteReader()
|
||||||
|
End While
|
||||||
|
dbread.Close()
|
||||||
|
'Assembles the username
|
||||||
|
Uname = Uname & Numbers
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when the browse pic button is clicked
|
||||||
|
Private Sub btnBrowsePic_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowsePic.Click
|
||||||
|
'Sets the filter of the browse window to only allow image files
|
||||||
|
diaPic.Filter = "Image Files|*.jpg;*.gif;*.bmp;*.png;*.jpeg|All Files|*.*"
|
||||||
|
'Sets the starting directory of the browse window to the C: drive
|
||||||
|
diaPic.InitialDirectory = "C:\"
|
||||||
|
'Sets the filter index of the browse window
|
||||||
|
diaPic.FilterIndex = 1
|
||||||
|
'Sets the title of the browse window
|
||||||
|
diaPic.Title = "Open File"
|
||||||
|
'If okay button of browse window is clicked...
|
||||||
|
If (diaPic.ShowDialog() = Windows.Forms.DialogResult.OK) Then
|
||||||
|
'Sets filepath to image
|
||||||
|
Filepath = diaPic.FileName
|
||||||
|
'Sets displayed image to selected image file
|
||||||
|
picPic.Image = Image.FromFile(Filepath)
|
||||||
|
'Sets picture box tag to indicate that a picture has been selected
|
||||||
|
picPic.Tag = 1
|
||||||
|
End If
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
End Class
|
57
FirstTimeSetup/frmAddSubject.vb
Normal file
57
FirstTimeSetup/frmAddSubject.vb
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
Imports MySql.Data.MySqlClient
|
||||||
|
|
||||||
|
Public Class frmAddSubject
|
||||||
|
|
||||||
|
'Subroutine runs when the form loads
|
||||||
|
Private Sub frmAddSubject_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
|
||||||
|
'Establishes the connection to the database
|
||||||
|
OpenDB()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when the add subject button is clicked
|
||||||
|
Private Sub btnAddSubject_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddSubject.Click
|
||||||
|
'Declares the variable used for detecting invalid data entry
|
||||||
|
Dim Errors As String = ""
|
||||||
|
'Declares the variable used for getting the result of the message box
|
||||||
|
Dim Result As MsgBoxResult
|
||||||
|
Dim sql As String
|
||||||
|
Dim dbcomm As MySqlCommand
|
||||||
|
Dim dbread As MySqlDataReader
|
||||||
|
|
||||||
|
'Assembles an error report if any invalid data entry detected
|
||||||
|
If txtSubjectName.Text = "" Then
|
||||||
|
Errors = Errors & "No subject name input" & vbCrLf
|
||||||
|
End If
|
||||||
|
|
||||||
|
'If no invalid data entry is detected...
|
||||||
|
If Errors = "" Then
|
||||||
|
'Displays a validation message box before saving the data to the database
|
||||||
|
Result = MsgBox("Are you sure all these details are correct? Remember, spelling is vital." & vbCrLf & vbCrLf & "Details:" & vbCrLf & txtSubjectName.Text, MsgBoxStyle.YesNo)
|
||||||
|
'If the data is approved by the user...
|
||||||
|
If Result = MsgBoxResult.Yes Then
|
||||||
|
'Builds SQL query to execute
|
||||||
|
sql = "INSERT INTO `cl51-ben`.`tblsubjects` (`Subject`) VALUES ('" & txtSubjectName.Text & "');"
|
||||||
|
|
||||||
|
dbcomm = New MySqlCommand(sql, DBConn)
|
||||||
|
dbread = dbcomm.ExecuteReader()
|
||||||
|
dbread.Close()
|
||||||
|
|
||||||
|
'Creates the topics text file for the subject
|
||||||
|
Dim file As System.IO.FileStream
|
||||||
|
file = System.IO.File.Create(txtSubjectName.Text & "Topics.txt")
|
||||||
|
file.Close()
|
||||||
|
End If
|
||||||
|
'If any invalid data entry is detected...
|
||||||
|
Else
|
||||||
|
'Displays a message box with any detected invalid data entry
|
||||||
|
MsgBox("Invalid input:" & vbCrLf & vbCrLf & Errors)
|
||||||
|
End If
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when the subject name text box is clicked
|
||||||
|
Private Sub txtSubjectName_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtSubjectName.Click
|
||||||
|
'Blanks out the text box
|
||||||
|
txtSubjectName.Text = ""
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
End Class
|
139
FirstTimeSetup/frmAddTeacher.vb
Normal file
139
FirstTimeSetup/frmAddTeacher.vb
Normal file
|
@ -0,0 +1,139 @@
|
||||||
|
Imports MySql.Data.MySqlClient
|
||||||
|
|
||||||
|
Public Class frmAddTeacher
|
||||||
|
|
||||||
|
'Declares the variable used for generating the username of the new student
|
||||||
|
Dim Uname As String
|
||||||
|
'Declares the variable used for getting the image of the new student
|
||||||
|
Dim Filepath As String
|
||||||
|
|
||||||
|
'Subroutine runs when the form loads
|
||||||
|
Private Sub frmAddTeacher_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
|
||||||
|
'Establishes the connection to the database
|
||||||
|
OpenDB()
|
||||||
|
|
||||||
|
'Indicates that no picture has been selected
|
||||||
|
picPic.Tag = 0
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when the teacher first name text box is clicked
|
||||||
|
Private Sub txtTeacherFirstName_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtTeacherFirstName.Click
|
||||||
|
'Blanks out the text box
|
||||||
|
txtTeacherFirstName.Text = ""
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when the teacher last name text box is clicked
|
||||||
|
Private Sub txtTeacherLastName_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtTeacherLastName.Click
|
||||||
|
'Blanks out the text box
|
||||||
|
txtTeacherLastName.Text = ""
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when the add teacher button is clicked
|
||||||
|
Private Sub btnAddTeacher_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddTeacher.Click
|
||||||
|
'Declares the variable used for getting the result of the message box
|
||||||
|
Dim Result As MsgBoxResult
|
||||||
|
'Declares the variable used for detecting invalid data entry
|
||||||
|
Dim Errors As String = ""
|
||||||
|
|
||||||
|
'Assembles an error report if any invalid data entry detected
|
||||||
|
If txtTeacherFirstName.Text = "" Then
|
||||||
|
Errors = Errors & "No first name input" & vbCrLf
|
||||||
|
End If
|
||||||
|
If txtTeacherLastName.Text = "" Then
|
||||||
|
Errors = Errors & "No last name input" & vbCrLf
|
||||||
|
End If
|
||||||
|
If picPic.Tag = 0 Then
|
||||||
|
Errors = Errors & "No picture input" & vbCrLf
|
||||||
|
End If
|
||||||
|
|
||||||
|
|
||||||
|
Dim sql As String
|
||||||
|
Dim dbcomm As MySqlCommand
|
||||||
|
Dim dbread As MySqlDataReader
|
||||||
|
|
||||||
|
'If no invalid data entry is detected...
|
||||||
|
If Errors = "" Then
|
||||||
|
'Runs the username generation subroutine
|
||||||
|
Username()
|
||||||
|
'Displays a validation message box before saving the data to the database
|
||||||
|
Result = MsgBox("Are you sure all these details are correct? Remember, spelling is vital." & vbCrLf & vbCrLf & "Details:" & vbCrLf & txtTeacherFirstName.Text & " " & txtTeacherLastName.Text, MsgBoxStyle.YesNo)
|
||||||
|
'If the data is approved by the user...
|
||||||
|
If Result = MsgBoxResult.Yes Then
|
||||||
|
'Builds SQL query to execute
|
||||||
|
sql = "INSERT INTO `cl51-ben`.`tblteachers` (`Fname`, `Lname`, `Username`, `Password`) VALUES ('" & txtTeacherFirstName.Text & "', '" & txtTeacherLastName.Text & "', '" & Uname & "', 'password');"
|
||||||
|
|
||||||
|
dbcomm = New MySqlCommand(sql, DBConn)
|
||||||
|
dbread = dbcomm.ExecuteReader()
|
||||||
|
dbread.Close()
|
||||||
|
|
||||||
|
'Creates the question creation text file for the teacher
|
||||||
|
Dim file As System.IO.FileStream
|
||||||
|
file = System.IO.File.Create(Uname & ".txt")
|
||||||
|
|
||||||
|
'Copies the image to the folder for student images and renames it to the new student's username
|
||||||
|
My.Computer.FileSystem.CopyFile(Filepath, Uname & ".jpg", FileIO.UIOption.AllDialogs, FileIO.UICancelOption.DoNothing)
|
||||||
|
End If
|
||||||
|
'If any invalid data entry is detected...
|
||||||
|
Else
|
||||||
|
'Displays a message box with any detected invalid data entry
|
||||||
|
MsgBox("Invalid input:" & vbCrLf & vbCrLf & Errors)
|
||||||
|
End If
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when called in the add teacher button sub
|
||||||
|
Sub Username()
|
||||||
|
|
||||||
|
'Declares the variable used to get the first letter of the new teacher's first name
|
||||||
|
Dim L1 As String = Mid(txtTeacherFirstName.Text, 1, 1)
|
||||||
|
'Declares the variable used to get the first letter of the new teacher's last name
|
||||||
|
Dim L2 As String = Mid(txtTeacherLastName.Text, 1, 1)
|
||||||
|
'Declares the variable used to get the numbers at the end of the new teacher's username
|
||||||
|
Dim Numbers As Integer = 11
|
||||||
|
Dim sql As String
|
||||||
|
Dim dbcomm As MySqlCommand
|
||||||
|
Dim dbread As MySqlDataReader
|
||||||
|
'Assembles the beginning and middle of the username
|
||||||
|
Uname = "st" & L1 & L2
|
||||||
|
|
||||||
|
'Builds SQL query to execute
|
||||||
|
sql = "SELECT * FROM tblteachers WHERE Username='" & Uname & Numbers & "'"
|
||||||
|
|
||||||
|
dbcomm = New MySqlCommand(sql, DBConn)
|
||||||
|
dbread = dbcomm.ExecuteReader()
|
||||||
|
'Fills the various properties of the LoggedInStudent object with their respective values from the database
|
||||||
|
While dbread.Read
|
||||||
|
dbread.Close()
|
||||||
|
'Increases the numbers on the end of the username
|
||||||
|
Numbers = Numbers + 1
|
||||||
|
'Opens a new recordset to check if the new username isn't taken
|
||||||
|
sql = "SELECT * FROM tblteachers WHERE Username='" & Uname & Numbers & "'"
|
||||||
|
dbcomm = New MySqlCommand(sql, DBConn)
|
||||||
|
dbread = dbcomm.ExecuteReader()
|
||||||
|
End While
|
||||||
|
dbread.Close()
|
||||||
|
'Assembles the username
|
||||||
|
Uname = Uname & Numbers
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when the browse pic button is clicked
|
||||||
|
Private Sub btnBrowsePic_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowsePic.Click
|
||||||
|
'Sets the filter of the browse window to only allow image files
|
||||||
|
diaPic.Filter = "Image Files|*.jpg;*.gif;*.bmp;*.png;*.jpeg|All Files|*.*"
|
||||||
|
'Sets the starting directory of the browse window to the C: drive
|
||||||
|
diaPic.InitialDirectory = "C:\"
|
||||||
|
'Sets the filter index of the browse window
|
||||||
|
diaPic.FilterIndex = 1
|
||||||
|
'Sets the title of the browse window
|
||||||
|
diaPic.Title = "Open File"
|
||||||
|
'If okay button of browse window is clicked...
|
||||||
|
If (diaPic.ShowDialog() = Windows.Forms.DialogResult.OK) Then
|
||||||
|
'Sets filepath to image
|
||||||
|
Filepath = diaPic.FileName
|
||||||
|
'Sets displayed image to selected image file
|
||||||
|
picPic.Image = Image.FromFile(Filepath)
|
||||||
|
'Sets picture box tag to indicate that a picture has been selected
|
||||||
|
picPic.Tag = 1
|
||||||
|
End If
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
End Class
|
79
FirstTimeSetup/frmAddTopic.vb
Normal file
79
FirstTimeSetup/frmAddTopic.vb
Normal file
|
@ -0,0 +1,79 @@
|
||||||
|
Imports MySql.Data.MySqlClient
|
||||||
|
|
||||||
|
Public Class frmAddTopic
|
||||||
|
|
||||||
|
'Subroutine runs when the form loads
|
||||||
|
Private Sub frmAddTopic_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
|
||||||
|
'Establishes the connection to the database
|
||||||
|
OpenDB()
|
||||||
|
|
||||||
|
'Runs the form population subroutine
|
||||||
|
Populate()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when the add topic button is clicked
|
||||||
|
Private Sub btnAddTopic_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddTopic.Click
|
||||||
|
'Runs the form population subroutine
|
||||||
|
CheckValid()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when called in the form load sub
|
||||||
|
Sub Populate()
|
||||||
|
Dim sql As String
|
||||||
|
Dim dbcomm As MySqlCommand
|
||||||
|
Dim dbread As MySqlDataReader
|
||||||
|
|
||||||
|
'Builds SQL query to execute
|
||||||
|
sql = "SELECT * FROM tblsubjects"
|
||||||
|
|
||||||
|
dbcomm = New MySqlCommand(sql, DBConn)
|
||||||
|
dbread = dbcomm.ExecuteReader()
|
||||||
|
'Fills the various properties of the LoggedInStudent object with their respective values from the database
|
||||||
|
While dbread.Read
|
||||||
|
'Populates the subject combobox with data
|
||||||
|
cmboSubject.Items.Add(dbread("Subject"))
|
||||||
|
End While
|
||||||
|
dbread.Close()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when called in the add topic button sub
|
||||||
|
Sub CheckValid()
|
||||||
|
'Declares the variable used for getting the result of the message box
|
||||||
|
Dim Result As MsgBoxResult
|
||||||
|
'Declares the variable used for detecting invalid data entry
|
||||||
|
Dim Errors As String = ""
|
||||||
|
|
||||||
|
'Assembles an error report if any invalid data entry detected
|
||||||
|
If cmboSubject.Text = "" Then
|
||||||
|
Errors = Errors & "No subject selected" & vbCrLf
|
||||||
|
End If
|
||||||
|
If cmboYear.Text = "" Then
|
||||||
|
Errors = Errors & "No year selected" & vbCrLf
|
||||||
|
End If
|
||||||
|
If txtTopic.Text = "" Then
|
||||||
|
Errors = Errors & "No topic input" & vbCrLf
|
||||||
|
End If
|
||||||
|
|
||||||
|
'If no invalid data entry is detected...
|
||||||
|
If Errors = "" Then
|
||||||
|
'Displays a validation message box before saving the data to the database
|
||||||
|
Result = MsgBox("Are you sure all these details are correct? Remember, spelling is vital." & vbCrLf & vbCrLf & "Details:" & vbCrLf & cmboSubject.SelectedItem & " (" & cmboYear.SelectedItem & ")" & vbCrLf & txtTopic.Text, MsgBoxStyle.YesNo)
|
||||||
|
'If the data is approved by the user...
|
||||||
|
If Result = MsgBoxResult.Yes Then
|
||||||
|
'Declares the variable used for writing to the text file
|
||||||
|
Dim writer As System.IO.StreamWriter
|
||||||
|
'Gets the filepath to the selected subject's topic text file, creating it if it doesn't exist
|
||||||
|
writer = My.Computer.FileSystem.OpenTextFileWriter(cmboSubject.Text & "Topics.txt", True)
|
||||||
|
'Adds the new topic to the selected subject's topics text file
|
||||||
|
writer.WriteLine(txtTopic.Text & " (" & cmboYear.Text & ")")
|
||||||
|
'Saves the text file
|
||||||
|
writer.Close()
|
||||||
|
End If
|
||||||
|
'If any invalid data entry is detected...
|
||||||
|
Else
|
||||||
|
'Displays a message box with any detected invalid data entry
|
||||||
|
MsgBox("Invalid input:" & vbCrLf & vbCrLf & Errors)
|
||||||
|
End If
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
End Class
|
26
FirstTimeSetup/frmFTSMsg.vb
Normal file
26
FirstTimeSetup/frmFTSMsg.vb
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
Public Class frmFTSMsg
|
||||||
|
|
||||||
|
'Subroutine runs when the yes button is clicked
|
||||||
|
Private Sub btnYes_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnYes.Click
|
||||||
|
'Closes the login form
|
||||||
|
frmLogin.Close()
|
||||||
|
'Opens the first-time setup form
|
||||||
|
frmFirstTimeSetup.Show()
|
||||||
|
'Closes this form
|
||||||
|
Me.Close()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when the no button is clicked
|
||||||
|
Private Sub btnNo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNo.Click
|
||||||
|
'Declares the variable used for writing to the text file
|
||||||
|
Dim writer As System.IO.StreamWriter
|
||||||
|
'Gets the filepath to the first-time setup text file
|
||||||
|
writer = My.Computer.FileSystem.OpenTextFileWriter("FTS.txt", False)
|
||||||
|
'Amends the text file to indicate that the first-time setup has been run
|
||||||
|
writer.WriteLine("1")
|
||||||
|
'Saves the log file
|
||||||
|
writer.Close()
|
||||||
|
'Closes this form
|
||||||
|
Me.Close()
|
||||||
|
End Sub
|
||||||
|
End Class
|
44
FirstTimeSetup/frmFirstTimeSetup.vb
Normal file
44
FirstTimeSetup/frmFirstTimeSetup.vb
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
Public Class frmFirstTimeSetup
|
||||||
|
|
||||||
|
'Subroutine runs when the add subject button is clicked
|
||||||
|
Private Sub btnAddSubject_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddSubject.Click
|
||||||
|
'Opens the add subject form
|
||||||
|
frmAddSubject.Show()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when the add topic button is clicked
|
||||||
|
Private Sub btnAddTopic_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddTopic.Click
|
||||||
|
'Opens the add topic form
|
||||||
|
frmAddTopic.Show()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when the add teacher button is clicked
|
||||||
|
Private Sub btnAddTeacher_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddTeacher.Click
|
||||||
|
'Opens the add teacher form
|
||||||
|
frmAddTeacher.Show()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when the add student button is clicked
|
||||||
|
Private Sub btnAddStudent_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddStudent.Click
|
||||||
|
'Opens the add student form
|
||||||
|
frmAddStudent.Show()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when the done button is clicked
|
||||||
|
Private Sub btnDone_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDone.Click
|
||||||
|
'Declares the variable used for writing to the text file
|
||||||
|
Dim writer As System.IO.StreamWriter
|
||||||
|
'Gets the filepath to the first-time setup text file
|
||||||
|
writer = My.Computer.FileSystem.OpenTextFileWriter("FTS.txt", False)
|
||||||
|
'Amends the text file to indicate that the first-time setup has been run
|
||||||
|
writer.WriteLine("1")
|
||||||
|
'Saves the log file
|
||||||
|
writer.Close()
|
||||||
|
|
||||||
|
'Opens the login form
|
||||||
|
frmLogin.Show()
|
||||||
|
'Closes this form
|
||||||
|
Me.Close()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
End Class
|
5
README.md
Normal file
5
README.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
Are You Not Edutained?!
|
||||||
|
======================
|
||||||
|
|
||||||
|
My A2 Computing project, an edutainment suite featuring achievements, 3 hotseat games and one network one. Got me an A.
|
||||||
|
Materials used: VB.NET
|
995
StudentForms/ConnectFour/frmConnect4Hotseat.vb
Normal file
995
StudentForms/ConnectFour/frmConnect4Hotseat.vb
Normal file
|
@ -0,0 +1,995 @@
|
||||||
|
Imports MySql.Data.MySqlClient
|
||||||
|
|
||||||
|
Public Class frmConnect4Hotseat
|
||||||
|
|
||||||
|
'Declares the variable used to determine the horizontal coordinate of the square being used
|
||||||
|
Dim x As Integer = 1
|
||||||
|
'Declares the variable used to determine the vertical coordinate of the square being used
|
||||||
|
Dim y As Integer = 1
|
||||||
|
'Declares the array containing the coordinates of all the pictureboxes that make up the grid
|
||||||
|
Dim Group(7, 6) As PictureBox
|
||||||
|
'Declares the array containing the coordinates of the squares of the grid and what condition they are currently in
|
||||||
|
'0 = Empty
|
||||||
|
'1 = Red
|
||||||
|
'2= Yellow
|
||||||
|
'3 = Terminator
|
||||||
|
Dim theGrid(7, 7) As Integer
|
||||||
|
'Declares the array containing the number of the buttons for dropping counters
|
||||||
|
Dim Buttons(7) As Button
|
||||||
|
|
||||||
|
'Declares the class used for both players
|
||||||
|
Public Class C4Play
|
||||||
|
'Declares the variables used for storing the details of the Connect Four player
|
||||||
|
Public Colour, Username, Fname, lname As String
|
||||||
|
End Class
|
||||||
|
'Declares the class used for both players' scores
|
||||||
|
Public Class Score
|
||||||
|
'Declares the variable used for storing score of the player
|
||||||
|
Public ScoreNum As Integer
|
||||||
|
'This subroutine runs when a player wins a game
|
||||||
|
Public Sub Increase()
|
||||||
|
'Increases the score by 1
|
||||||
|
ScoreNum = ScoreNum + 1
|
||||||
|
End Sub
|
||||||
|
End Class
|
||||||
|
'Creates two objects of the Score class, one for each player
|
||||||
|
Dim RedScore As New Score
|
||||||
|
Dim YellowScore As New Score
|
||||||
|
'Creates two objects of the C4Play class, one for each player
|
||||||
|
Dim RedPlayer As New C4Play
|
||||||
|
Dim YellowPlayer As New C4Play
|
||||||
|
|
||||||
|
'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 for detecting wins along the y-axis
|
||||||
|
Dim Why As Integer
|
||||||
|
'Declares the variable used to keep track of how many reds in a row there are
|
||||||
|
Dim RedAddUp As Integer = 0
|
||||||
|
'Declares the variable used to keep track of how many yellow in a row there are
|
||||||
|
Dim YellowAddUp As Integer = 0
|
||||||
|
'Declares the variable used to determine if a question was answered correctly
|
||||||
|
Dim QCorrect As Boolean = False
|
||||||
|
'Declares the variables used to store whether there is a winner or the game is a draw
|
||||||
|
Dim Won As Boolean = False
|
||||||
|
Dim Draw As Boolean = False
|
||||||
|
|
||||||
|
'Subroutine runs on form load
|
||||||
|
Private Sub frmConnect4Hotseat_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
|
||||||
|
'Runs the OpenDB subroutine
|
||||||
|
OpenDB()
|
||||||
|
|
||||||
|
'If the logged-in student is red...
|
||||||
|
If LoggedInStudent.C4Player = "Red" Then
|
||||||
|
'Populate the RedPlayer object with the logged-in student's details
|
||||||
|
With RedPlayer
|
||||||
|
.Colour = "Red"
|
||||||
|
.Username = LoggedInStudent.Username
|
||||||
|
.Fname = LoggedInStudent.Fname
|
||||||
|
.lname = LoggedInStudent.Lname
|
||||||
|
End With
|
||||||
|
|
||||||
|
'Populate the YellowPlayer object with the opponent student's details
|
||||||
|
With YellowPlayer
|
||||||
|
.Colour = "Yellow"
|
||||||
|
.Username = OppStudent.Username
|
||||||
|
.Fname = OppStudent.Fname
|
||||||
|
.lname = OppStudent.Lname
|
||||||
|
End With
|
||||||
|
'But if the logged-in student is yellow...
|
||||||
|
Else
|
||||||
|
'Populate the RedPlayer object with the logged-in student's details
|
||||||
|
With RedPlayer
|
||||||
|
.Colour = "Red"
|
||||||
|
.Username = OppStudent.Username
|
||||||
|
.Fname = OppStudent.Fname
|
||||||
|
.lname = OppStudent.Lname
|
||||||
|
End With
|
||||||
|
|
||||||
|
'Populate the YellowPlayer object with the opponent student's details
|
||||||
|
With YellowPlayer
|
||||||
|
.Colour = "Yellow"
|
||||||
|
.Username = LoggedInStudent.Username
|
||||||
|
.Fname = LoggedInStudent.Fname
|
||||||
|
.lname = LoggedInStudent.Lname
|
||||||
|
End With
|
||||||
|
End If
|
||||||
|
|
||||||
|
'Runs the AccountSection subroutine
|
||||||
|
AccountSection()
|
||||||
|
'Runs the MakeGrid subroutine
|
||||||
|
MakeGrid()
|
||||||
|
'Runs the Terminators subroutine
|
||||||
|
Terminators()
|
||||||
|
|
||||||
|
'Declares the variables used to store the current horizontal and vertical coordinates of the grid
|
||||||
|
Dim GridHor, GridVer As Integer
|
||||||
|
|
||||||
|
'For each column of the grid...
|
||||||
|
For GridHor = 1 To 7
|
||||||
|
'For each square in that column...
|
||||||
|
For GridVer = 1 To 6
|
||||||
|
'Set the value to empty
|
||||||
|
theGrid(GridHor, GridVer) = 0
|
||||||
|
Next
|
||||||
|
Next
|
||||||
|
|
||||||
|
'Sets the scores to the defaults
|
||||||
|
RedScore.ScoreNum = 0
|
||||||
|
YellowScore.ScoreNum = 0
|
||||||
|
|
||||||
|
'Sets the current player, runs the ChangePlayer and CurrPlayer subroutines
|
||||||
|
C4Player = "Yellow"
|
||||||
|
ChangePlayer()
|
||||||
|
CurrPlayer()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when called in DetectWinner 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 red player is the winner...
|
||||||
|
If RedScore.ScoreNum = 1 Then
|
||||||
|
If RedPlayer.Username = LoggedInStudent.Username Then
|
||||||
|
'Builds SQL query to execute
|
||||||
|
sql = "UPDATE `tblstudents` SET `Wins`=`Wins`+1 WHERE `Username`='" & RedPlayer.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(RedPlayer.Username & ".txt", True)
|
||||||
|
|
||||||
|
'Writes the relevant data to the log
|
||||||
|
writer.WriteLine(RedPlayer.Fname & " " & RedPlayer.lname & " beat " & YellowPlayer.Fname & " " & YellowPlayer.lname & " in Connect Four - " & TimeOfDay & " " & DateValue(Now))
|
||||||
|
'Saves the log file
|
||||||
|
writer.Close()
|
||||||
|
ElseIf YellowPlayer.Username = LoggedInStudent.Username Then
|
||||||
|
'Builds SQL query to execute
|
||||||
|
sql = "UPDATE `tblstudents` SET `Losses`=`Losses`+1 WHERE `Username`='" & YellowPlayer.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(YellowPlayer.Username & ".txt", True)
|
||||||
|
|
||||||
|
'Writes the relevant data to the log
|
||||||
|
writer.WriteLine(YellowPlayer.Fname & " " & YellowPlayer.lname & " was beaten by " & RedPlayer.Fname & " " & RedPlayer.lname & " in Connect Four - " & TimeOfDay & " " & DateValue(Now))
|
||||||
|
'Saves the log file
|
||||||
|
writer.Close()
|
||||||
|
End If
|
||||||
|
|
||||||
|
'Resets the red score back to its default
|
||||||
|
RedScore.ScoreNum = 0
|
||||||
|
End If
|
||||||
|
'However, if the yellow player is the winner...
|
||||||
|
If YellowScore.ScoreNum = 1 Then
|
||||||
|
If YellowPlayer.Username = LoggedInStudent.Username Then
|
||||||
|
'Builds SQL query to execute
|
||||||
|
sql = "UPDATE `tblstudents` SET `Wins`=`Wins`+1 WHERE `Username`='" & YellowPlayer.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(YellowPlayer.Username & ".txt", True)
|
||||||
|
|
||||||
|
'Writes the relevant data to the log
|
||||||
|
writer.WriteLine(YellowPlayer.Fname & " " & YellowPlayer.lname & " beat " & RedPlayer.Fname & " " & RedPlayer.lname & " in Connect Four - " & TimeOfDay & " " & DateValue(Now))
|
||||||
|
'Saves the log file
|
||||||
|
writer.Close()
|
||||||
|
ElseIf RedPlayer.Username = LoggedInStudent.Username Then
|
||||||
|
'Builds SQL query to execute
|
||||||
|
sql = "UPDATE `tblstudents` SET `Losses`=`Losses`+1 WHERE `Username`='" & RedPlayer.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(RedPlayer.Username & ".txt", True)
|
||||||
|
|
||||||
|
'Writes the relevant data to the log
|
||||||
|
writer.WriteLine(RedPlayer.Fname & " " & RedPlayer.lname & " was beaten by " & YellowPlayer.Fname & " " & YellowPlayer.lname & " in Connect Four - " & TimeOfDay & " " & DateValue(Now))
|
||||||
|
'Saves the log file
|
||||||
|
writer.Close()
|
||||||
|
End If
|
||||||
|
'Resets the red score back to its default
|
||||||
|
YellowScore.ScoreNum = 0
|
||||||
|
End If
|
||||||
|
'However, if the game is a draw...
|
||||||
|
If Draw = True Then
|
||||||
|
If RedPlayer.Username = LoggedInStudent.Username Then
|
||||||
|
'Builds SQL query to execute
|
||||||
|
sql = "UPDATE `tblstudents` SET `Draws`=`Draws`+1 WHERE `Username`='" & RedPlayer.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(RedPlayer.Username & ".txt", True)
|
||||||
|
|
||||||
|
'Writes the relevant data to the log
|
||||||
|
writer.WriteLine(RedPlayer.Fname & " " & RedPlayer.lname & " drew with " & YellowPlayer.Fname & " " & YellowPlayer.lname & " in Connect Four - " & TimeOfDay & " " & DateValue(Now))
|
||||||
|
'Saves the log file
|
||||||
|
writer.Close()
|
||||||
|
ElseIf YellowPlayer.Username = LoggedInStudent.Username Then
|
||||||
|
'Builds SQL query to execute
|
||||||
|
sql = "UPDATE `tblstudents` SET `Draws`=`Draws`+1 WHERE `Username`='" & YellowPlayer.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(YellowPlayer.Username & ".txt", True)
|
||||||
|
|
||||||
|
'Writes the relevant data to the log
|
||||||
|
writer.WriteLine(YellowPlayer.Fname & " " & YellowPlayer.lname & " drew with " & RedPlayer.Fname & " " & RedPlayer.lname & " in Connect Four - " & TimeOfDay & " " & DateValue(Now))
|
||||||
|
'Saves the log file
|
||||||
|
writer.Close()
|
||||||
|
End If
|
||||||
|
End If
|
||||||
|
End Sub
|
||||||
|
'Subroutine runs when called in the ChangePlayer subroutine
|
||||||
|
Sub CurrPlayer()
|
||||||
|
'If the logged-in player is the same as the current player, which is red...
|
||||||
|
If LoggedInStudent.C4Player = "Red" Then
|
||||||
|
If C4Player = "Red" Then
|
||||||
|
'Places the current player label pointing to the logged-in student
|
||||||
|
lblCurrPlayer.Top = StudentCurrLocationY
|
||||||
|
'However if the current player is yellow...
|
||||||
|
Else
|
||||||
|
'Places the current player label pointing to the opponent student
|
||||||
|
lblCurrPlayer.Top = OppStudentCurrLocationY
|
||||||
|
End If
|
||||||
|
'However, if the opponent student is the same as the current player, which is yellow...
|
||||||
|
Else
|
||||||
|
If C4Player = "Yellow" Then
|
||||||
|
'Places the current player label pointing to the logged-in student
|
||||||
|
lblCurrPlayer.Top = StudentCurrLocationY
|
||||||
|
'However if the current player is red...
|
||||||
|
Else
|
||||||
|
'Places the current player label pointing to the opponent student
|
||||||
|
lblCurrPlayer.Top = OppStudentCurrLocationY
|
||||||
|
End If
|
||||||
|
End If
|
||||||
|
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 = RedPlayer.Username & ".jpg"
|
||||||
|
|
||||||
|
lblOppStudentName.Text = OppStudent.Fname & " " & OppStudent.Lname
|
||||||
|
picOppStudentPic.ImageLocation = YellowPlayer.Username & ".jpg"
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when called in form load subroutine
|
||||||
|
Sub MakeGrid()
|
||||||
|
'Ties the Buttons array with the button controls for dropping counters
|
||||||
|
Buttons(1) = btn1
|
||||||
|
Buttons(2) = btn2
|
||||||
|
Buttons(3) = btn3
|
||||||
|
Buttons(4) = btn4
|
||||||
|
Buttons(5) = btn5
|
||||||
|
Buttons(6) = btn6
|
||||||
|
Buttons(7) = btn7
|
||||||
|
|
||||||
|
'Ties the Group coordinates with the pictureboxes on the form
|
||||||
|
Group(1, 1) = pb1dash1
|
||||||
|
Group(1, 2) = pb1dash2
|
||||||
|
Group(1, 3) = pb1dash3
|
||||||
|
Group(1, 4) = pb1dash4
|
||||||
|
Group(1, 5) = pb1dash5
|
||||||
|
Group(1, 6) = pb1dash6
|
||||||
|
|
||||||
|
Group(2, 1) = pb2dash1
|
||||||
|
Group(2, 2) = pb2dash2
|
||||||
|
Group(2, 3) = pb2dash3
|
||||||
|
Group(2, 4) = pb2dash4
|
||||||
|
Group(2, 5) = pb2dash5
|
||||||
|
Group(2, 6) = pb2dash6
|
||||||
|
|
||||||
|
Group(3, 1) = pb3dash1
|
||||||
|
Group(3, 2) = pb3dash2
|
||||||
|
Group(3, 3) = pb3dash3
|
||||||
|
Group(3, 4) = pb3dash4
|
||||||
|
Group(3, 5) = pb3dash5
|
||||||
|
Group(3, 6) = pb3dash6
|
||||||
|
|
||||||
|
Group(4, 1) = pb4dash1
|
||||||
|
Group(4, 2) = pb4dash2
|
||||||
|
Group(4, 3) = pb4dash3
|
||||||
|
Group(4, 4) = pb4dash4
|
||||||
|
Group(4, 5) = pb4dash5
|
||||||
|
Group(4, 6) = pb4dash6
|
||||||
|
|
||||||
|
Group(5, 1) = pb5dash1
|
||||||
|
Group(5, 2) = pb5dash2
|
||||||
|
Group(5, 3) = pb5dash3
|
||||||
|
Group(5, 4) = pb5dash4
|
||||||
|
Group(5, 5) = pb5dash5
|
||||||
|
Group(5, 6) = pb5dash6
|
||||||
|
|
||||||
|
Group(6, 1) = pb6dash1
|
||||||
|
Group(6, 2) = pb6dash2
|
||||||
|
Group(6, 3) = pb6dash3
|
||||||
|
Group(6, 4) = pb6dash4
|
||||||
|
Group(6, 5) = pb6dash5
|
||||||
|
Group(6, 6) = pb6dash6
|
||||||
|
|
||||||
|
Group(7, 1) = pb7dash1
|
||||||
|
Group(7, 2) = pb7dash2
|
||||||
|
Group(7, 3) = pb7dash3
|
||||||
|
Group(7, 4) = pb7dash4
|
||||||
|
Group(7, 5) = pb7dash5
|
||||||
|
Group(7, 6) = pb7dash6
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when called in form load and btnReset_Click subroutines
|
||||||
|
Sub Terminators()
|
||||||
|
'Sets the extra seventh horizontal line of squares in theGrid to terminators
|
||||||
|
While y <> 8
|
||||||
|
theGrid(y, 7) = 3
|
||||||
|
y = y + 1
|
||||||
|
End While
|
||||||
|
|
||||||
|
'Sets x back to 1 for use later
|
||||||
|
y = 1
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when called in button click subroutines
|
||||||
|
Sub CounterPlace()
|
||||||
|
'Runs down the column to find the next blank space
|
||||||
|
While theGrid(x, y) = 0
|
||||||
|
y = y + 1
|
||||||
|
End While
|
||||||
|
|
||||||
|
'Changes the next blank space into the current player's marker and claims the square for them
|
||||||
|
If theGrid(x, 2) = 0 Then
|
||||||
|
y = y - 1
|
||||||
|
|
||||||
|
If C4Player = "Red" Then
|
||||||
|
theGrid(x, y) = 1
|
||||||
|
Group(x, y).Image = My.Resources.red
|
||||||
|
Else
|
||||||
|
theGrid(x, y) = 2
|
||||||
|
Group(x, y).Image = My.Resources.yellow
|
||||||
|
End If
|
||||||
|
Else
|
||||||
|
'If the only square left in the current row is the topmost one, the button disables after being pressed to seal off the column
|
||||||
|
y = y - 1
|
||||||
|
If C4Player = "Red" Then
|
||||||
|
theGrid(x, y) = 1
|
||||||
|
Group(x, y).Image = My.Resources.red
|
||||||
|
Else
|
||||||
|
theGrid(x, y) = 2
|
||||||
|
Group(x, y).Image = My.Resources.yellow
|
||||||
|
End If
|
||||||
|
Buttons(x).Enabled = False
|
||||||
|
End If
|
||||||
|
|
||||||
|
'Detects whether there is a winner
|
||||||
|
DetectWinner()
|
||||||
|
|
||||||
|
'If the game is still on, runs the ChangePlayer subroutine
|
||||||
|
If (Won = False) And (Draw = False) Then
|
||||||
|
ChangePlayer()
|
||||||
|
End If
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when called in CounterPlace subroutine
|
||||||
|
Sub DetectWinner()
|
||||||
|
'Declares the variable used to determine number of spaces to the left of the last-placed counter
|
||||||
|
Dim SpacestoLeft As Integer
|
||||||
|
'Declares the variable used to determine number of spaces to the right of the last-placed counter
|
||||||
|
Dim SpacestoRight As Integer
|
||||||
|
'Declares the variable used to determine number of spaces above the last-placed counter
|
||||||
|
Dim SpacesAbove As Integer
|
||||||
|
'Declares the variable used to determine number of spaces below the last-placed counter
|
||||||
|
Dim SpacesBelow As Integer
|
||||||
|
|
||||||
|
'///WIN CONDITIONS\\\
|
||||||
|
|
||||||
|
'/HORIZONTAL\
|
||||||
|
|
||||||
|
'Determines no. of spaces to left and right of last-placed coutner
|
||||||
|
SpacestoLeft = x - 1
|
||||||
|
SpacestoRight = 7 - x
|
||||||
|
|
||||||
|
'Runs along the row of the last-placed counter to see if there are four red or four yellows in a row
|
||||||
|
For HorizSquare As Integer = x - SpacestoLeft To x + SpacestoRight
|
||||||
|
If theGrid(HorizSquare, y) = 1 Then
|
||||||
|
YellowAddUp = 0
|
||||||
|
RedAddUp = RedAddUp + 1
|
||||||
|
'If there are four reds in a row horizontally...
|
||||||
|
If RedAddUp = 4 Then
|
||||||
|
'Gives the red player a win, pops up a messagebox, makes changes to the database and sets up the game to be reset
|
||||||
|
Won = True
|
||||||
|
RedScore.Increase()
|
||||||
|
MsgBox("Red wins")
|
||||||
|
DatabaseDetails()
|
||||||
|
btn1.Enabled = False
|
||||||
|
btn2.Enabled = False
|
||||||
|
btn3.Enabled = False
|
||||||
|
btn4.Enabled = False
|
||||||
|
btn5.Enabled = False
|
||||||
|
btn6.Enabled = False
|
||||||
|
btn7.Enabled = False
|
||||||
|
lblCurrPlayer.Visible = False
|
||||||
|
btnReset.Visible = True
|
||||||
|
End If
|
||||||
|
End If
|
||||||
|
If theGrid(HorizSquare, y) = 2 Then
|
||||||
|
RedAddUp = 0
|
||||||
|
YellowAddUp = YellowAddUp + 1
|
||||||
|
'Of there are four yellows in a row horizontally...
|
||||||
|
If YellowAddUp = 4 Then
|
||||||
|
'Gives the yellow player a win, pops up a messagebox, makes changes to the database and sets up the game to be reset
|
||||||
|
Won = True
|
||||||
|
YellowScore.Increase()
|
||||||
|
MsgBox("Yellow wins")
|
||||||
|
DatabaseDetails()
|
||||||
|
btn1.Enabled = False
|
||||||
|
btn2.Enabled = False
|
||||||
|
btn3.Enabled = False
|
||||||
|
btn4.Enabled = False
|
||||||
|
btn5.Enabled = False
|
||||||
|
btn6.Enabled = False
|
||||||
|
btn7.Enabled = False
|
||||||
|
lblCurrPlayer.Visible = False
|
||||||
|
btnReset.Visible = True
|
||||||
|
End If
|
||||||
|
End If
|
||||||
|
If theGrid(HorizSquare, y) = 0 Then
|
||||||
|
RedAddUp = 0
|
||||||
|
YellowAddUp = 0
|
||||||
|
End If
|
||||||
|
Next
|
||||||
|
|
||||||
|
'/VERTICAL\
|
||||||
|
|
||||||
|
'Determines no. of spaces above and below the last-placed coutner
|
||||||
|
SpacesAbove = y - 1
|
||||||
|
SpacesBelow = 7 - y
|
||||||
|
|
||||||
|
'Runs down the column of the last-placed counter to see if there are four red or four yellows in a row
|
||||||
|
For VertSquare As Integer = y - SpacesAbove To y + SpacesBelow
|
||||||
|
If theGrid(x, VertSquare) = 1 Then
|
||||||
|
YellowAddUp = 0
|
||||||
|
RedAddUp = RedAddUp + 1
|
||||||
|
'If there are four reds in a row vertically...
|
||||||
|
If RedAddUp = 4 Then
|
||||||
|
'Gives the red player a win, pops up a messagebox, makes changes to the database and sets up the game to be reset
|
||||||
|
Won = True
|
||||||
|
RedScore.Increase()
|
||||||
|
MsgBox("Red wins")
|
||||||
|
DatabaseDetails()
|
||||||
|
btn1.Enabled = False
|
||||||
|
btn2.Enabled = False
|
||||||
|
btn3.Enabled = False
|
||||||
|
btn4.Enabled = False
|
||||||
|
btn5.Enabled = False
|
||||||
|
btn6.Enabled = False
|
||||||
|
btn7.Enabled = False
|
||||||
|
lblCurrPlayer.Visible = False
|
||||||
|
btnReset.Visible = True
|
||||||
|
End If
|
||||||
|
End If
|
||||||
|
If theGrid(x, VertSquare) = 2 Then
|
||||||
|
RedAddUp = 0
|
||||||
|
YellowAddUp = YellowAddUp + 1
|
||||||
|
'If there are four yellow in a row vertically...
|
||||||
|
If RedAddUp = 4 Then
|
||||||
|
'Gives the yellow player a win, pops up a messagebox, makes changes to the database and sets up the game to be reset
|
||||||
|
Won = True
|
||||||
|
YellowScore.Increase()
|
||||||
|
MsgBox("Yellow wins")
|
||||||
|
DatabaseDetails()
|
||||||
|
btn1.Enabled = False
|
||||||
|
btn2.Enabled = False
|
||||||
|
btn3.Enabled = False
|
||||||
|
btn4.Enabled = False
|
||||||
|
btn5.Enabled = False
|
||||||
|
btn6.Enabled = False
|
||||||
|
btn7.Enabled = False
|
||||||
|
lblCurrPlayer.Visible = False
|
||||||
|
btnReset.Visible = True
|
||||||
|
End If
|
||||||
|
End If
|
||||||
|
If theGrid(x, VertSquare) = 0 Then
|
||||||
|
RedAddUp = 0
|
||||||
|
YellowAddUp = 0
|
||||||
|
End If
|
||||||
|
Next
|
||||||
|
|
||||||
|
'If a diagonal win in possible with the position of the last-placed counter...
|
||||||
|
If x < 5 Then
|
||||||
|
|
||||||
|
'/DIAGONAL BOTTOM-UP\
|
||||||
|
|
||||||
|
'Runs the Diag (Bottom-Up) Win Detection subroutine
|
||||||
|
DiagBUWin()
|
||||||
|
|
||||||
|
End If
|
||||||
|
|
||||||
|
'If a diagonal win in possible with the position of the last-placed counter...
|
||||||
|
If x > 3 Then
|
||||||
|
|
||||||
|
'/DIAGONAL TOP-DOWN\
|
||||||
|
|
||||||
|
'Runs the Diag (Top-Down) Win Detection subroutine
|
||||||
|
DiagTDWin()
|
||||||
|
|
||||||
|
End If
|
||||||
|
|
||||||
|
'If there is no winner...
|
||||||
|
If Won <> True Then
|
||||||
|
'Declares the variable used to keep track of how many blank squares there are left
|
||||||
|
Dim Blanks As Integer = 42
|
||||||
|
'Goes through the grid row-by-row, column-by-column, decrementing the blanks value when a non-blank square in encountered
|
||||||
|
For Why = 1 To 6
|
||||||
|
For x = 1 To 7
|
||||||
|
If theGrid(x, Why) <> 0 Then
|
||||||
|
Blanks = Blanks - 1
|
||||||
|
End If
|
||||||
|
Next
|
||||||
|
Next
|
||||||
|
'If there are no blanks left...
|
||||||
|
If Blanks = 0 Then
|
||||||
|
'Declares the game a draw, amends the database, sets the form up to reset
|
||||||
|
Draw = True
|
||||||
|
MsgBox("No-one wins, it's a draw")
|
||||||
|
DatabaseDetails()
|
||||||
|
lblCurrPlayer.Visible = False
|
||||||
|
btnReset.Visible = True
|
||||||
|
End If
|
||||||
|
End If
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when called in DetectWinner subroutine
|
||||||
|
Sub DiagTDWin()
|
||||||
|
'Declares the varables used to run through the diagonals
|
||||||
|
Dim v, z, a, w As Integer
|
||||||
|
|
||||||
|
'Sets the variables to their defaults
|
||||||
|
x = 1
|
||||||
|
v = x
|
||||||
|
a = x
|
||||||
|
z = x + 3
|
||||||
|
y = 1
|
||||||
|
|
||||||
|
'Runs through the diagonals to determine if there are four red or yellow counters in a row
|
||||||
|
For Why = 1 To 3
|
||||||
|
For x = 1 To 4
|
||||||
|
w = x
|
||||||
|
y = Why
|
||||||
|
If theGrid(x, y) = 1 Then
|
||||||
|
RedAddUp = 1
|
||||||
|
For v = a To z
|
||||||
|
x = x + 1
|
||||||
|
y = y + 1
|
||||||
|
If x < 8 Then
|
||||||
|
If theGrid(x, y) = 1 Then
|
||||||
|
RedAddUp = RedAddUp + 1
|
||||||
|
End If
|
||||||
|
'If there are four reds in a row diagonally...
|
||||||
|
If RedAddUp = 4 Then
|
||||||
|
'Gives the red player a win, pops up a messagebox, makes changes to the database and sets up the game to be reset
|
||||||
|
Won = True
|
||||||
|
RedScore.Increase()
|
||||||
|
MsgBox("Red wins")
|
||||||
|
DatabaseDetails()
|
||||||
|
btn1.Enabled = False
|
||||||
|
btn2.Enabled = False
|
||||||
|
btn3.Enabled = False
|
||||||
|
btn4.Enabled = False
|
||||||
|
btn5.Enabled = False
|
||||||
|
btn6.Enabled = False
|
||||||
|
btn7.Enabled = False
|
||||||
|
lblCurrPlayer.Visible = False
|
||||||
|
btnReset.Visible = True
|
||||||
|
Exit Sub
|
||||||
|
End If
|
||||||
|
End If
|
||||||
|
Next
|
||||||
|
End If
|
||||||
|
|
||||||
|
If theGrid(w, y) = 2 Then
|
||||||
|
YellowAddUp = 1
|
||||||
|
For v = a To z
|
||||||
|
w = w + 1
|
||||||
|
y = y + 1
|
||||||
|
If w < 8 Then
|
||||||
|
If theGrid(w, y) = 1 Then
|
||||||
|
YellowAddUp = YellowAddUp + 1
|
||||||
|
End If
|
||||||
|
'If there are four yellow in a row diagonally...
|
||||||
|
If YellowAddUp = 4 Then
|
||||||
|
'Gives the yellow player a win, pops up a messagebox, makes changes to the database and sets up the game to be reset
|
||||||
|
Won = True
|
||||||
|
YellowScore.Increase()
|
||||||
|
MsgBox("Yellow wins")
|
||||||
|
DatabaseDetails()
|
||||||
|
btn1.Enabled = False
|
||||||
|
btn2.Enabled = False
|
||||||
|
btn3.Enabled = False
|
||||||
|
btn4.Enabled = False
|
||||||
|
btn5.Enabled = False
|
||||||
|
btn6.Enabled = False
|
||||||
|
btn7.Enabled = False
|
||||||
|
lblCurrPlayer.Visible = False
|
||||||
|
btnReset.Visible = True
|
||||||
|
Exit Sub
|
||||||
|
End If
|
||||||
|
End If
|
||||||
|
Next
|
||||||
|
End If
|
||||||
|
Next
|
||||||
|
Next
|
||||||
|
|
||||||
|
'Resets the values to their defaults
|
||||||
|
RedAddUp = 0
|
||||||
|
YellowAddUp = 0
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when called in DetectWinner subroutine
|
||||||
|
Sub DiagBUWin()
|
||||||
|
'Declares the varables used to run through the diagonals
|
||||||
|
Dim v, z, a, w As Integer
|
||||||
|
|
||||||
|
'Sets the variables to their defaults
|
||||||
|
x = 1
|
||||||
|
v = x
|
||||||
|
a = x
|
||||||
|
z = x + 3
|
||||||
|
y = 6
|
||||||
|
|
||||||
|
'Runs through the diagonals to determine if there are four red or yellow counters in a row
|
||||||
|
For Why = 4 To 6
|
||||||
|
For x = 1 To 4
|
||||||
|
w = x
|
||||||
|
y = Why
|
||||||
|
If theGrid(x, y) = 1 Then
|
||||||
|
RedAddUp = 1
|
||||||
|
For v = a To z
|
||||||
|
x = x + 1
|
||||||
|
y = y - 1
|
||||||
|
If x < 8 Then
|
||||||
|
If theGrid(x, y) = 1 Then
|
||||||
|
RedAddUp = RedAddUp + 1
|
||||||
|
End If
|
||||||
|
'If there are four reds in a row diagonally...
|
||||||
|
If RedAddUp = 4 Then
|
||||||
|
'Gives the red player a win, pops up a messagebox, makes changes to the database and sets up the game to be reset
|
||||||
|
Won = True
|
||||||
|
RedScore.Increase()
|
||||||
|
MsgBox("Red wins")
|
||||||
|
DatabaseDetails()
|
||||||
|
btn1.Enabled = False
|
||||||
|
btn2.Enabled = False
|
||||||
|
btn3.Enabled = False
|
||||||
|
btn4.Enabled = False
|
||||||
|
btn5.Enabled = False
|
||||||
|
btn6.Enabled = False
|
||||||
|
btn7.Enabled = False
|
||||||
|
lblCurrPlayer.Visible = False
|
||||||
|
btnReset.Visible = True
|
||||||
|
Exit Sub
|
||||||
|
End If
|
||||||
|
End If
|
||||||
|
Next
|
||||||
|
End If
|
||||||
|
|
||||||
|
If theGrid(w, y) = 2 Then
|
||||||
|
YellowAddUp = 1
|
||||||
|
For v = a To z
|
||||||
|
w = w + 1
|
||||||
|
y = y - 1
|
||||||
|
If w < 8 Then
|
||||||
|
If theGrid(w, y) = 1 Then
|
||||||
|
YellowAddUp = YellowAddUp + 1
|
||||||
|
End If
|
||||||
|
'If there are four yellows in a row diagonally...
|
||||||
|
If YellowAddUp = 4 Then
|
||||||
|
'Gives the yellow player a win, pops up a messagebox, makes changes to the database and sets up the game to be reset
|
||||||
|
Won = True
|
||||||
|
YellowScore.Increase()
|
||||||
|
MsgBox("Yellow wins")
|
||||||
|
DatabaseDetails()
|
||||||
|
btn1.Enabled = False
|
||||||
|
btn2.Enabled = False
|
||||||
|
btn3.Enabled = False
|
||||||
|
btn4.Enabled = False
|
||||||
|
btn5.Enabled = False
|
||||||
|
btn6.Enabled = False
|
||||||
|
btn7.Enabled = False
|
||||||
|
lblCurrPlayer.Visible = False
|
||||||
|
btnReset.Visible = True
|
||||||
|
Exit Sub
|
||||||
|
End If
|
||||||
|
End If
|
||||||
|
Next
|
||||||
|
End If
|
||||||
|
Next
|
||||||
|
Next
|
||||||
|
|
||||||
|
'Resets the values to their defaults
|
||||||
|
RedAddUp = 0
|
||||||
|
YellowAddUp = 0
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when reset button is clicked
|
||||||
|
Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click
|
||||||
|
'Resets the values to their defaults
|
||||||
|
RedAddUp = 0
|
||||||
|
YellowAddUp = 0
|
||||||
|
|
||||||
|
'Resets the grid to its original blank state
|
||||||
|
For y = 1 To 7
|
||||||
|
For x = 1 To 7
|
||||||
|
theGrid(x, y) = 0
|
||||||
|
If y < 7 Then
|
||||||
|
Group(x, y).Image = Nothing
|
||||||
|
End If
|
||||||
|
Next
|
||||||
|
Next
|
||||||
|
|
||||||
|
'Resets the game state variables
|
||||||
|
Won = False
|
||||||
|
Draw = False
|
||||||
|
|
||||||
|
'Resets the x and y coords of the grid
|
||||||
|
x = 1
|
||||||
|
y = 1
|
||||||
|
|
||||||
|
'Runs the Terminators subroutine
|
||||||
|
Terminators()
|
||||||
|
|
||||||
|
'Resets the current player
|
||||||
|
C4Player = "Red"
|
||||||
|
CurrPlayer()
|
||||||
|
|
||||||
|
'Disables the counter drop buttons
|
||||||
|
btn1.Visible = False
|
||||||
|
btn2.Visible = False
|
||||||
|
btn3.Visible = False
|
||||||
|
btn4.Visible = False
|
||||||
|
btn5.Visible = False
|
||||||
|
btn6.Visible = False
|
||||||
|
btn7.Visible = False
|
||||||
|
'Enables them for later
|
||||||
|
btn1.Enabled = True
|
||||||
|
btn2.Enabled = True
|
||||||
|
btn3.Enabled = True
|
||||||
|
btn4.Enabled = True
|
||||||
|
btn5.Enabled = True
|
||||||
|
btn6.Enabled = True
|
||||||
|
btn7.Enabled = True
|
||||||
|
|
||||||
|
'Runs the Question subroutine
|
||||||
|
Question()
|
||||||
|
|
||||||
|
'Hides the reset button
|
||||||
|
lblCurrPlayer.Visible = True
|
||||||
|
btnReset.Visible = False
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutines run when their respective buttons are clicked
|
||||||
|
Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click
|
||||||
|
'Sets x to the x-coord of the selected column
|
||||||
|
x = 1
|
||||||
|
'Runs the CounterPlace subroutine
|
||||||
|
CounterPlace()
|
||||||
|
End Sub
|
||||||
|
Private Sub btn2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn2.Click
|
||||||
|
x = 2
|
||||||
|
CounterPlace()
|
||||||
|
End Sub
|
||||||
|
Private Sub btn3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn3.Click
|
||||||
|
x = 3
|
||||||
|
CounterPlace()
|
||||||
|
End Sub
|
||||||
|
Private Sub btn4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn4.Click
|
||||||
|
x = 4
|
||||||
|
CounterPlace()
|
||||||
|
End Sub
|
||||||
|
Private Sub btn5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn5.Click
|
||||||
|
x = 5
|
||||||
|
CounterPlace()
|
||||||
|
End Sub
|
||||||
|
Private Sub btn6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn6.Click
|
||||||
|
x = 6
|
||||||
|
CounterPlace()
|
||||||
|
End Sub
|
||||||
|
Private Sub btn7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn7.Click
|
||||||
|
x = 7
|
||||||
|
CounterPlace()
|
||||||
|
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 Connect Four menu
|
||||||
|
frmConnect4Menu.Show()
|
||||||
|
'Closes this form
|
||||||
|
Me.Close()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when called in ChangePlayer and btnReset_Click subroutines
|
||||||
|
Sub Question()
|
||||||
|
Dim sql As String
|
||||||
|
Dim dbcomm As MySqlCommand
|
||||||
|
Dim dbread As MySqlDataReader
|
||||||
|
|
||||||
|
sql = "SELECT * FROM tblquestions WHERE SubjectID='" & C4HSubject & "' AND Difficulty='" & C4HDifficulty & "' AND Topic='" & C4HTopic & "' 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 when called in form load and CounterPlace subroutines
|
||||||
|
Sub ChangePlayer()
|
||||||
|
'Sets x & y back to 1 for use later
|
||||||
|
x = 1
|
||||||
|
y = 1
|
||||||
|
|
||||||
|
'Changes the current player
|
||||||
|
If C4Player = "Red" Then
|
||||||
|
C4Player = "Yellow"
|
||||||
|
CurrPlayer()
|
||||||
|
Else
|
||||||
|
C4Player = "Red"
|
||||||
|
CurrPlayer()
|
||||||
|
End If
|
||||||
|
|
||||||
|
'Hides the counter placing buttons
|
||||||
|
btn1.Visible = False
|
||||||
|
btn2.Visible = False
|
||||||
|
btn3.Visible = False
|
||||||
|
btn4.Visible = False
|
||||||
|
btn5.Visible = False
|
||||||
|
btn6.Visible = False
|
||||||
|
btn7.Visible = False
|
||||||
|
|
||||||
|
'Runs the Question subroutine
|
||||||
|
Question()
|
||||||
|
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 counter placement buttons visible
|
||||||
|
btn1.Visible = True
|
||||||
|
btn2.Visible = True
|
||||||
|
btn3.Visible = True
|
||||||
|
btn4.Visible = True
|
||||||
|
btn5.Visible = True
|
||||||
|
btn6.Visible = True
|
||||||
|
btn7.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
|
||||||
|
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 C4Player = "Red" Then
|
||||||
|
If RedPlayer.Username = LoggedInStudent.Username Then
|
||||||
|
sql = "INSERT INTO `cl51-ben`.`tblattempted` (`SubjectID`, `QuestionID`, `StudentID`, `When`, `Correct`) VALUES ('" & C4HSubject & "', '" & QuestionID & "', '" & LoggedInStudent.StudentID & "', '" & TimeOfDay & " " & DateValue(Now) & "', "
|
||||||
|
Else
|
||||||
|
sql = "INSERT INTO `cl51-ben`.`tblattempted` (`SubjectID`, `QuestionID`, `StudentID`, `When`, `Correct`) VALUES ('" & C4HSubject & "', '" & QuestionID & "', '" & OppStudent.StudentID & "', '" & TimeOfDay & " " & DateValue(Now) & "', "
|
||||||
|
End If
|
||||||
|
Else
|
||||||
|
If YellowPlayer.Username = LoggedInStudent.Username Then
|
||||||
|
sql = "INSERT INTO `cl51-ben`.`tblattempted` (`SubjectID`, `QuestionID`, `StudentID`, `When`, `Correct`) VALUES ('" & C4HSubject & "', '" & QuestionID & "', '" & LoggedInStudent.StudentID & "', '" & TimeOfDay & " " & DateValue(Now) & "', "
|
||||||
|
Else
|
||||||
|
sql = "INSERT INTO `cl51-ben`.`tblattempted` (`SubjectID`, `QuestionID`, `StudentID`, `When`, `Correct`) VALUES ('" & C4HSubject & "', '" & QuestionID & "', '" & OppStudent.StudentID & "', '" & TimeOfDay & " " & DateValue(Now) & "', "
|
||||||
|
End If
|
||||||
|
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
|
||||||
|
|
||||||
|
End Class
|
74
StudentForms/ConnectFour/frmConnect4HotseatLogin.vb
Normal file
74
StudentForms/ConnectFour/frmConnect4HotseatLogin.vb
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
Imports MySql.Data.MySqlClient
|
||||||
|
|
||||||
|
Public Class frmConnect4HotseatLogin
|
||||||
|
|
||||||
|
'Declares the variables used to log in
|
||||||
|
Dim EnteredUsername, EnteredPassword As String
|
||||||
|
|
||||||
|
'Subroutine runs when the form loads
|
||||||
|
Private Sub frmConnect4HotseatLogin_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 Connect Four subject selection form
|
||||||
|
frmConnect4HotseatSubject.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 Connect Four menu form
|
||||||
|
frmConnect4Menu.Show()
|
||||||
|
'Closes this form
|
||||||
|
Me.Close()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
End Class
|
89
StudentForms/ConnectFour/frmConnect4HotseatPlayerSelect.vb
Normal file
89
StudentForms/ConnectFour/frmConnect4HotseatPlayerSelect.vb
Normal file
|
@ -0,0 +1,89 @@
|
||||||
|
Public Class frmConnect4HotseatPlayerSelect
|
||||||
|
|
||||||
|
'Subroutine runs on form load
|
||||||
|
Private Sub frmConnect4HotseatPlayerSelect_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
|
||||||
|
'Populates the player name labels with data
|
||||||
|
lblLoggedInStudent.Text = LoggedInStudent.Fname & " " & LoggedInStudent.Lname
|
||||||
|
lblOppStudent.Text = OppStudent.Fname & " " & OppStudent.Lname
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutines run when the counter selection buttons are clicked
|
||||||
|
Private Sub btnOSred_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOSred.Click
|
||||||
|
'Sets the opponent student's colour to red
|
||||||
|
OppStudent.C4Player = "Red"
|
||||||
|
'Updates the appearance of the form
|
||||||
|
picOSred.Image = My.Resources.red
|
||||||
|
'Disables changing the colour and the logged-in student also picking red
|
||||||
|
btnOSred.Enabled = False
|
||||||
|
btnOSyellow.Enabled = False
|
||||||
|
btnLISred.Enabled = False
|
||||||
|
With picRed
|
||||||
|
.Image = Nothing
|
||||||
|
.Tag = "None"
|
||||||
|
End With
|
||||||
|
'Runs the CheckBoth subroutine
|
||||||
|
CheckBoth()
|
||||||
|
End Sub
|
||||||
|
Private Sub btnOSyellow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOSyellow.Click
|
||||||
|
OppStudent.C4Player = "Yellow"
|
||||||
|
picOSyellow.Image = My.Resources.yellow
|
||||||
|
btnOSyellow.Enabled = False
|
||||||
|
btnOSred.Enabled = False
|
||||||
|
btnLISyellow.Enabled = False
|
||||||
|
With picYellow
|
||||||
|
.Image = Nothing
|
||||||
|
.Tag = "None"
|
||||||
|
End With
|
||||||
|
CheckBoth()
|
||||||
|
End Sub
|
||||||
|
Private Sub btnLISred_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLISred.Click
|
||||||
|
LoggedInStudent.C4Player = "Red"
|
||||||
|
picLISred.Image = My.Resources.red
|
||||||
|
btnLISred.Enabled = False
|
||||||
|
btnLISyellow.Enabled = False
|
||||||
|
btnOSred.Enabled = False
|
||||||
|
With picRed
|
||||||
|
.Image = Nothing
|
||||||
|
.Tag = "None"
|
||||||
|
End With
|
||||||
|
CheckBoth()
|
||||||
|
End Sub
|
||||||
|
Private Sub btnLISyellow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLISyellow.Click
|
||||||
|
LoggedInStudent.C4Player = "Yellow"
|
||||||
|
picLISyellow.Image = My.Resources.yellow
|
||||||
|
btnLISyellow.Enabled = False
|
||||||
|
btnLISred.Enabled = False
|
||||||
|
btnOSyellow.Enabled = False
|
||||||
|
With picYellow
|
||||||
|
.Image = Nothing
|
||||||
|
.Tag = "None"
|
||||||
|
End With
|
||||||
|
CheckBoth()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when called in the counter selection button click subroutines
|
||||||
|
Sub CheckBoth()
|
||||||
|
'If both players have chosen...
|
||||||
|
If picYellow.Tag = "None" And picRed.Tag = "None" Then
|
||||||
|
'Enables the button to leave the form
|
||||||
|
btnContinue.Enabled = True
|
||||||
|
End If
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when the continue button is clicked
|
||||||
|
Private Sub btnContinue_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnContinue.Click
|
||||||
|
'Shows the Connect Four hotseat form
|
||||||
|
frmConnect4Hotseat.Show()
|
||||||
|
'Closes this form
|
||||||
|
Me.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 Connect Four hotseat question selection form
|
||||||
|
frmConnect4HotseatSubject.Show()
|
||||||
|
'Closes this form
|
||||||
|
Me.Close()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
End Class
|
92
StudentForms/ConnectFour/frmConnect4HotseatSubject.vb
Normal file
92
StudentForms/ConnectFour/frmConnect4HotseatSubject.vb
Normal file
|
@ -0,0 +1,92 @@
|
||||||
|
Imports MySql.Data.MySqlClient
|
||||||
|
|
||||||
|
Public Class frmConnect4HotseatSubject
|
||||||
|
'Declares the variable used to store the chosen SubjectID
|
||||||
|
Dim SubjectID As Integer
|
||||||
|
|
||||||
|
'Subroutine runs on form load
|
||||||
|
Private Sub frmConnect4HotseatSubject_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
|
||||||
|
C4HSubject = SubjectID
|
||||||
|
C4HDifficulty = cmboDifficulty.SelectedItem
|
||||||
|
C4HTopic = cmboTopic.SelectedItem
|
||||||
|
|
||||||
|
'Shows the Connect Four hotseat player selection form
|
||||||
|
frmConnect4HotseatPlayerSelect.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 Connect Four hotseat login form
|
||||||
|
frmConnect4HotseatLogin.Show()
|
||||||
|
'Closes this form
|
||||||
|
Me.Close()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
End Class
|
27
StudentForms/ConnectFour/frmConnect4Menu.vb
Normal file
27
StudentForms/ConnectFour/frmConnect4Menu.vb
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
Public Class frmConnect4Menu
|
||||||
|
|
||||||
|
'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 Connect Four hotseat login form
|
||||||
|
frmConnect4HotseatLogin.Show()
|
||||||
|
'Closes this form
|
||||||
|
Me.Close()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when the network game button is clicked
|
||||||
|
Private Sub btnNetwork_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNetwork.Click
|
||||||
|
'Shows the Connect Four network lobby form
|
||||||
|
frmConnect4NetworkLobby.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
|
1192
StudentForms/ConnectFour/frmConnect4Network.vb
Normal file
1192
StudentForms/ConnectFour/frmConnect4Network.vb
Normal file
File diff suppressed because it is too large
Load diff
114
StudentForms/ConnectFour/frmConnect4NetworkHostGame.vb
Normal file
114
StudentForms/ConnectFour/frmConnect4NetworkHostGame.vb
Normal file
|
@ -0,0 +1,114 @@
|
||||||
|
Imports MySql.Data.MySqlClient
|
||||||
|
|
||||||
|
Public Class frmConnect4NetworkHostGame
|
||||||
|
'Declares the variable used to store the chosen SubjectID
|
||||||
|
Dim SubjectID As Integer
|
||||||
|
|
||||||
|
'Subroutine runs on form load
|
||||||
|
Private Sub frmConnect4NetworkHostGame_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 host game button is clicked
|
||||||
|
Private Sub btnHost_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHost.Click
|
||||||
|
'Declares the variable used for getting the result of the message box
|
||||||
|
Dim Result As MsgBoxResult
|
||||||
|
'Declares the variable used for detecting invalid data entry
|
||||||
|
Dim Errors As String = ""
|
||||||
|
|
||||||
|
Dim sql As String
|
||||||
|
Dim dbcomm As MySqlCommand
|
||||||
|
Dim dbread As MySqlDataReader
|
||||||
|
|
||||||
|
'Assembles an error report if any invalid data entry detected
|
||||||
|
If txtGameName.Text = "" Then
|
||||||
|
Errors = Errors & "No game name input" & vbCrLf
|
||||||
|
End If
|
||||||
|
If cmboSubject.SelectedItem = "" Then
|
||||||
|
Errors = Errors & "No subject selected" & vbCrLf
|
||||||
|
End If
|
||||||
|
If cmboDifficulty.SelectedItem = "" Then
|
||||||
|
Errors = Errors & "No difficulty selected" & vbCrLf
|
||||||
|
End If
|
||||||
|
If cmboTopic.SelectedItem = "" Then
|
||||||
|
Errors = Errors & "No topic selected" & vbCrLf
|
||||||
|
End If
|
||||||
|
|
||||||
|
'If no invalid data entry is detected...
|
||||||
|
If Errors = "" Then
|
||||||
|
'Displays a validation message box before saving the data to the database
|
||||||
|
Result = MsgBox("Are you sure all these details are correct? Remember, spelling is vital." & vbCrLf & vbCrLf & "Details:" & vbCrLf & txtGameName.Text & vbCrLf & cmboSubject.SelectedItem & " (" & cmboDifficulty.SelectedItem & ")" & vbCrLf & cmboTopic.SelectedItem, MsgBoxStyle.YesNo)
|
||||||
|
'If the data is approved by the user...
|
||||||
|
If Result = MsgBoxResult.Yes Then
|
||||||
|
'Builds SQL query to execute
|
||||||
|
sql = "INSERT INTO `cl51-ben`.`tblconnect4` (`GameName`, `HostUsername`, `CurrentPlayer`, `C4NSubject`, `C4NDifficulty`, `C4NTopic`) VALUES ('" & txtGameName.Text & "', '" & LoggedInStudent.Username & "', 'Red', '" & SubjectID & "', '" & cmboDifficulty.SelectedItem & "', '" & cmboTopic.SelectedItem & "');"
|
||||||
|
|
||||||
|
dbcomm = New MySqlCommand(sql, DBConn)
|
||||||
|
dbread = dbcomm.ExecuteReader()
|
||||||
|
dbread.Close()
|
||||||
|
End If
|
||||||
|
'If any invalid data entry is detected...
|
||||||
|
Else
|
||||||
|
'Displays a message box with any detected invalid data entry
|
||||||
|
MsgBox("Invalid input:" & vbCrLf & vbCrLf & Errors)
|
||||||
|
End If
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when called in form load subroutine
|
||||||
|
Sub Populate()
|
||||||
|
Dim sql As String
|
||||||
|
Dim dbcomm As MySqlCommand
|
||||||
|
Dim dbread As MySqlDataReader
|
||||||
|
|
||||||
|
'Builds SQL query to execute
|
||||||
|
sql = "SELECT * FROM tblsubjects"
|
||||||
|
|
||||||
|
dbcomm = New MySqlCommand(sql, DBConn)
|
||||||
|
dbread = dbcomm.ExecuteReader()
|
||||||
|
'Fills the various properties of the LoggedInStudent object with their respective values from the database
|
||||||
|
While dbread.Read
|
||||||
|
cmboSubject.Items.Add(dbread("Subject"))
|
||||||
|
End While
|
||||||
|
dbread.Close()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when the selected item in 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
|
||||||
|
|
||||||
|
'Builds SQL query to execute
|
||||||
|
sql = "SELECT * FROM tblsubjects WHERE Subject='" & cmboSubject.SelectedItem & "'"
|
||||||
|
|
||||||
|
dbcomm = New MySqlCommand(sql, DBConn)
|
||||||
|
dbread = dbcomm.ExecuteReader()
|
||||||
|
'Fills the various properties of the LoggedInStudent object with their respective values from the database
|
||||||
|
While dbread.Read
|
||||||
|
SubjectID = dbread("SubjectID")
|
||||||
|
End While
|
||||||
|
dbread.Close()
|
||||||
|
End Sub
|
||||||
|
End Class
|
202
StudentForms/ConnectFour/frmConnect4NetworkLobby.vb
Normal file
202
StudentForms/ConnectFour/frmConnect4NetworkLobby.vb
Normal file
|
@ -0,0 +1,202 @@
|
||||||
|
Imports MySql.Data.MySqlClient
|
||||||
|
|
||||||
|
Public Class frmConnect4NetworkLobby
|
||||||
|
'Declares the variable used to determine if a game has a second player or not
|
||||||
|
Dim NoOpp As Boolean = True
|
||||||
|
'Declares the variable used to determine if the logged-in player is the host of a game
|
||||||
|
Dim Host As Boolean = True
|
||||||
|
|
||||||
|
'Subroutine runs on form load
|
||||||
|
Private Sub frmConnect4NetworkLobby_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
|
||||||
|
'Runs the OpenDB subroutine
|
||||||
|
OpenDB()
|
||||||
|
|
||||||
|
'Runs the UpdateList subroutine
|
||||||
|
UpdateList()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when called on form load or btnRefresh_Click subroutines
|
||||||
|
Sub UpdateList()
|
||||||
|
'Clears the lobby listbox of data
|
||||||
|
lstLobby.Items.Clear()
|
||||||
|
|
||||||
|
'Declares the variable used to determine if the logged-in player is currently playing a given game
|
||||||
|
Dim CurrPlaying As String = ""
|
||||||
|
|
||||||
|
Dim sql As String
|
||||||
|
Dim dbcomm As MySqlCommand
|
||||||
|
Dim dbread As MySqlDataReader
|
||||||
|
|
||||||
|
'Builds SQL query to execute
|
||||||
|
sql = "SELECT * FROM tblconnect4 WHERE OppUsername ='' OR OppUsername ='" & LoggedInStudent.Username & "' OR HostUsername ='" & LoggedInStudent.Username & "';"
|
||||||
|
|
||||||
|
dbcomm = New MySqlCommand(sql, DBConn)
|
||||||
|
dbread = dbcomm.ExecuteReader()
|
||||||
|
Dim foo As Integer = 0
|
||||||
|
'Fills the various properties of the LoggedInStudent object with their respective values from the database
|
||||||
|
While dbread.Read
|
||||||
|
'If there is an opponent in the game...
|
||||||
|
If dbread("OppUsername") <> "" Then
|
||||||
|
'Sets CurrPlaying to positive
|
||||||
|
CurrPlaying = " - CURRENTLY PLAYING"
|
||||||
|
Else
|
||||||
|
'Otherwise CurrPlaying is negative
|
||||||
|
CurrPlaying = ""
|
||||||
|
End If
|
||||||
|
'Add the game details to the lobby listbox
|
||||||
|
lstLobby.Items.Add(dbread("GameID") & " - " & dbread("GameName") & " - " & dbread("HostUsername") & CurrPlaying)
|
||||||
|
foo = 1
|
||||||
|
End While
|
||||||
|
dbread.Close()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when the host game button is clicked
|
||||||
|
Private Sub btnHostGame_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHostGame.Click
|
||||||
|
'Shows the Connect Four network hosting form
|
||||||
|
frmConnect4NetworkHostGame.Show()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when the your games button is clicked
|
||||||
|
Private Sub btnYourGames_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnYourGames.Click
|
||||||
|
'Shows the Connect Four network your games form
|
||||||
|
frmConnect4NetworkYourGames.Show()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when the selected item of the lobby listbox is changes
|
||||||
|
Private Sub lstLobby_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstLobby.SelectedIndexChanged
|
||||||
|
foob()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
Sub foob()
|
||||||
|
'Determine the GameID of the selected game
|
||||||
|
Dim EndofGamID As Integer = InStr(1, lstLobby.SelectedItem, " ", CompareMethod.Text)
|
||||||
|
Dim GamID As String = Mid(lstLobby.SelectedItem, 1, EndofGamID - 1)
|
||||||
|
|
||||||
|
'Declares the variables used to determine the usernames of both players in the selected game
|
||||||
|
Dim HUsername As String
|
||||||
|
Dim Username As String
|
||||||
|
|
||||||
|
Dim sql As String
|
||||||
|
Dim dbcomm As MySqlCommand
|
||||||
|
Dim dbread As MySqlDataReader
|
||||||
|
'Builds SQL query to execute
|
||||||
|
sql = "SELECT * FROM tblconnect4 WHERE GameID=" & GamID & ";"
|
||||||
|
|
||||||
|
'Sets the selected GameID
|
||||||
|
GameID = GamID
|
||||||
|
|
||||||
|
dbcomm = New MySqlCommand(sql, DBConn)
|
||||||
|
dbread = dbcomm.ExecuteReader()
|
||||||
|
|
||||||
|
'Fills the various properties of the LoggedInStudent object with their respective values from the database
|
||||||
|
While dbread.Read
|
||||||
|
'If the logged-in user isn't the host of the selected game...
|
||||||
|
If dbread("HostUsername") <> LoggedInStudent.Username Then
|
||||||
|
'Sets the host flag to false
|
||||||
|
Host = False
|
||||||
|
|
||||||
|
'Sets the players
|
||||||
|
LoggedInStudent.C4Player = "Yellow"
|
||||||
|
OppStudent.C4Player = "Red"
|
||||||
|
|
||||||
|
'Sets the opponent as the host
|
||||||
|
Username = dbread("HostUsername")
|
||||||
|
|
||||||
|
'Closes the recordset
|
||||||
|
dbread.Close()
|
||||||
|
|
||||||
|
'Builds SQL query to execute
|
||||||
|
sql = "SELECT * FROM tblstudents WHERE Username='" & Username & "';"
|
||||||
|
|
||||||
|
dbcomm = New MySqlCommand(sql, DBConn)
|
||||||
|
dbread = dbcomm.ExecuteReader()
|
||||||
|
|
||||||
|
While dbread.Read
|
||||||
|
'Populates the properties of the OppStudent object with the host's data
|
||||||
|
With OppStudent
|
||||||
|
.Fname = dbread("Fname")
|
||||||
|
.Lname = dbread("Lname")
|
||||||
|
.StudentID = dbread("StudentID")
|
||||||
|
.Username = dbread("Username")
|
||||||
|
End With
|
||||||
|
End While
|
||||||
|
|
||||||
|
'Sets the no opponent flag to false
|
||||||
|
NoOpp = False
|
||||||
|
dbread.Close()
|
||||||
|
Else
|
||||||
|
'If the logged-in user is the host, sets the host flag to true
|
||||||
|
Host = True
|
||||||
|
'Sets the players
|
||||||
|
LoggedInStudent.C4Player = "Red"
|
||||||
|
OppStudent.C4Player = "Yellow"
|
||||||
|
|
||||||
|
'Sets the usernames of the players
|
||||||
|
HUsername = dbread("HostUsername")
|
||||||
|
Username = dbread("OppUsername")
|
||||||
|
|
||||||
|
'Closes the recordset
|
||||||
|
dbread.Close()
|
||||||
|
|
||||||
|
'Builds SQL query to execute
|
||||||
|
sql = "SELECT * FROM tblstudents WHERE Username='" & Username & "';"
|
||||||
|
|
||||||
|
dbcomm = New MySqlCommand(sql, DBConn)
|
||||||
|
dbread = dbcomm.ExecuteReader()
|
||||||
|
|
||||||
|
While dbread.Read
|
||||||
|
'Populates the properties of the OppStudent object with data
|
||||||
|
With OppStudent
|
||||||
|
.Fname = dbread("Fname")
|
||||||
|
.Lname = dbread("Lname")
|
||||||
|
.StudentID = dbread("StudentID")
|
||||||
|
.Username = dbread("Username")
|
||||||
|
End With
|
||||||
|
'Sets the no opponent flag to false
|
||||||
|
NoOpp = False
|
||||||
|
dbread.Close()
|
||||||
|
Exit Sub
|
||||||
|
End While
|
||||||
|
'Sets the no opponent flag to true
|
||||||
|
NoOpp = True
|
||||||
|
dbread.Close()
|
||||||
|
Exit Sub
|
||||||
|
End If
|
||||||
|
'Closes the recordset
|
||||||
|
dbread.Close()
|
||||||
|
Exit Sub
|
||||||
|
End While
|
||||||
|
dbread.Close()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when join game button is clicked
|
||||||
|
Private Sub btnJoinGame_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnJoinGame.Click
|
||||||
|
Dim sql As String
|
||||||
|
Dim dbcomm As MySqlCommand
|
||||||
|
Dim dbread As MySqlDataReader
|
||||||
|
|
||||||
|
'If there is an opponent in the game...
|
||||||
|
If NoOpp = False Then
|
||||||
|
If Host = False Then
|
||||||
|
'Builds the SQL query to execute
|
||||||
|
sql = "UPDATE `tblconnect4` SET `OppUsername`='" & LoggedInStudent.Username & "' WHERE `GameID`='" & GameID & "';"
|
||||||
|
dbcomm = New MySqlCommand(sql, DBConn)
|
||||||
|
dbread = dbcomm.ExecuteReader()
|
||||||
|
dbread.Close()
|
||||||
|
End If
|
||||||
|
|
||||||
|
'Shows the Connect Four network game form
|
||||||
|
frmConnect4Network.Show()
|
||||||
|
Me.Close()
|
||||||
|
Else
|
||||||
|
'Displays an error message
|
||||||
|
MsgBox("No opponent in game")
|
||||||
|
End If
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when the refresh button is clicked
|
||||||
|
Private Sub btnRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRefresh.Click
|
||||||
|
'Runs the UpdateList subroutine
|
||||||
|
UpdateList()
|
||||||
|
End Sub
|
||||||
|
End Class
|
152
StudentForms/ConnectFour/frmConnect4NetworkYourGames.vb
Normal file
152
StudentForms/ConnectFour/frmConnect4NetworkYourGames.vb
Normal file
|
@ -0,0 +1,152 @@
|
||||||
|
Imports MySql.Data.MySqlClient
|
||||||
|
|
||||||
|
Public Class frmConnect4NetworkYourGames
|
||||||
|
|
||||||
|
'Declares the variable used to determine if a game has a second player or not
|
||||||
|
Dim NoOpp As Boolean = True
|
||||||
|
|
||||||
|
'Subroutine runs on form load
|
||||||
|
Private Sub frmConnect4NetworkYourGames_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
|
||||||
|
'Runs the OpenDB subroutine
|
||||||
|
OpenDB()
|
||||||
|
|
||||||
|
'Runs the UpdateList subroutine
|
||||||
|
UpdateList()
|
||||||
|
|
||||||
|
'Brings the host game form to the front
|
||||||
|
frmConnect4NetworkHostGame.BringToFront()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when called on form load or btnRefresh_Click subroutines
|
||||||
|
Sub UpdateList()
|
||||||
|
'Clears the lobby listbox of data
|
||||||
|
lstYourGames.Items.Clear()
|
||||||
|
|
||||||
|
'Declares the variable used for the result of the confirmation messagebox
|
||||||
|
Dim Result As MsgBoxResult
|
||||||
|
'Declares the variable used to determine if the logged-in player is currently playing a given game
|
||||||
|
Dim CurrPlaying As String = ""
|
||||||
|
|
||||||
|
Dim sql As String
|
||||||
|
Dim dbcomm As MySqlCommand
|
||||||
|
Dim dbread As MySqlDataReader
|
||||||
|
|
||||||
|
'Builds SQL query to execute
|
||||||
|
sql = "SELECT * FROM tblconnect4 WHERE HostUsername = '" & LoggedInStudent.Username & "'"
|
||||||
|
|
||||||
|
dbcomm = New MySqlCommand(sql, DBConn)
|
||||||
|
dbread = dbcomm.ExecuteReader()
|
||||||
|
'Fills the various properties of the LoggedInStudent object with their respective values from the database
|
||||||
|
While dbread.Read
|
||||||
|
'If there is an opponent in the game...
|
||||||
|
If dbread("OppUsername").Value <> "" Then
|
||||||
|
'Sets CurrPlaying to positive
|
||||||
|
CurrPlaying = " - Opponent: " & dbread("OppUsername").Value
|
||||||
|
Else
|
||||||
|
'Otherwise CurrPlaying is negative
|
||||||
|
CurrPlaying = " - No opponent"
|
||||||
|
End If
|
||||||
|
'Add the game details to the lobby listbox
|
||||||
|
lstYourGames.Items.Add(dbread("GameID").Value & " - " & dbread("GameName").Value & " - " & dbread("HostUsername").Value & CurrPlaying)
|
||||||
|
dbread.Close()
|
||||||
|
Exit Sub
|
||||||
|
End While
|
||||||
|
dbread.Close()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when the host game button is clicked
|
||||||
|
Private Sub btnHostGame_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHostGame.Click
|
||||||
|
'Shows the Connect Four network host game form
|
||||||
|
frmConnect4NetworkHostGame.Show()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when the selected item of the lobby listbox is changes
|
||||||
|
Private Sub lstYourGames_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstYourGames.SelectedIndexChanged
|
||||||
|
'Determine the GameID of the selected game
|
||||||
|
Dim EndofGamID As Integer = InStr(1, lstYourGames.SelectedItem, " ", CompareMethod.Text)
|
||||||
|
Dim GamID As String = Mid(lstYourGames.SelectedItem, 1, EndofGamID)
|
||||||
|
|
||||||
|
'Declares the variable used to determine the username of the host
|
||||||
|
Dim Username As String
|
||||||
|
|
||||||
|
Dim sql As String
|
||||||
|
Dim dbcomm As MySqlCommand
|
||||||
|
Dim dbread As MySqlDataReader
|
||||||
|
|
||||||
|
Try
|
||||||
|
'Builds SQL query to execute
|
||||||
|
sql = "SELECT * FROM tblConnect4 WHERE GameID='" & GamID & "'"
|
||||||
|
|
||||||
|
'Sets the selected GameID
|
||||||
|
GameID = GamID
|
||||||
|
|
||||||
|
dbcomm = New MySqlCommand(sql, DBConn)
|
||||||
|
dbread = dbcomm.ExecuteReader()
|
||||||
|
'Fills the various properties of the LoggedInStudent object with their respective values from the database
|
||||||
|
While dbread.Read
|
||||||
|
'If there is an opponent...
|
||||||
|
If dbread("OppUsername") <> "" Then
|
||||||
|
'Sets the players
|
||||||
|
LoggedInStudent.C4Player = "Red"
|
||||||
|
OppStudent.C4Player = "Yellow"
|
||||||
|
|
||||||
|
'Sets the host
|
||||||
|
Username = dbread("OppUsername")
|
||||||
|
|
||||||
|
'Closes the recordset
|
||||||
|
dbread.Close()
|
||||||
|
|
||||||
|
'Builds the SQl query to execute
|
||||||
|
sql = "SELECT * FROM tblstudents WHERE username='" & Username & "'"
|
||||||
|
dbcomm = New MySqlCommand(sql, DBConn)
|
||||||
|
dbread = dbcomm.ExecuteReader()
|
||||||
|
|
||||||
|
'If there are records found...
|
||||||
|
While dbread.Read
|
||||||
|
'Populates the properties of the OppStudent object with the host's data
|
||||||
|
With OppStudent
|
||||||
|
.Fname = dbread("fname")
|
||||||
|
.Lname = dbread("lname")
|
||||||
|
.StudentID = dbread("StudentID")
|
||||||
|
.Username = dbread("username")
|
||||||
|
End With
|
||||||
|
|
||||||
|
'Sets the no opponent flag to false
|
||||||
|
NoOpp = False
|
||||||
|
dbread.Close()
|
||||||
|
Exit Sub
|
||||||
|
End While
|
||||||
|
'Sets the no opponent flag to true
|
||||||
|
NoOpp = True
|
||||||
|
dbread.Close()
|
||||||
|
Exit Sub
|
||||||
|
End If
|
||||||
|
'Closes the recordset
|
||||||
|
dbread.Close()
|
||||||
|
Exit Sub
|
||||||
|
End While
|
||||||
|
dbread.Close()
|
||||||
|
Catch
|
||||||
|
End Try
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when join game button is clicked
|
||||||
|
Private Sub btnJoinGame_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnJoinGame.Click
|
||||||
|
'If there is an opponent in the game...
|
||||||
|
If NoOpp = False Then
|
||||||
|
'Shows the Connect Four network game form
|
||||||
|
frmConnect4Network.Show()
|
||||||
|
'Closes this form
|
||||||
|
Me.Close()
|
||||||
|
Else
|
||||||
|
'Displays an error message
|
||||||
|
MsgBox("No opponent in game")
|
||||||
|
End If
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when the refresh button is clicked
|
||||||
|
Private Sub btnRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRefresh.Click
|
||||||
|
'Runs the UpdateList subroutine
|
||||||
|
UpdateList()
|
||||||
|
End Sub
|
||||||
|
End Class
|
780
StudentForms/NoughtsandCrosses/frmNaCHotseat.vb
Normal file
780
StudentForms/NoughtsandCrosses/frmNaCHotseat.vb
Normal file
|
@ -0,0 +1,780 @@
|
||||||
|
Imports MySql.Data.MySqlClient
|
||||||
|
|
||||||
|
Public Class frmNaCHotseat
|
||||||
|
|
||||||
|
'Declares the array containing the coordinates of the squares of the grid and what condition they are currently in
|
||||||
|
Dim theGrid(9) As String
|
||||||
|
|
||||||
|
'Declares the class used for both players
|
||||||
|
Public Class NaCPlay
|
||||||
|
'Declares the variables used for storing the details of the Noughts and Crosses player
|
||||||
|
Public Letter, Username, Fname, lname As String
|
||||||
|
End Class
|
||||||
|
'Declares the class used for both players' scores
|
||||||
|
Public Class Score
|
||||||
|
'Declares the variable used for storing score of the player
|
||||||
|
Public ScoreNum As Integer
|
||||||
|
'This subroutine runs when a player wins a game
|
||||||
|
Public Sub Increase()
|
||||||
|
'Increases the score by 1
|
||||||
|
ScoreNum = ScoreNum + 1
|
||||||
|
End Sub
|
||||||
|
End Class
|
||||||
|
'Creates two objects of the score class, one for each player
|
||||||
|
Dim XScore As New Score
|
||||||
|
Dim OScore As New Score
|
||||||
|
'Creates two objects of the C4Play class, one for each player
|
||||||
|
Dim XPlayer As New NaCPlay
|
||||||
|
Dim OPlayer As New NaCPlay
|
||||||
|
|
||||||
|
'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
|
||||||
|
|
||||||
|
'Subroutine runs on form load
|
||||||
|
Private Sub frmNaCHotseat_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
|
||||||
|
'Runs the OpenDB subroutine
|
||||||
|
OpenDB()
|
||||||
|
|
||||||
|
'Hides the reset button
|
||||||
|
btnReset.Visible = False
|
||||||
|
|
||||||
|
'If the logged-in student is X...
|
||||||
|
If LoggedInStudent.NaCPlayer = "X" Then
|
||||||
|
'Populate the XPlayer object with the logged-in student's details
|
||||||
|
With XPlayer
|
||||||
|
.Letter = "X"
|
||||||
|
.Username = LoggedInStudent.Username
|
||||||
|
.Fname = LoggedInStudent.Fname
|
||||||
|
.lname = LoggedInStudent.Lname
|
||||||
|
End With
|
||||||
|
|
||||||
|
'Populate the OPlayer object with the opponent student's details
|
||||||
|
With OPlayer
|
||||||
|
.Letter = "O"
|
||||||
|
.Username = OppStudent.Username
|
||||||
|
.Fname = OppStudent.Fname
|
||||||
|
.lname = OppStudent.Lname
|
||||||
|
End With
|
||||||
|
'But if the logged-in student is yellow...
|
||||||
|
Else
|
||||||
|
'Populate the XPlayer object with the logged-in student's details
|
||||||
|
With XPlayer
|
||||||
|
.Letter = "X"
|
||||||
|
.Username = OppStudent.Username
|
||||||
|
.Fname = OppStudent.Fname
|
||||||
|
.lname = OppStudent.Lname
|
||||||
|
End With
|
||||||
|
|
||||||
|
'Populate the OPlayer object with the opponent student's details
|
||||||
|
With OPlayer
|
||||||
|
.Letter = "O"
|
||||||
|
.Username = LoggedInStudent.Username
|
||||||
|
.Fname = LoggedInStudent.Fname
|
||||||
|
.lname = LoggedInStudent.Lname
|
||||||
|
End With
|
||||||
|
End If
|
||||||
|
|
||||||
|
'Runs the AccountSection subroutine
|
||||||
|
AccountSection()
|
||||||
|
|
||||||
|
'Sets the scores to the defaults
|
||||||
|
XScore.ScoreNum = 0
|
||||||
|
OScore.ScoreNum = 0
|
||||||
|
|
||||||
|
'Sets the current player, runs the ChangePlayer and CurrPlayer subroutines
|
||||||
|
NaCPlayer = "O"
|
||||||
|
ChangePlayer()
|
||||||
|
CurrPlayer()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutines run when their respective buttons are clicked
|
||||||
|
Private Sub btntopleft_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btntopleft.Click
|
||||||
|
'Sets the chosen square to the current player
|
||||||
|
btntopleft.Text = NaCPlayer
|
||||||
|
theGrid(1) = NaCPlayer
|
||||||
|
|
||||||
|
'Runs the ChangePlayer subroutine
|
||||||
|
ChangePlayer()
|
||||||
|
'Disables the button
|
||||||
|
btntopleft.Enabled = False
|
||||||
|
'Runs the CheckForAWinner subroutine
|
||||||
|
CheckForAWinner()
|
||||||
|
End Sub
|
||||||
|
Private Sub btntop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btntop.Click
|
||||||
|
btntop.Text = NaCPlayer
|
||||||
|
theGrid(2) = NaCPlayer
|
||||||
|
|
||||||
|
ChangePlayer()
|
||||||
|
btntop.Enabled = False
|
||||||
|
CheckForAWinner()
|
||||||
|
End Sub
|
||||||
|
Private Sub btntopright_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btntopright.Click
|
||||||
|
btntopright.Text = NaCPlayer
|
||||||
|
theGrid(3) = NaCPlayer
|
||||||
|
|
||||||
|
ChangePlayer()
|
||||||
|
btntopright.Enabled = False
|
||||||
|
CheckForAWinner()
|
||||||
|
End Sub
|
||||||
|
Private Sub btnleft_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnleft.Click
|
||||||
|
btnleft.Text = NaCPlayer
|
||||||
|
theGrid(4) = NaCPlayer
|
||||||
|
|
||||||
|
ChangePlayer()
|
||||||
|
btnleft.Enabled = False
|
||||||
|
CheckForAWinner()
|
||||||
|
End Sub
|
||||||
|
Private Sub btnmiddle_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnmiddle.Click
|
||||||
|
btnmiddle.Text = NaCPlayer
|
||||||
|
theGrid(5) = NaCPlayer
|
||||||
|
|
||||||
|
ChangePlayer()
|
||||||
|
btnmiddle.Enabled = False
|
||||||
|
CheckForAWinner()
|
||||||
|
End Sub
|
||||||
|
Private Sub btnright_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnright.Click
|
||||||
|
btnright.Text = NaCPlayer
|
||||||
|
theGrid(6) = NaCPlayer
|
||||||
|
|
||||||
|
ChangePlayer()
|
||||||
|
btnright.Enabled = False
|
||||||
|
CheckForAWinner()
|
||||||
|
End Sub
|
||||||
|
Private Sub btnbottomleft_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnbottomleft.Click
|
||||||
|
btnbottomleft.Text = NaCPlayer
|
||||||
|
theGrid(7) = NaCPlayer
|
||||||
|
|
||||||
|
ChangePlayer()
|
||||||
|
btnbottomleft.Enabled = False
|
||||||
|
CheckForAWinner()
|
||||||
|
End Sub
|
||||||
|
Private Sub btnbottom_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnbottom.Click
|
||||||
|
btnbottom.Text = NaCPlayer
|
||||||
|
theGrid(8) = NaCPlayer
|
||||||
|
|
||||||
|
ChangePlayer()
|
||||||
|
btnbottom.Enabled = False
|
||||||
|
CheckForAWinner()
|
||||||
|
End Sub
|
||||||
|
Private Sub btnbottomright_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnbottomright.Click
|
||||||
|
btnbottomright.Text = NaCPlayer
|
||||||
|
theGrid(9) = NaCPlayer
|
||||||
|
|
||||||
|
ChangePlayer()
|
||||||
|
btnbottomright.Enabled = False
|
||||||
|
CheckForAWinner()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when called in button click subroutines
|
||||||
|
Private Sub CheckForAWinner()
|
||||||
|
'Declares the variable used to store the winner
|
||||||
|
Dim WhoWon As String = ""
|
||||||
|
|
||||||
|
'Checks top row to see if there are three Xs or Os in a row
|
||||||
|
If theGrid(1) = theGrid(2) And theGrid(2) = theGrid(3) And theGrid(1) <> "" Then
|
||||||
|
'Declares the player who has claimed the three squares the winner
|
||||||
|
WhoWon = theGrid(1)
|
||||||
|
If WhoWon = "X" Then
|
||||||
|
XScore.Increase()
|
||||||
|
Else
|
||||||
|
OScore.Increase()
|
||||||
|
End If
|
||||||
|
DatabaseDetails()
|
||||||
|
|
||||||
|
'Disables grid
|
||||||
|
btntopleft.Enabled = False
|
||||||
|
btntop.Enabled = False
|
||||||
|
btntopright.Enabled = False
|
||||||
|
btnleft.Enabled = False
|
||||||
|
btnmiddle.Enabled = False
|
||||||
|
btnright.Enabled = False
|
||||||
|
btnbottomleft.Enabled = False
|
||||||
|
btnbottom.Enabled = False
|
||||||
|
btnbottomright.Enabled = False
|
||||||
|
End If
|
||||||
|
|
||||||
|
'Checks middle row to see if there are three Xs or Os in a row
|
||||||
|
If theGrid(4) = theGrid(5) And theGrid(5) = theGrid(6) And theGrid(4) <> "" Then
|
||||||
|
'Declares the player who has claimed the three squares the winner
|
||||||
|
WhoWon = theGrid(4)
|
||||||
|
If WhoWon = "X" Then
|
||||||
|
XScore.Increase()
|
||||||
|
Else
|
||||||
|
OScore.Increase()
|
||||||
|
End If
|
||||||
|
DatabaseDetails()
|
||||||
|
|
||||||
|
'Disables grid
|
||||||
|
btntopleft.Enabled = False
|
||||||
|
btntop.Enabled = False
|
||||||
|
btntopright.Enabled = False
|
||||||
|
btnleft.Enabled = False
|
||||||
|
btnmiddle.Enabled = False
|
||||||
|
btnright.Enabled = False
|
||||||
|
btnbottomleft.Enabled = False
|
||||||
|
btnbottom.Enabled = False
|
||||||
|
btnbottomright.Enabled = False
|
||||||
|
End If
|
||||||
|
|
||||||
|
'Checks bottom row to see if there are three Xs or Os in a row
|
||||||
|
If theGrid(7) = theGrid(8) And theGrid(8) = theGrid(9) And theGrid(7) <> "" Then
|
||||||
|
'Declares the player who has claimed the three squares the winner
|
||||||
|
WhoWon = theGrid(7)
|
||||||
|
If WhoWon = "X" Then
|
||||||
|
XScore.Increase()
|
||||||
|
Else
|
||||||
|
OScore.Increase()
|
||||||
|
End If
|
||||||
|
DatabaseDetails()
|
||||||
|
|
||||||
|
'Disables grid
|
||||||
|
btntopleft.Enabled = False
|
||||||
|
btntop.Enabled = False
|
||||||
|
btntopright.Enabled = False
|
||||||
|
btnleft.Enabled = False
|
||||||
|
btnmiddle.Enabled = False
|
||||||
|
btnright.Enabled = False
|
||||||
|
btnbottomleft.Enabled = False
|
||||||
|
btnbottom.Enabled = False
|
||||||
|
btnbottomright.Enabled = False
|
||||||
|
End If
|
||||||
|
|
||||||
|
'Checks left column to see if there are three Xs or Os in a row
|
||||||
|
If theGrid(1) = theGrid(4) And theGrid(4) = theGrid(7) And theGrid(1) <> "" Then
|
||||||
|
'Declares the player who has claimed the three squares the winner
|
||||||
|
WhoWon = theGrid(1)
|
||||||
|
If WhoWon = "X" Then
|
||||||
|
XScore.Increase()
|
||||||
|
Else
|
||||||
|
OScore.Increase()
|
||||||
|
End If
|
||||||
|
DatabaseDetails()
|
||||||
|
|
||||||
|
'Disables grid
|
||||||
|
btntopleft.Enabled = False
|
||||||
|
btntop.Enabled = False
|
||||||
|
btntopright.Enabled = False
|
||||||
|
btnleft.Enabled = False
|
||||||
|
btnmiddle.Enabled = False
|
||||||
|
btnright.Enabled = False
|
||||||
|
btnbottomleft.Enabled = False
|
||||||
|
btnbottom.Enabled = False
|
||||||
|
btnbottomright.Enabled = False
|
||||||
|
End If
|
||||||
|
|
||||||
|
'Checks middle column to see if there are three Xs or Os in a row
|
||||||
|
If theGrid(2) = theGrid(5) And theGrid(5) = theGrid(8) And theGrid(2) <> "" Then
|
||||||
|
'Declares the player who has claimed the three squares the winner
|
||||||
|
WhoWon = theGrid(2)
|
||||||
|
If WhoWon = "X" Then
|
||||||
|
XScore.Increase()
|
||||||
|
Else
|
||||||
|
OScore.Increase()
|
||||||
|
End If
|
||||||
|
DatabaseDetails()
|
||||||
|
|
||||||
|
'Disables grid
|
||||||
|
btntopleft.Enabled = False
|
||||||
|
btntop.Enabled = False
|
||||||
|
btntopright.Enabled = False
|
||||||
|
btnleft.Enabled = False
|
||||||
|
btnmiddle.Enabled = False
|
||||||
|
btnright.Enabled = False
|
||||||
|
btnbottomleft.Enabled = False
|
||||||
|
btnbottom.Enabled = False
|
||||||
|
btnbottomright.Enabled = False
|
||||||
|
End If
|
||||||
|
|
||||||
|
'Checks right column to see if there are three Xs or Os in a row
|
||||||
|
If theGrid(3) = theGrid(6) And theGrid(6) = theGrid(9) And theGrid(3) <> "" Then
|
||||||
|
'Declares the player who has claimed the three squares the winner
|
||||||
|
WhoWon = theGrid(3)
|
||||||
|
If WhoWon = "X" Then
|
||||||
|
XScore.Increase()
|
||||||
|
Else
|
||||||
|
OScore.Increase()
|
||||||
|
End If
|
||||||
|
DatabaseDetails()
|
||||||
|
|
||||||
|
'Disables grid
|
||||||
|
btntopleft.Enabled = False
|
||||||
|
btntop.Enabled = False
|
||||||
|
btntopright.Enabled = False
|
||||||
|
btnleft.Enabled = False
|
||||||
|
btnmiddle.Enabled = False
|
||||||
|
btnright.Enabled = False
|
||||||
|
btnbottomleft.Enabled = False
|
||||||
|
btnbottom.Enabled = False
|
||||||
|
btnbottomright.Enabled = False
|
||||||
|
End If
|
||||||
|
|
||||||
|
'Checks top-left to bottom-right diagonal to see if there are three Xs or Os in a row
|
||||||
|
If theGrid(1) = theGrid(5) And theGrid(5) = theGrid(9) And theGrid(1) <> "" Then
|
||||||
|
'Declares the player who has claimed the three squares the winner
|
||||||
|
WhoWon = theGrid(1)
|
||||||
|
If WhoWon = "X" Then
|
||||||
|
XScore.Increase()
|
||||||
|
Else
|
||||||
|
OScore.Increase()
|
||||||
|
End If
|
||||||
|
DatabaseDetails()
|
||||||
|
|
||||||
|
'Disables grid
|
||||||
|
btntopleft.Enabled = False
|
||||||
|
btntop.Enabled = False
|
||||||
|
btntopright.Enabled = False
|
||||||
|
btnleft.Enabled = False
|
||||||
|
btnmiddle.Enabled = False
|
||||||
|
btnright.Enabled = False
|
||||||
|
btnbottomleft.Enabled = False
|
||||||
|
btnbottom.Enabled = False
|
||||||
|
btnbottomright.Enabled = False
|
||||||
|
End If
|
||||||
|
|
||||||
|
'Checks top-right to bottom-left diagonal to see if there are three Xs or Os in a row
|
||||||
|
If theGrid(3) = theGrid(5) And theGrid(5) = theGrid(7) And theGrid(3) <> "" Then
|
||||||
|
'Declares the player who has claimed the three squares the winner
|
||||||
|
WhoWon = theGrid(3)
|
||||||
|
If WhoWon = "X" Then
|
||||||
|
XScore.Increase()
|
||||||
|
Else
|
||||||
|
OScore.Increase()
|
||||||
|
End If
|
||||||
|
DatabaseDetails()
|
||||||
|
|
||||||
|
'Disables grid
|
||||||
|
btntopleft.Enabled = False
|
||||||
|
btntop.Enabled = False
|
||||||
|
btntopright.Enabled = False
|
||||||
|
btnleft.Enabled = False
|
||||||
|
btnmiddle.Enabled = False
|
||||||
|
btnright.Enabled = False
|
||||||
|
btnbottomleft.Enabled = False
|
||||||
|
btnbottom.Enabled = False
|
||||||
|
btnbottomright.Enabled = False
|
||||||
|
End If
|
||||||
|
|
||||||
|
'Declares the variables used to count the number of blank squares
|
||||||
|
Dim n As Integer
|
||||||
|
Dim Blanks As Integer
|
||||||
|
|
||||||
|
'For each square...
|
||||||
|
For n = 1 To 9
|
||||||
|
'If the square isn't blank, increment blanks
|
||||||
|
If theGrid(n) = "" Then Blanks = Blanks + 1
|
||||||
|
Next
|
||||||
|
|
||||||
|
'If there is a winner...
|
||||||
|
If WhoWon <> "" Then
|
||||||
|
'Makes buttons invisible
|
||||||
|
btnReset.Visible = True
|
||||||
|
lblQuestion.Visible = False
|
||||||
|
lblCurrPlayer.Visible = False
|
||||||
|
grpQuestion.Visible = False
|
||||||
|
txtAnswer.Visible = False
|
||||||
|
btnSubmit.Visible = False
|
||||||
|
'Declares winner
|
||||||
|
MsgBox(WhoWon & " wins.")
|
||||||
|
'Stops game
|
||||||
|
Exit Sub
|
||||||
|
End If
|
||||||
|
|
||||||
|
'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 there a draw...
|
||||||
|
If Blanks = 0 Then
|
||||||
|
|
||||||
|
If OPlayer.Username = LoggedInStudent.Username Then
|
||||||
|
'Builds SQL query to execute
|
||||||
|
sql = "UPDATE `tblstudents` SET `Draws`=`Draws`+1 WHERE `Username`='" & OPlayer.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(OPlayer.Username & ".txt", True)
|
||||||
|
|
||||||
|
'Writes the relevant data to the log
|
||||||
|
writer.WriteLine(OPlayer.Fname & " " & OPlayer.lname & " drew with " & XPlayer.Fname & " " & XPlayer.lname & " in Noughts and Crosses - " & TimeOfDay & " " & DateValue(Now))
|
||||||
|
'Saves the log file
|
||||||
|
writer.Close()
|
||||||
|
ElseIf XPlayer.Username = LoggedInStudent.Username Then
|
||||||
|
'Builds SQL query to execute
|
||||||
|
sql = "UPDATE `tblstudents` SET `Draws`=`Draws`+1 WHERE `Username`='" & XPlayer.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(XPlayer.Username & ".txt", True)
|
||||||
|
|
||||||
|
'Writes the relevant data to the log
|
||||||
|
writer.WriteLine(XPlayer.Fname & " " & XPlayer.lname & " drew with " & OPlayer.Fname & " " & OPlayer.lname & " in Noughts and Crosses - " & TimeOfDay & " " & DateValue(Now))
|
||||||
|
'Saves the log file
|
||||||
|
writer.Close()
|
||||||
|
End If
|
||||||
|
|
||||||
|
'Declares draw
|
||||||
|
MsgBox("Draw")
|
||||||
|
'Makes buttons invisible
|
||||||
|
btnReset.Visible = True
|
||||||
|
grpQuestion.Visible = False
|
||||||
|
lblQuestion.Visible = False
|
||||||
|
txtAnswer.Visible = False
|
||||||
|
btnSubmit.Visible = False
|
||||||
|
lblCurrPlayer.Visible = False
|
||||||
|
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 OScore.ScoreNum = 1 Then
|
||||||
|
If OPlayer.Username = LoggedInStudent.Username Then
|
||||||
|
'Builds SQL query to execute
|
||||||
|
sql = "UPDATE `tblstudents` SET `Wins`=`Wins`+1 WHERE `Username`='" & OPlayer.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(OPlayer.Username & ".txt", True)
|
||||||
|
|
||||||
|
'Writes the relevant data to the log
|
||||||
|
writer.WriteLine(OPlayer.Fname & " " & OPlayer.lname & " beat " & XPlayer.Fname & " " & XPlayer.lname & " in Noughts and Crosses - " & TimeOfDay & " " & DateValue(Now))
|
||||||
|
'Saves the log file
|
||||||
|
writer.Close()
|
||||||
|
ElseIf XPlayer.Username = LoggedInStudent.Username Then
|
||||||
|
'Builds SQL query to execute
|
||||||
|
sql = "UPDATE `tblstudents` SET `Losses`=`Losses`+1 WHERE `Username`='" & XPlayer.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(XPlayer.Username & ".txt", True)
|
||||||
|
|
||||||
|
'Writes the relevant data to the log
|
||||||
|
writer.WriteLine(XPlayer.Fname & " " & XPlayer.lname & " was beaten by " & OPlayer.Fname & " " & OPlayer.lname & " in Noughts and Crosses - " & TimeOfDay & " " & DateValue(Now))
|
||||||
|
'Saves the log file
|
||||||
|
writer.Close()
|
||||||
|
End If
|
||||||
|
|
||||||
|
'Resets the O score back to its default
|
||||||
|
OScore.ScoreNum = 0
|
||||||
|
End If
|
||||||
|
'However, if the X player is the winner...
|
||||||
|
If XScore.ScoreNum = 1 Then
|
||||||
|
If XPlayer.Username = LoggedInStudent.Username Then
|
||||||
|
'Builds SQL query to execute
|
||||||
|
sql = "UPDATE `tblstudents` SET `Wins`=`Wins`+1 WHERE `Username`='" & XPlayer.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(XPlayer.Username & ".txt", True)
|
||||||
|
|
||||||
|
'Writes the relevant data to the log
|
||||||
|
writer.WriteLine(XPlayer.Fname & " " & XPlayer.lname & " beat " & OPlayer.Fname & " " & OPlayer.lname & " in Noughts and Crosses - " & TimeOfDay & " " & DateValue(Now))
|
||||||
|
'Saves the log file
|
||||||
|
writer.Close()
|
||||||
|
ElseIf OPlayer.Username = LoggedInStudent.Username Then
|
||||||
|
'Builds SQL query to execute
|
||||||
|
sql = "UPDATE `tblstudents` SET `Losses`=`Losses`+1 WHERE `Username`='" & OPlayer.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(OPlayer.Username & ".txt", True)
|
||||||
|
|
||||||
|
'Writes the relevant data to the log
|
||||||
|
writer.WriteLine(OPlayer.Fname & " " & OPlayer.lname & " was beaten by " & XPlayer.Fname & " " & XPlayer.lname & " in Noughts and Crosses - " & TimeOfDay & " " & DateValue(Now))
|
||||||
|
'Saves the log file
|
||||||
|
writer.Close()
|
||||||
|
End If
|
||||||
|
'Resets the O score back to its default
|
||||||
|
XScore.ScoreNum = 0
|
||||||
|
End If
|
||||||
|
|
||||||
|
grpQuestion.Visible = False
|
||||||
|
|
||||||
|
btnReset.Location = New Point(331, 206)
|
||||||
|
btnReset.Visible = True
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when called in the ChangePlayer subroutine
|
||||||
|
Sub CurrPlayer()
|
||||||
|
'If the logged-in player is the same as the current player, which is X...
|
||||||
|
If LoggedInStudent.NaCPlayer = "X" Then
|
||||||
|
If NaCPlayer = "X" Then
|
||||||
|
'Places the current player label pointing to the logged-in student
|
||||||
|
lblCurrPlayer.Top = StudentCurrLocationY
|
||||||
|
'However if the current player is O...
|
||||||
|
Else
|
||||||
|
'Places the current player label pointing to the opponent student
|
||||||
|
lblCurrPlayer.Top = OppStudentCurrLocationY
|
||||||
|
End If
|
||||||
|
'However, if the opponent student is the same as the current player, which is O...
|
||||||
|
Else
|
||||||
|
If NaCPlayer = "O" Then
|
||||||
|
'Places the current player label pointing to the logged-in student
|
||||||
|
lblCurrPlayer.Top = StudentCurrLocationY
|
||||||
|
'However if the current player is yellow...
|
||||||
|
Else
|
||||||
|
'Places the current player label pointing to the opponent student
|
||||||
|
lblCurrPlayer.Top = OppStudentCurrLocationY
|
||||||
|
End If
|
||||||
|
End If
|
||||||
|
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 = OPlayer.Username & ".jpg"
|
||||||
|
|
||||||
|
lblOppStudentName.Text = OppStudent.Fname & " " & OppStudent.Lname
|
||||||
|
picOppStudentPic.ImageLocation = XPlayer.Username & ".jpg"
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when reset button is clicked
|
||||||
|
Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click
|
||||||
|
'This re-enables all of the buttons, removes the Xs and 0s from them as well as resetting the array
|
||||||
|
btntopleft.Enabled = True
|
||||||
|
btntop.Enabled = True
|
||||||
|
btntopright.Enabled = True
|
||||||
|
btnleft.Enabled = True
|
||||||
|
btnmiddle.Enabled = True
|
||||||
|
btnright.Enabled = True
|
||||||
|
btnbottomleft.Enabled = True
|
||||||
|
btnbottom.Enabled = True
|
||||||
|
btnbottomright.Enabled = True
|
||||||
|
|
||||||
|
btntopleft.Text = ""
|
||||||
|
btntop.Text = ""
|
||||||
|
btntopright.Text = ""
|
||||||
|
btnleft.Text = ""
|
||||||
|
btnmiddle.Text = ""
|
||||||
|
btnright.Text = ""
|
||||||
|
btnbottomleft.Text = ""
|
||||||
|
btnbottom.Text = ""
|
||||||
|
btnbottomright.Text = ""
|
||||||
|
|
||||||
|
Dim n As Integer
|
||||||
|
|
||||||
|
For n = 1 To 9
|
||||||
|
theGrid(n) = ""
|
||||||
|
Next
|
||||||
|
|
||||||
|
'Resets the current player
|
||||||
|
NaCPlayer = "X"
|
||||||
|
CurrPlayer()
|
||||||
|
|
||||||
|
'Runs the Question subroutine
|
||||||
|
Question()
|
||||||
|
|
||||||
|
'Makes the controls visible
|
||||||
|
lblCurrPlayer.Visible = True
|
||||||
|
grpQuestion.Visible = True
|
||||||
|
lblQuestion.Visible = True
|
||||||
|
txtAnswer.Visible = True
|
||||||
|
btnSubmit.Visible = True
|
||||||
|
btnReset.Visible = False
|
||||||
|
btnReset.Location = New Point(19, 90)
|
||||||
|
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 Noughts and Crosses menu
|
||||||
|
frmNoughtsandCrossesMenu.Show()
|
||||||
|
'Closes this form
|
||||||
|
Me.Close()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when called in ChangePlayer and btnReset_Click subroutines
|
||||||
|
Sub Question()
|
||||||
|
Dim sql As String
|
||||||
|
Dim dbcomm As MySqlCommand
|
||||||
|
Dim dbread As MySqlDataReader
|
||||||
|
|
||||||
|
sql = "SELECT * FROM tblquestions WHERE SubjectID='" & NaCSubject & "' AND Difficulty='" & NaCDifficulty & "' AND Topic='" & NaCTopic & "' 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 when called in form load and button click subroutines
|
||||||
|
Sub ChangePlayer()
|
||||||
|
'Changes the current player
|
||||||
|
If NaCPlayer = "X" Then
|
||||||
|
NaCPlayer = "O"
|
||||||
|
CurrPlayer()
|
||||||
|
Else
|
||||||
|
NaCPlayer = "X"
|
||||||
|
CurrPlayer()
|
||||||
|
End If
|
||||||
|
|
||||||
|
'Hides the buttons
|
||||||
|
btntopleft.Enabled = False
|
||||||
|
btntop.Enabled = False
|
||||||
|
btntopright.Enabled = False
|
||||||
|
btnleft.Enabled = False
|
||||||
|
btnmiddle.Enabled = False
|
||||||
|
btnright.Enabled = False
|
||||||
|
btnbottomleft.Enabled = False
|
||||||
|
btnbottom.Enabled = False
|
||||||
|
btnbottomright.Enabled = False
|
||||||
|
|
||||||
|
'Runs the Question subroutine
|
||||||
|
Question()
|
||||||
|
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 buttons visible
|
||||||
|
btntopleft.Enabled = True
|
||||||
|
btntop.Enabled = True
|
||||||
|
btntopright.Enabled = True
|
||||||
|
btnleft.Enabled = True
|
||||||
|
btnmiddle.Enabled = True
|
||||||
|
btnright.Enabled = True
|
||||||
|
btnbottomleft.Enabled = True
|
||||||
|
btnbottom.Enabled = True
|
||||||
|
btnbottomright.Enabled = 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
|
||||||
|
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 C4Player = "Red" Then
|
||||||
|
If OPlayer.Username = LoggedInStudent.Username Then
|
||||||
|
sql = "INSERT INTO `cl51-ben`.`tblattempted` (`SubjectID`, `QuestionID`, `StudentID`, `When`, `Correct`) VALUES ('" & NaCSubject & "', '" & QuestionID & "', '" & LoggedInStudent.StudentID & "', '" & TimeOfDay & " " & DateValue(Now) & "', "
|
||||||
|
Else
|
||||||
|
sql = "INSERT INTO `cl51-ben`.`tblattempted` (`SubjectID`, `QuestionID`, `StudentID`, `When`, `Correct`) VALUES ('" & NaCSubject & "', '" & QuestionID & "', '" & OppStudent.StudentID & "', '" & TimeOfDay & " " & DateValue(Now) & "', "
|
||||||
|
End If
|
||||||
|
Else
|
||||||
|
If XPlayer.Username = LoggedInStudent.Username Then
|
||||||
|
sql = "INSERT INTO `cl51-ben`.`tblattempted` (`SubjectID`, `QuestionID`, `StudentID`, `When`, `Correct`) VALUES ('" & NaCSubject & "', '" & QuestionID & "', '" & LoggedInStudent.StudentID & "', '" & TimeOfDay & " " & DateValue(Now) & "', "
|
||||||
|
Else
|
||||||
|
sql = "INSERT INTO `cl51-ben`.`tblattempted` (`SubjectID`, `QuestionID`, `StudentID`, `When`, `Correct`) VALUES ('" & NaCSubject & "', '" & QuestionID & "', '" & OppStudent.StudentID & "', '" & TimeOfDay & " " & DateValue(Now) & "', "
|
||||||
|
End If
|
||||||
|
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
|
||||||
|
End Class
|
74
StudentForms/NoughtsandCrosses/frmNaCHotseatLogin.vb
Normal file
74
StudentForms/NoughtsandCrosses/frmNaCHotseatLogin.vb
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
Imports MySql.Data.MySqlClient
|
||||||
|
|
||||||
|
Public Class frmNaCHotseatLogin
|
||||||
|
|
||||||
|
'Declares the variables used to log in
|
||||||
|
Dim EnteredUsername, EnteredPassword As String
|
||||||
|
|
||||||
|
'Subroutine runs when the form loads
|
||||||
|
Private Sub frmNaCHotseatLogin_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
|
||||||
|
frmNaCHotseatSubject.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 Noughts and Crosses menu form
|
||||||
|
frmNoughtsandCrossesMenu.Show()
|
||||||
|
'Closes this form
|
||||||
|
Me.Close()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
End Class
|
89
StudentForms/NoughtsandCrosses/frmNaCHotseatPlayerSelect.vb
Normal file
89
StudentForms/NoughtsandCrosses/frmNaCHotseatPlayerSelect.vb
Normal file
|
@ -0,0 +1,89 @@
|
||||||
|
Public Class frmNaCHotseatPlayerSelect
|
||||||
|
|
||||||
|
'Subroutine runs on form load
|
||||||
|
Private Sub frmNACHotseatPlayerSelect_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
|
||||||
|
'Populates the player name labels with data
|
||||||
|
lblLoggedInStudent.Text = LoggedInStudent.Fname & " " & LoggedInStudent.Lname
|
||||||
|
lblOppStudent.Text = OppStudent.Fname & " " & OppStudent.Lname
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutines run when the counter selection buttons are clicked
|
||||||
|
Private Sub btnOSX_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOSX.Click
|
||||||
|
'Sets the opponent student's counter to X
|
||||||
|
OppStudent.NaCPlayer = "X"
|
||||||
|
'Updates the appearance of the form
|
||||||
|
picOSX.Image = My.Resources.x
|
||||||
|
'Disables changing the counter and the logged-in student also picking X
|
||||||
|
btnOSX.Enabled = False
|
||||||
|
btnOSO.Enabled = False
|
||||||
|
btnLISX.Enabled = False
|
||||||
|
With picX
|
||||||
|
.Image = Nothing
|
||||||
|
.Tag = "None"
|
||||||
|
End With
|
||||||
|
'Runs the CheckBoth subroutine
|
||||||
|
CheckBoth()
|
||||||
|
End Sub
|
||||||
|
Private Sub btnOSO_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOSO.Click
|
||||||
|
OppStudent.NaCPlayer = "O"
|
||||||
|
picOSO.Image = My.Resources.o
|
||||||
|
btnOSO.Enabled = False
|
||||||
|
btnOSX.Enabled = False
|
||||||
|
btnLISO.Enabled = False
|
||||||
|
With picO
|
||||||
|
.Image = Nothing
|
||||||
|
.Tag = "None"
|
||||||
|
End With
|
||||||
|
CheckBoth()
|
||||||
|
End Sub
|
||||||
|
Private Sub btnLISX_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLISX.Click
|
||||||
|
LoggedInStudent.NaCPlayer = "X"
|
||||||
|
picLISX.Image = My.Resources.x
|
||||||
|
btnLISX.Enabled = False
|
||||||
|
btnLISO.Enabled = False
|
||||||
|
btnOSX.Enabled = False
|
||||||
|
With picX
|
||||||
|
.Image = Nothing
|
||||||
|
.Tag = "None"
|
||||||
|
End With
|
||||||
|
CheckBoth()
|
||||||
|
End Sub
|
||||||
|
Private Sub btnLISO_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLISO.Click
|
||||||
|
LoggedInStudent.NaCPlayer = "O"
|
||||||
|
picLISO.Image = My.Resources.o
|
||||||
|
btnLISO.Enabled = False
|
||||||
|
btnLISX.Enabled = False
|
||||||
|
btnOSO.Enabled = False
|
||||||
|
With picO
|
||||||
|
.Image = Nothing
|
||||||
|
.Tag = "None"
|
||||||
|
End With
|
||||||
|
CheckBoth()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when called in the counter selection button click subroutines
|
||||||
|
Sub CheckBoth()
|
||||||
|
'If both players have chosen...
|
||||||
|
If picO.Tag = "None" And picX.Tag = "None" Then
|
||||||
|
'Enables the button to leave the form
|
||||||
|
btnContinue.Enabled = True
|
||||||
|
End If
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when the continue button is clicked
|
||||||
|
Private Sub btnContinue_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnContinue.Click
|
||||||
|
'Shows the Noughts and Crosses hotseat form
|
||||||
|
frmNaCHotseat.Show()
|
||||||
|
'Closes this form
|
||||||
|
Me.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 Noughts and Crosses hotseat question selection form
|
||||||
|
frmNaCHotseatSubject.Show()
|
||||||
|
'Closes this form
|
||||||
|
Me.Close()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
End Class
|
92
StudentForms/NoughtsandCrosses/frmNaCHotseatSubject.vb
Normal file
92
StudentForms/NoughtsandCrosses/frmNaCHotseatSubject.vb
Normal file
|
@ -0,0 +1,92 @@
|
||||||
|
Imports MySql.Data.MySqlClient
|
||||||
|
|
||||||
|
Public Class frmNaCHotseatSubject
|
||||||
|
'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
|
||||||
|
NaCSubject = SubjectID
|
||||||
|
NaCDifficulty = cmboDifficulty.SelectedItem
|
||||||
|
NaCTopic = cmboTopic.SelectedItem
|
||||||
|
|
||||||
|
'Shows the Connect Four hotseat player selection form
|
||||||
|
frmNaCHotseatPlayerSelect.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 Noughts and Crosses hotseat login form
|
||||||
|
frmNaCHotseatLogin.Show()
|
||||||
|
'Closes this form
|
||||||
|
Me.Close()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
End Class
|
19
StudentForms/NoughtsandCrosses/frmNoughtsandCrossesMenu.vb
Normal file
19
StudentForms/NoughtsandCrosses/frmNoughtsandCrossesMenu.vb
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
Public Class frmNoughtsandCrossesMenu
|
||||||
|
|
||||||
|
'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 Noughts and Crosses hotseat login form
|
||||||
|
frmNaCHotseatLogin.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
|
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
|
54
StudentForms/frmStudentAccount.vb
Normal file
54
StudentForms/frmStudentAccount.vb
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
Public Class frmStudentAccount
|
||||||
|
|
||||||
|
'Subroutine runs when the form loads
|
||||||
|
Private Sub frmAccount_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
|
||||||
|
'Runs the account section population subroutine
|
||||||
|
AccountSection()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when the form loads
|
||||||
|
Sub AccountSection()
|
||||||
|
'If the account to be viewed is the logged-in or searched-for student's...
|
||||||
|
If Viewing = 1 Then
|
||||||
|
'Places the logged-in student's namse onto the form
|
||||||
|
lblStudentName.Text = LoggedInStudent.Fname & " " & LoggedInStudent.Lname
|
||||||
|
'Places the logged-in student's form onto the form
|
||||||
|
lblForm.Text = LoggedInStudent.Form
|
||||||
|
'Places the logged-in student's picture onto the form
|
||||||
|
picStudent.ImageLocation = LoggedInStudent.Username & ".jpg"
|
||||||
|
'Places the logged-in student's wins onto the form
|
||||||
|
lblWins.Text = "Wins: " & LoggedInStudent.Wins
|
||||||
|
'Places the logged-in student's losses onto the form
|
||||||
|
lblLosses.Text = "Losses: " & LoggedInStudent.Losses
|
||||||
|
'Places the logged-in student's draws onto the form
|
||||||
|
lblDraws.Text = "Draws: " & LoggedInStudent.Draws
|
||||||
|
'However, if it is the opponent student's...
|
||||||
|
Else
|
||||||
|
'Places the opponent student's name onto the form
|
||||||
|
lblStudentName.Text = OppStudent.Fname & " " & OppStudent.Lname
|
||||||
|
'Places the opponent student's form onto the form
|
||||||
|
lblForm.Text = OppStudent.Form
|
||||||
|
'Places the opponent student's picture onto the form
|
||||||
|
picStudent.ImageLocation = OppStudent.Username & ".jpg"
|
||||||
|
'Places the opponent student's wins onto the form
|
||||||
|
lblWins.Text = "Wins: " & OppStudent.Wins
|
||||||
|
'Places the opponent student's losses onto the form
|
||||||
|
lblLosses.Text = "Losses: " & OppStudent.Losses
|
||||||
|
'Places the opponent student's draws onto the form
|
||||||
|
lblDraws.Text = "Draws: " & OppStudent.Draws
|
||||||
|
End If
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when the view breakdown button is clicked
|
||||||
|
Private Sub btnBreakdown_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBreakdown.Click
|
||||||
|
'Opens the student breakdown form
|
||||||
|
frmStudentBreakdown.Show()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when the view achievments button is clicked
|
||||||
|
Private Sub btnAchievements_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAchievements.Click
|
||||||
|
'Opens the student achievments form
|
||||||
|
frmStudentAchievements.Show()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
End Class
|
61
StudentForms/frmStudentAchievements.vb
Normal file
61
StudentForms/frmStudentAchievements.vb
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
Imports MySql.Data.MySqlClient
|
||||||
|
|
||||||
|
Public Class frmStudentAchievements
|
||||||
|
|
||||||
|
'Subroutine runs when the form loads
|
||||||
|
Private Sub frmStudentAchievements_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
|
||||||
|
'Establishes the connection to the database
|
||||||
|
OpenDB()
|
||||||
|
|
||||||
|
'If the account to be viewed is the logged-in or searched-for student's...
|
||||||
|
If Viewing = 1 Then
|
||||||
|
'Places the logged-in student's name onto the form
|
||||||
|
lblAchievements.Text = LoggedInStudent.Fname & " " & LoggedInStudent.Lname & " Achievements"
|
||||||
|
'However, if it is the opponent student's...
|
||||||
|
Else
|
||||||
|
'Places the opponent student's name onto the form
|
||||||
|
lblAchievements.Text = OppStudent.Fname & " " & OppStudent.Lname & " Achievements"
|
||||||
|
End If
|
||||||
|
|
||||||
|
'Runs the achievements population subroutine
|
||||||
|
Achievements()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when the form runs
|
||||||
|
Sub Achievements()
|
||||||
|
'Runs the achievment subroutines
|
||||||
|
FirstBlood()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutines run when the achievement subroutine calls them
|
||||||
|
Sub FirstBlood()
|
||||||
|
Dim sql As String
|
||||||
|
Dim dbcomm As MySqlCommand
|
||||||
|
Dim dbread As MySqlDataReader
|
||||||
|
|
||||||
|
'If the account to be viewed is the logged-in or searched-for student's...
|
||||||
|
If Viewing = 1 Then
|
||||||
|
'Builds SQL query to execute
|
||||||
|
sql = "SELECT * FROM `tblstudents` WHERE `username`='" & LoggedInStudent.Username & "' AND `wins` >0;"
|
||||||
|
'However, if it is the opponent student's...
|
||||||
|
Else
|
||||||
|
'Builds SQL query to execute
|
||||||
|
sql = "SELECT * FROM `tblstudents` WHERE `username`='" & OppStudent.Username & "' AND `wins` >0;"
|
||||||
|
End If
|
||||||
|
|
||||||
|
dbcomm = New MySqlCommand(sql, DBConn)
|
||||||
|
dbread = dbcomm.ExecuteReader()
|
||||||
|
'Fills the various properties of the LoggedInStudent object with their respective values from the database
|
||||||
|
While dbread.Read
|
||||||
|
'Unlocks the achievement
|
||||||
|
lblFirstBlood.Text = "First Blood"
|
||||||
|
lblFirstBloodDeets.Text = "Win your first game"
|
||||||
|
picFirstBlood.Image = My.Resources.firstblood
|
||||||
|
|
||||||
|
dbread.Close()
|
||||||
|
DBConn.Close()
|
||||||
|
Exit Sub
|
||||||
|
End While
|
||||||
|
dbread.Close()
|
||||||
|
End Sub
|
||||||
|
End Class
|
34
StudentForms/frmStudentBreakdown.vb
Normal file
34
StudentForms/frmStudentBreakdown.vb
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
Public Class frmStudentBreakdown
|
||||||
|
|
||||||
|
'Subroutine runs when the form loads
|
||||||
|
Private Sub frmStudentBreakdown_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
|
||||||
|
'Declares the variable used to read the student breakdown text file
|
||||||
|
Dim Reader As System.IO.StreamReader
|
||||||
|
|
||||||
|
'If the account to be viewed is the logged-in or searched-for student's...
|
||||||
|
If Viewing = 1 Then
|
||||||
|
'Places the logged-in student's name onto the form
|
||||||
|
lblBreakdown.Text = LoggedInStudent.Fname & " " & LoggedInStudent.Lname & " Win Breakdown"
|
||||||
|
|
||||||
|
'Gets the path to the logged-in student's breakdown text file
|
||||||
|
Reader = My.Computer.FileSystem.OpenTextFileReader(LoggedInStudent.Username & ".txt")
|
||||||
|
'However, if it is the opponent student's...
|
||||||
|
Else
|
||||||
|
'Places the opponent student's name onto the form
|
||||||
|
lblBreakdown.Text = OppStudent.Fname & " " & OppStudent.Lname & " Win Breakdown"
|
||||||
|
|
||||||
|
'Gets the path to the opponent student's breakdown text file
|
||||||
|
Reader = My.Computer.FileSystem.OpenTextFileReader(OppStudent.Username & ".txt")
|
||||||
|
End If
|
||||||
|
|
||||||
|
'Whilst the end of the text file hasn't been reached...
|
||||||
|
While Not Reader.EndOfStream
|
||||||
|
'Adds a line to the breakdown listbox
|
||||||
|
lstBreakdown.Items.Add(Reader.ReadLine)
|
||||||
|
End While
|
||||||
|
|
||||||
|
'Closes the recordset
|
||||||
|
Reader.Close()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
End Class
|
90
StudentForms/frmStudentHome.vb
Normal file
90
StudentForms/frmStudentHome.vb
Normal file
|
@ -0,0 +1,90 @@
|
||||||
|
Public Class frmStudentHome
|
||||||
|
|
||||||
|
'Subroutine runs when the form loads
|
||||||
|
Private Sub frmStudentHome_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
|
||||||
|
'Runs the account section population subroutine
|
||||||
|
AccountSection()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when called in the form load sub
|
||||||
|
Sub AccountSection()
|
||||||
|
'Places the logged-in student's name onto the form
|
||||||
|
lblStudentName.Text = LoggedInStudent.Fname & " " & LoggedInStudent.Lname
|
||||||
|
'Places the logged-in student's picture onto the form
|
||||||
|
picStudent.ImageLocation = LoggedInStudent.Username & ".jpg"
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when the view profile button is clicked
|
||||||
|
Private Sub btnViewProfile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnViewProfile.Click
|
||||||
|
'Sets the viewed profile to that of the logged-in student
|
||||||
|
Viewing = 1
|
||||||
|
|
||||||
|
'Opens the teacher account form
|
||||||
|
frmStudentAccount.Show()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
|
||||||
|
'Subroutine runs when the Connect Four button is clicked
|
||||||
|
Private Sub btnConnectFour_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConnectFour.Click
|
||||||
|
'Opens the Connect Four menu form
|
||||||
|
frmConnect4Menu.Show()
|
||||||
|
'Closes this form
|
||||||
|
Me.Close()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when the Noughts and Crosses button is clicked
|
||||||
|
Private Sub btnNoughtsandCrosses_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNoughtsandCrosses.Click
|
||||||
|
'Opens the Noughts and Crosses menu form
|
||||||
|
frmNoughtsandCrossesMenu.Show()
|
||||||
|
'Closes this form
|
||||||
|
Me.Close()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when the Rock, Paper, Scissors button is clicked
|
||||||
|
Private Sub btnRPS_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRPS.Click
|
||||||
|
'Opens the Rock, Paper, Scissors menu form
|
||||||
|
frmRockPaperScissorsMenu.Show()
|
||||||
|
'Closes this form
|
||||||
|
Me.Close()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when Connect Four button is moused over
|
||||||
|
Private Sub btnConnectFour_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles btnConnectFour.MouseMove
|
||||||
|
'Changes the game description
|
||||||
|
lblGameDesc.Text = "Strike from the skies with your mighty red or yellow tokens, and slay the foul xenos with your glorious row of 4!" & vbCrLf & vbCrLf & "2 players"
|
||||||
|
'Changes the game image
|
||||||
|
picGameImg.Image = My.Resources.nac
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when Noughts and Crosses button is moused over
|
||||||
|
Private Sub btnNoughtsandCrosses_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles btnNoughtsandCrosses.MouseMove
|
||||||
|
'Changes the game description
|
||||||
|
lblGameDesc.Text = "On the barren fields of battle, strike the enemy where he is most vulnerable by forming a line of three consecutive counters!" & vbCrLf & vbCrLf & "2 players"
|
||||||
|
'Changes the game image
|
||||||
|
picGameImg.Image = My.Resources.ox
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when Rock Paper Scissors button is moused over
|
||||||
|
Private Sub btnRPS_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles btnRPS.MouseMove
|
||||||
|
'Changes the game description
|
||||||
|
lblGameDesc.Text = "It's a veritable battle royale out there, show no mercy as you lead your chosen item of stationary or geological formation to victory and glory!" & vbCrLf & vbCrLf & "2 players"
|
||||||
|
'Changes the game image
|
||||||
|
picGameImg.Image = My.Resources.rps
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when form is moused over
|
||||||
|
Private Sub frmStudentHome_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
|
||||||
|
'Changes the game description back to the default
|
||||||
|
lblGameDesc.Text = "Hello and welcome to the official Bourne Grammar School edutainment suite!" & vbCrLf & vbCrLf & "Pick a game or check out your account"
|
||||||
|
'Changes the game image
|
||||||
|
picGameImg.Image = My.Resources.edutained
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when game description label is moused over
|
||||||
|
Private Sub lblGameDesc_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lblGameDesc.MouseMove
|
||||||
|
'Changes the game description back to the default
|
||||||
|
lblGameDesc.Text = "Hello and welcome to the official Bourne Grammar School edutainment suite!" & vbCrLf & vbCrLf & "Pick a game or check out your account"
|
||||||
|
'Changes the game image
|
||||||
|
picGameImg.Image = My.Resources.edutained
|
||||||
|
End Sub
|
||||||
|
End Class
|
148
TeacherForms/frmAddQuestion.vb
Normal file
148
TeacherForms/frmAddQuestion.vb
Normal file
|
@ -0,0 +1,148 @@
|
||||||
|
Imports MySql.Data.MySqlClient
|
||||||
|
|
||||||
|
Public Class frmAddQuestion
|
||||||
|
|
||||||
|
'Declares the variable used for storing the SubjectID
|
||||||
|
Dim SubjectID As Integer
|
||||||
|
|
||||||
|
'Subroutine runs when the form loads
|
||||||
|
Private Sub frmAddQuestion_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
|
||||||
|
'Establishes the connection to the database
|
||||||
|
OpenDB()
|
||||||
|
|
||||||
|
'Runs the form population subroutine
|
||||||
|
Populate()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when called in the form load sub
|
||||||
|
Sub Populate()
|
||||||
|
Dim sql As String
|
||||||
|
Dim dbcomm As MySqlCommand
|
||||||
|
Dim dbread As MySqlDataReader
|
||||||
|
|
||||||
|
'Builds SQL query to execute
|
||||||
|
sql = "SELECT * FROM tblsubjects"
|
||||||
|
|
||||||
|
dbcomm = New MySqlCommand(sql, DBConn)
|
||||||
|
dbread = dbcomm.ExecuteReader()
|
||||||
|
'Fills the various properties of the LoggedInStudent object with their respective values from the database
|
||||||
|
While dbread.Read
|
||||||
|
'Populates the subject combobox with data
|
||||||
|
cmboSubject.Items.Add(dbread("Subject"))
|
||||||
|
End While
|
||||||
|
dbread.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
|
||||||
|
'Closes the form
|
||||||
|
Me.Close()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when the selected index in the subject combobox changes
|
||||||
|
Private Sub cmboSubject_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmboSubject.SelectedIndexChanged
|
||||||
|
'Declares the varibale used to read the topics text file
|
||||||
|
Dim Reader As System.IO.StreamReader
|
||||||
|
|
||||||
|
'Enables the topics combobox
|
||||||
|
cmboTopic.Enabled = True
|
||||||
|
cmboTopic.Items.Clear()
|
||||||
|
|
||||||
|
'Gets the path to the selected subject's topics text file
|
||||||
|
Reader = My.Computer.FileSystem.OpenTextFileReader(cmboSubject.SelectedItem & "Topics.txt")
|
||||||
|
'Whilst the end of the text file hasn't been reacher...
|
||||||
|
While Not Reader.EndOfStream
|
||||||
|
'Adds an item to the topics combobox
|
||||||
|
cmboTopic.Items.Add(Reader.ReadLine)
|
||||||
|
End While
|
||||||
|
|
||||||
|
'Closes the recordset
|
||||||
|
Reader.Close()
|
||||||
|
|
||||||
|
Dim sql As String
|
||||||
|
Dim dbcomm As MySqlCommand
|
||||||
|
Dim dbread As MySqlDataReader
|
||||||
|
|
||||||
|
'Builds SQL query to execute
|
||||||
|
sql = "SELECT * FROM tblsubjects WHERE Subject='" & cmboSubject.SelectedItem & "'"
|
||||||
|
|
||||||
|
dbcomm = New MySqlCommand(sql, DBConn)
|
||||||
|
dbread = dbcomm.ExecuteReader()
|
||||||
|
'Fills the various properties of the LoggedInStudent object with their respective values from the database
|
||||||
|
While dbread.Read
|
||||||
|
'Populates the subject combobox with data
|
||||||
|
SubjectID = dbread("SubjectID")
|
||||||
|
End While
|
||||||
|
dbread.Close()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when the question textbox is clicked
|
||||||
|
Private Sub txtQuestion_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtQuestion.Click
|
||||||
|
'Blanks out the textbox
|
||||||
|
txtQuestion.Text = ""
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when the answer textbox is clicked
|
||||||
|
Private Sub txtAnswer_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtAnswer.Click
|
||||||
|
'Blanks out the textbox
|
||||||
|
txtAnswer.Text = ""
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when the submit button is clicked
|
||||||
|
Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
|
||||||
|
'Declares the variable used for getting the result of the message box
|
||||||
|
Dim Result As MsgBoxResult
|
||||||
|
'Declares the variable used for detecting invalid data entry
|
||||||
|
Dim Errors As String = ""
|
||||||
|
'Assembles an error report if any invalid data entry detected
|
||||||
|
If cmboSubject.Text = "" Then
|
||||||
|
Errors = Errors & "No subject selected" & vbCrLf
|
||||||
|
End If
|
||||||
|
If cmboDifficulty.Text = "" Then
|
||||||
|
Errors = Errors & "No difficulty selected" & vbCrLf
|
||||||
|
End If
|
||||||
|
If cmboTopic.Text = "" Then
|
||||||
|
Errors = Errors & "No topic selected" & vbCrLf
|
||||||
|
End If
|
||||||
|
If txtQuestion.Text = "" Then
|
||||||
|
Errors = Errors & "No question input" & vbCrLf
|
||||||
|
End If
|
||||||
|
If txtAnswer.Text = "" Then
|
||||||
|
Errors = Errors & "No answer input" & vbCrLf
|
||||||
|
End If
|
||||||
|
|
||||||
|
|
||||||
|
Dim sql As String
|
||||||
|
Dim dbcomm As MySqlCommand
|
||||||
|
Dim dbread As MySqlDataReader
|
||||||
|
|
||||||
|
'If no invalid data entry is detected...
|
||||||
|
If Errors = "" Then
|
||||||
|
'Displays a validation message box before saving the data to the database
|
||||||
|
Result = MsgBox("Are you sure all these details are correct? Remember, spelling is vital." & vbCrLf & vbCrLf & "Details:" & vbCrLf & cmboDifficulty.SelectedItem & " " & cmboSubject.SelectedItem & vbCrLf & cmboTopic.SelectedItem & vbCrLf & vbCrLf & "Question: ''" & txtQuestion.Text & "''" & vbCrLf & "Answer: ''" & txtAnswer.Text & "''", MsgBoxStyle.YesNo)
|
||||||
|
'If the data is approved by the user...
|
||||||
|
If Result = MsgBoxResult.Yes Then
|
||||||
|
'Builds SQL query to execute
|
||||||
|
sql = "INSERT INTO `cl51-ben`.`tblquestions` (`SubjectID`, `TeacherID`, `Question`, `Answer`, `Difficulty`, `Topic`) VALUES ('" & SubjectID & "', '" & LoggedInTeacher.TeacherID & "', '" & txtQuestion.Text & "', '" & txtAnswer.Text & "', '" & cmboDifficulty.SelectedItem & "', '" & cmboTopic.SelectedItem & "');"
|
||||||
|
|
||||||
|
dbcomm = New MySqlCommand(sql, DBConn)
|
||||||
|
dbread = dbcomm.ExecuteReader()
|
||||||
|
dbread.Close()
|
||||||
|
End If
|
||||||
|
'If any invalid data entry is detected...
|
||||||
|
Else
|
||||||
|
'Displays a message box with any detected invalid data entry
|
||||||
|
MsgBox("Invalid input:" & vbCrLf & vbCrLf & Errors)
|
||||||
|
End If
|
||||||
|
|
||||||
|
'Declares the variable used for writing to the text file
|
||||||
|
Dim writer As System.IO.StreamWriter
|
||||||
|
'Gets the filepath to the logged-in teacher's question creation log text file
|
||||||
|
writer = My.Computer.FileSystem.OpenTextFileWriter(LoggedInTeacher.Username & ".txt", True)
|
||||||
|
'Adds the log of the question creation to the logged-in teacher's log file
|
||||||
|
writer.WriteLine(LoggedInTeacher.Fname & " " & LoggedInTeacher.Lname & " created a question for " & cmboDifficulty.SelectedItem & " " & cmboSubject.SelectedItem & " (''" & txtQuestion.Text & "'') - " & TimeOfDay & " " & DateValue(Now))
|
||||||
|
'Saves the log file
|
||||||
|
writer.Close()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
End Class
|
55
TeacherForms/frmTeacherAccount.vb
Normal file
55
TeacherForms/frmTeacherAccount.vb
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
Imports MySql.Data.MySqlClient
|
||||||
|
|
||||||
|
Public Class frmTeacherAccount
|
||||||
|
|
||||||
|
'Subroutine runs when the form loads
|
||||||
|
Private Sub frmTeacherAccount_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
|
||||||
|
'Establishes the connection to the database
|
||||||
|
OpenDB()
|
||||||
|
|
||||||
|
'Runs the account section population subroutine
|
||||||
|
AccountSection()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when the form loads
|
||||||
|
Sub AccountSection()
|
||||||
|
'Places the logged-in teacher's name onto the form
|
||||||
|
lblTeacherName.Text = LoggedInTeacher.Fname & " " & LoggedInTeacher.Lname
|
||||||
|
'Places the logged-in teacher's picture onto the form
|
||||||
|
picTeacher.ImageLocation = LoggedInTeacher.Username & ".jpg"
|
||||||
|
|
||||||
|
Dim sql As String
|
||||||
|
Dim dbcomm As MySqlCommand
|
||||||
|
Dim dbread As MySqlDataReader
|
||||||
|
|
||||||
|
'Builds SQL query to execute
|
||||||
|
sql = "SELECT * FROM `tblquestions` WHERE `TeacherID`='" & LoggedInTeacher.TeacherID & "';"
|
||||||
|
dbcomm = New MySqlCommand(sql, DBConn)
|
||||||
|
dbread = dbcomm.ExecuteReader()
|
||||||
|
Dim i As Integer = 0
|
||||||
|
'Populates the questions created label
|
||||||
|
If dbread.HasRows = True Then
|
||||||
|
While dbread.Read
|
||||||
|
i = i + 1
|
||||||
|
End While
|
||||||
|
lblQsCreated.Text = "Questions Created: " & i
|
||||||
|
Else
|
||||||
|
lblQsCreated.Text = "Questions Created: 0"
|
||||||
|
End If
|
||||||
|
'Closes the recordset
|
||||||
|
dbread.Close()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when the view breakdown button is clicked
|
||||||
|
Private Sub btnBreakdown_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBreakdown.Click
|
||||||
|
'Shows the teacher breakdown form
|
||||||
|
frmTeacherBreakdown.Show()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when the view achievements button is clicked
|
||||||
|
Private Sub btnAchievements_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAchievements.Click
|
||||||
|
'Shows the teacher achievements form
|
||||||
|
frmTeacherAchievements.Show()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
End Class
|
72
TeacherForms/frmTeacherAchievements.vb
Normal file
72
TeacherForms/frmTeacherAchievements.vb
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
Imports MySql.Data.MySqlClient
|
||||||
|
|
||||||
|
Public Class frmTeacherAchievements
|
||||||
|
|
||||||
|
'Subroutine runs when the form loads
|
||||||
|
Private Sub frmTeacherAchievements_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
|
||||||
|
'Establishes the connection to the database
|
||||||
|
OpenDB()
|
||||||
|
|
||||||
|
'Places the logged-in teacher's name onto the form
|
||||||
|
lblAchievements.Text = LoggedInTeacher.Fname & " " & LoggedInTeacher.Lname & " Achievements"
|
||||||
|
|
||||||
|
'Runs the achievements population subroutine
|
||||||
|
Achievements()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when the form runs
|
||||||
|
Sub Achievements()
|
||||||
|
'Runs the achievment subroutines
|
||||||
|
TeachingAssistant()
|
||||||
|
TenuredProf()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutines run when the achievement subroutine calls them
|
||||||
|
Sub TeachingAssistant()
|
||||||
|
Dim sql As String
|
||||||
|
Dim dbcomm As MySqlCommand
|
||||||
|
Dim dbread As MySqlDataReader
|
||||||
|
|
||||||
|
'Builds SQL query to execute
|
||||||
|
sql = "SELECT * FROM `tblquestions` WHERE `TeacherID`='" & LoggedInTeacher.TeacherID & "' AND `QsAdded` >0"
|
||||||
|
|
||||||
|
dbcomm = New MySqlCommand(sql, DBConn)
|
||||||
|
dbread = dbcomm.ExecuteReader()
|
||||||
|
'Fills the various properties of the LoggedInStudent object with their respective values from the database
|
||||||
|
While dbread.Read
|
||||||
|
'Unlocks the achievement
|
||||||
|
lblTeachingAssistant.Text = "Teaching Assistant"
|
||||||
|
lblTeachingAssistantDeets.Text = "Create your first question"
|
||||||
|
picTeachingAssistant.Image = My.Resources.Assistant
|
||||||
|
|
||||||
|
dbread.Close()
|
||||||
|
DBConn.Close()
|
||||||
|
Exit Sub
|
||||||
|
End While
|
||||||
|
dbread.Close()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
Sub TenuredProf()
|
||||||
|
Dim sql As String
|
||||||
|
Dim dbcomm As MySqlCommand
|
||||||
|
Dim dbread As MySqlDataReader
|
||||||
|
|
||||||
|
'Builds SQL query to execute
|
||||||
|
sql = "SELECT * FROM `tblquestions` WHERE `TeacherID`='" & LoggedInTeacher.TeacherID & "' AND `QsAdded` >19"
|
||||||
|
|
||||||
|
dbcomm = New MySqlCommand(sql, DBConn)
|
||||||
|
dbread = dbcomm.ExecuteReader()
|
||||||
|
'Fills the various properties of the LoggedInStudent object with their respective values from the database
|
||||||
|
While dbread.Read
|
||||||
|
'Unlocks the achievement
|
||||||
|
lblTenuredProf.Text = "Tenured Professor"
|
||||||
|
lblTenuredProfDeets.Text = "Create 20 questions"
|
||||||
|
picTenuredProf.Image = My.Resources.professor
|
||||||
|
|
||||||
|
dbread.Close()
|
||||||
|
DBConn.Close()
|
||||||
|
Exit Sub
|
||||||
|
End While
|
||||||
|
dbread.Close()
|
||||||
|
End Sub
|
||||||
|
End Class
|
24
TeacherForms/frmTeacherBreakdown.vb
Normal file
24
TeacherForms/frmTeacherBreakdown.vb
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
Public Class frmTeacherBreakdown
|
||||||
|
|
||||||
|
'Subroutine runs when the form loads
|
||||||
|
Private Sub frmTeacherBreakdown_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
|
||||||
|
'Declares the variable used to read the teacher breakdown text file
|
||||||
|
Dim Reader As System.IO.StreamReader
|
||||||
|
|
||||||
|
'Places the logged-in teacher's name onto the form
|
||||||
|
lblBreakdown.Text = LoggedInTeacher.Fname & " " & LoggedInTeacher.Lname & " Question Breakdown"
|
||||||
|
|
||||||
|
'Gets the path to the logged-in teacher's breakdown text file
|
||||||
|
Reader = My.Computer.FileSystem.OpenTextFileReader(LoggedInTeacher.Username & ".txt")
|
||||||
|
|
||||||
|
'Whilst the end of the text file hasn't been reached...
|
||||||
|
While Not Reader.EndOfStream
|
||||||
|
'Adds a line to the breakdown listbox
|
||||||
|
lstBreakdown.Items.Add(Reader.ReadLine)
|
||||||
|
End While
|
||||||
|
|
||||||
|
'Closes the recordset
|
||||||
|
Reader.Close()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
End Class
|
43
TeacherForms/frmTeacherHome.vb
Normal file
43
TeacherForms/frmTeacherHome.vb
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
Public Class frmTeacherHome
|
||||||
|
|
||||||
|
'Subroutine runs when the form loads
|
||||||
|
Private Sub frmTeacherHome_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
|
||||||
|
'Runs the account section population subroutine
|
||||||
|
AccountSection()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when called in the form load sub
|
||||||
|
Sub AccountSection()
|
||||||
|
'Places the logged-in teacher's name onto the form
|
||||||
|
lblTeacherName.Text = LoggedInTeacher.Fname & " " & LoggedInTeacher.Lname
|
||||||
|
'Places the logged-in teacher's picture onto the form
|
||||||
|
picTeacher.ImageLocation = LoggedInTeacher.Username & ".jpg"
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when the view profile button is clicked
|
||||||
|
Private Sub btnViewProfile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnViewProfile.Click
|
||||||
|
'Opens the teacher account form
|
||||||
|
frmTeacherAccount.Show()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when the view student button is clicked
|
||||||
|
Private Sub btnViewStudent_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnViewStudent.Click
|
||||||
|
'Opens the view student form
|
||||||
|
frmViewStudent.Show()
|
||||||
|
'Closes this form
|
||||||
|
Me.Close()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when the create question button is clicked
|
||||||
|
Private Sub btnCreateQuestion_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreateQuestion.Click
|
||||||
|
'Opens the add question form
|
||||||
|
frmAddQuestion.Show()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when the add student button is clicked
|
||||||
|
Private Sub btnAddStudent_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddStudent.Click
|
||||||
|
'Opens the add student form
|
||||||
|
frmAddStudent.Show()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
End Class
|
134
TeacherForms/frmViewStudent.vb
Normal file
134
TeacherForms/frmViewStudent.vb
Normal file
|
@ -0,0 +1,134 @@
|
||||||
|
Imports MySql.Data.MySqlClient
|
||||||
|
|
||||||
|
Public Class frmViewStudent
|
||||||
|
|
||||||
|
'Subroutine runs when the form loads
|
||||||
|
Private Sub frmViewStudent_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
|
||||||
|
'Establishes the connection to the database
|
||||||
|
OpenDB()
|
||||||
|
|
||||||
|
'Runs the account section population subroutine
|
||||||
|
AccountSection()
|
||||||
|
|
||||||
|
Dim sql As String
|
||||||
|
Dim dbcomm As MySqlCommand
|
||||||
|
Dim dbread As MySqlDataReader
|
||||||
|
|
||||||
|
'Builds SQL query to execute
|
||||||
|
sql = "SELECT * FROM tblstudents"
|
||||||
|
|
||||||
|
dbcomm = New MySqlCommand(sql, DBConn)
|
||||||
|
dbread = dbcomm.ExecuteReader()
|
||||||
|
'Fills the various properties of the LoggedInStudent object with their respective values from the database
|
||||||
|
While dbread.Read
|
||||||
|
'Adds a line to the students listbox
|
||||||
|
lstStudents.Items.Add(dbread("StudentID") & " - " & dbread("Fname") & " " & dbread("Lname"))
|
||||||
|
End While
|
||||||
|
dbread.Close()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when called in the form loads
|
||||||
|
Sub AccountSection()
|
||||||
|
'Places the logged-in teacher's name onto the form
|
||||||
|
lblTeacherName.Text = LoggedInTeacher.Fname & " " & LoggedInTeacher.Lname
|
||||||
|
'Places the logged-in teacher's picture onto the form
|
||||||
|
picTeacher.ImageLocation = LoggedInTeacher.Username & ".jpg"
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when the view profile button is clicked
|
||||||
|
Private Sub btnViewProfile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnViewProfile.Click
|
||||||
|
'Opens teacher account form
|
||||||
|
frmTeacherAccount.Show()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when the search button is clicked
|
||||||
|
Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
|
||||||
|
Dim sql As String
|
||||||
|
Dim dbcomm As MySqlCommand
|
||||||
|
Dim dbread As MySqlDataReader
|
||||||
|
|
||||||
|
'Blanks the listbox
|
||||||
|
lstStudents.Items.Clear()
|
||||||
|
|
||||||
|
'Builds SQL query to execute
|
||||||
|
If (txtFname.Text <> "") And (txtLname.Text <> "") Then
|
||||||
|
'Builds SQL query to execute
|
||||||
|
sql = "SELECT * FROM tblstudents WHERE Fname LIKE '%" & txtFname.Text & "%' AND Lname LIKE '%" & txtLname.Text & "%'"
|
||||||
|
ElseIf (txtFname.Text <> "") And (txtLname.Text = "") Then
|
||||||
|
'Builds SQL query to execute
|
||||||
|
sql = "SELECT * FROM tblstudents WHERE Fname LIKE '%" & txtFname.Text & "%'"
|
||||||
|
ElseIf (txtFname.Text = "") And (txtLname.Text <> "") Then
|
||||||
|
'Builds SQL query to execute
|
||||||
|
sql = "SELECT * FROM tblstudents WHERE Lname LIKE '%" & txtLname.Text & "%'"
|
||||||
|
ElseIf (txtFname.Text = "") And (txtLname.Text = "") Then
|
||||||
|
'Builds SQL query to execute
|
||||||
|
sql = "SELECT * FROM tblstudents"
|
||||||
|
End If
|
||||||
|
|
||||||
|
dbcomm = New MySqlCommand(sql, DBConn)
|
||||||
|
dbread = dbcomm.ExecuteReader()
|
||||||
|
Dim foo As Integer = 0
|
||||||
|
While dbread.Read
|
||||||
|
'Adds a line to the students listbox
|
||||||
|
lstStudents.Items.Add(dbread("StudentID") & " - " & dbread("Fname") & " " & dbread("Lname"))
|
||||||
|
foo = 1
|
||||||
|
End While
|
||||||
|
If foo = 1 Then
|
||||||
|
dbread.Close()
|
||||||
|
Exit Sub
|
||||||
|
End If
|
||||||
|
'If no records are found...
|
||||||
|
'Displays a message box
|
||||||
|
MsgBox("No records found")
|
||||||
|
dbread.Close()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when the selected index of the students listbox changes
|
||||||
|
Private Sub lstStudents_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstStudents.SelectedIndexChanged
|
||||||
|
'Declares the variable used for getting the end of the StudentID
|
||||||
|
Dim EndofStudentID As Integer = InStr(1, lstStudents.SelectedItem, " ", CompareMethod.Text)
|
||||||
|
'Declares the variable used for storing the StudentID
|
||||||
|
Dim StudID As String = Mid(lstStudents.SelectedItem, 1, EndofStudentID)
|
||||||
|
|
||||||
|
|
||||||
|
Dim sql As String
|
||||||
|
Dim dbcomm As MySqlCommand
|
||||||
|
Dim dbread As MySqlDataReader
|
||||||
|
|
||||||
|
'Builds SQL query to execute
|
||||||
|
sql = "SELECT * FROM tblstudents WHERE StudentID='" & StudID & "'"
|
||||||
|
|
||||||
|
dbcomm = New MySqlCommand(sql, DBConn)
|
||||||
|
dbread = dbcomm.ExecuteReader()
|
||||||
|
'Fills the various properties of the LoggedInStudent object with their respective values from the database
|
||||||
|
While dbread.Read
|
||||||
|
With LoggedInStudent
|
||||||
|
.Fname = dbread("Fname")
|
||||||
|
.Lname = dbread("Lname")
|
||||||
|
.Form = dbread("FormNum") & dbread("FormLetter")
|
||||||
|
.Wins = dbread("Wins")
|
||||||
|
.Losses = dbread("Losses")
|
||||||
|
.Draws = dbread("Draws")
|
||||||
|
.Username = dbread("Username")
|
||||||
|
End With
|
||||||
|
End While
|
||||||
|
dbread.Close()
|
||||||
|
|
||||||
|
'Enables the view student profile button
|
||||||
|
btnViewStudentProfile.Enabled = True
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when the view student button is clicked
|
||||||
|
Private Sub btnViewStudentProfile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnViewStudentProfile.Click
|
||||||
|
'Opens the student account form
|
||||||
|
frmStudentAccount.Show()
|
||||||
|
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
|
||||||
|
'Opens the teacher home form
|
||||||
|
frmTeacherHome.Show()
|
||||||
|
'Closes this form
|
||||||
|
Me.Close()
|
||||||
|
End Sub
|
||||||
|
End Class
|
123
frmLogin.vb
Normal file
123
frmLogin.vb
Normal file
|
@ -0,0 +1,123 @@
|
||||||
|
Imports MySql.Data.MySqlClient
|
||||||
|
|
||||||
|
Public Class frmLogin
|
||||||
|
|
||||||
|
'Declares the variables used for logging in
|
||||||
|
Dim EnteredUsername, EnteredPassword As String
|
||||||
|
|
||||||
|
'Subroutine runs when the form loads
|
||||||
|
Private Sub frmLogin_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
|
||||||
|
'Closes the splash screen form
|
||||||
|
frmSplash.Close()
|
||||||
|
|
||||||
|
'Runs the first-time setup detection subroutine
|
||||||
|
DetectFTS()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when the OK 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 the cancel button is clicked
|
||||||
|
Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
|
||||||
|
'Closes the program
|
||||||
|
Me.Close()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when called in the form load sub
|
||||||
|
Sub DetectFTS()
|
||||||
|
'Declares the variable used to determine whether first-time setup has been run
|
||||||
|
Dim FTS As String
|
||||||
|
'Declares the variable used to read the first-time setup text file
|
||||||
|
Dim Reader As System.IO.StreamReader
|
||||||
|
|
||||||
|
'Gets the path to the FTS.txt text file
|
||||||
|
Reader = My.Computer.FileSystem.OpenTextFileReader("FTS.txt")
|
||||||
|
|
||||||
|
'Reads what is in the FTS.txt text file
|
||||||
|
FTS = Reader.ReadToEnd
|
||||||
|
'If the text file consists of 0 then the first-time setup has not been run before, so...
|
||||||
|
If FTS = "0" Then
|
||||||
|
'Opens the first-time setup message form
|
||||||
|
frmFTSMsg.Show()
|
||||||
|
End If
|
||||||
|
'Closes the reader
|
||||||
|
Reader.Close()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when called in the OK button click sub
|
||||||
|
Sub Login()
|
||||||
|
'Establishes the connection to the database
|
||||||
|
OpenDB()
|
||||||
|
|
||||||
|
'Sets the EnteredUsername variable to the entered username
|
||||||
|
EnteredUsername = txtUsername.Text
|
||||||
|
'Sets the EnteredPassword variable to the entered password
|
||||||
|
EnteredPassword = txtPassword.Text
|
||||||
|
|
||||||
|
Dim sql As String
|
||||||
|
Dim dbcomm As MySqlCommand
|
||||||
|
Dim dbread As MySqlDataReader
|
||||||
|
|
||||||
|
'Builds SQL query to execute
|
||||||
|
sql = "SELECT * FROM tblstudents WHERE Username='" & EnteredUsername & "' AND Password='" & EnteredPassword & "'"
|
||||||
|
|
||||||
|
dbcomm = New MySqlCommand(sql, DBConn)
|
||||||
|
dbread = dbcomm.ExecuteReader()
|
||||||
|
'Fills the various properties of the LoggedInStudent object with their respective values from the database
|
||||||
|
While dbread.Read
|
||||||
|
With LoggedInStudent
|
||||||
|
.Fname = dbread("Fname")
|
||||||
|
.Lname = dbread("Lname")
|
||||||
|
.Form = dbread("FormNum") & dbread("FormLetter")
|
||||||
|
.Wins = dbread("Wins")
|
||||||
|
.Losses = dbread("Losses")
|
||||||
|
.Draws = dbread("Draws")
|
||||||
|
.Username = dbread("Username")
|
||||||
|
.StudentID = dbread("StudentID")
|
||||||
|
End With
|
||||||
|
dbread.Close()
|
||||||
|
DBConn.Close()
|
||||||
|
|
||||||
|
'Opens the student home form
|
||||||
|
frmStudentHome.Show()
|
||||||
|
'Closes this form
|
||||||
|
Me.Close()
|
||||||
|
Exit Sub
|
||||||
|
End While
|
||||||
|
dbread.Close()
|
||||||
|
|
||||||
|
sql = "SELECT * FROM tblteachers WHERE Username='" & EnteredUsername & "' AND Password='" & EnteredPassword & "'"
|
||||||
|
|
||||||
|
dbcomm = New MySqlCommand(sql, DBConn)
|
||||||
|
dbread = dbcomm.ExecuteReader()
|
||||||
|
'Fills the various properties of the LoggedInTeacher object with their respective values from the database
|
||||||
|
While dbread.Read
|
||||||
|
With LoggedInTeacher
|
||||||
|
.Fname = dbread("Fname")
|
||||||
|
.Lname = dbread("Lname")
|
||||||
|
.Username = dbread("Username")
|
||||||
|
.TeacherID = dbread("TeacherID")
|
||||||
|
End With
|
||||||
|
dbread.Close()
|
||||||
|
DBConn.Close()
|
||||||
|
|
||||||
|
'Opens the teacher home form
|
||||||
|
frmTeacherHome.Show()
|
||||||
|
'Closes this form
|
||||||
|
Me.Close()
|
||||||
|
Exit Sub
|
||||||
|
End While
|
||||||
|
dbread.Close()
|
||||||
|
|
||||||
|
'If no records are found in either table...
|
||||||
|
'Displays an error message
|
||||||
|
MsgBox("Invalid: Incorrect username or password.")
|
||||||
|
'Blanks out the username textbox
|
||||||
|
txtUsername.Text = ""
|
||||||
|
'Blanks out the password textbox
|
||||||
|
txtPassword.Text = ""
|
||||||
|
End Sub
|
||||||
|
End Class
|
106
frmSplash.vb
Normal file
106
frmSplash.vb
Normal file
|
@ -0,0 +1,106 @@
|
||||||
|
Public Class frmSplash
|
||||||
|
'Declares the variable used for counting down the loading
|
||||||
|
Dim Count As Integer = 0
|
||||||
|
'Declares the variable used for the first half of the loading phrases
|
||||||
|
Dim LiesP1(11) As String
|
||||||
|
'Declares the variable used for the second half of the loading phrases
|
||||||
|
Dim LiesP2(11) As String
|
||||||
|
|
||||||
|
'Subroutine runs when the form loads
|
||||||
|
Private Sub frmSplash_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
|
||||||
|
'Enables the timer used to simulate a loading
|
||||||
|
tmrLoading.Enabled = True
|
||||||
|
|
||||||
|
'Runs the loading phrase generation subroutine
|
||||||
|
Lies()
|
||||||
|
|
||||||
|
'Runs the random number generator subroutine
|
||||||
|
Randomize()
|
||||||
|
|
||||||
|
'Declares the variable used for the first half of the loading phrases
|
||||||
|
Dim Lie1 As Integer = CInt(Int(5 * Rnd()) + 1)
|
||||||
|
'Declares the variable used for the second half of the loading phrases
|
||||||
|
Dim Lie2 As Integer = CInt(Int(5 * Rnd()) + 1)
|
||||||
|
|
||||||
|
'Creates a loading phrase
|
||||||
|
lblLies.Text = LiesP1(Lie1) & " " & LiesP2(Lie2)
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when called in the form load sub
|
||||||
|
Sub Lies()
|
||||||
|
'Fills the first half of the loading phrase with possible words
|
||||||
|
LiesP1(1) = "Triangulating"
|
||||||
|
LiesP1(2) = "Decoding"
|
||||||
|
LiesP1(3) = "Turtling"
|
||||||
|
LiesP1(4) = "Calculating"
|
||||||
|
LiesP1(5) = "Transcoding"
|
||||||
|
LiesP1(6) = "Observing"
|
||||||
|
LiesP1(7) = "Translating"
|
||||||
|
LiesP1(8) = "Hypothesising"
|
||||||
|
LiesP1(9) = "Polymorphing"
|
||||||
|
LiesP1(10) = "Flipping"
|
||||||
|
LiesP1(11) = "Reticulating"
|
||||||
|
|
||||||
|
'Fills the second half of the loading phrase with possible words
|
||||||
|
LiesP2(1) = "code"
|
||||||
|
LiesP2(2) = "sums"
|
||||||
|
LiesP2(3) = "hexagons"
|
||||||
|
LiesP2(4) = "rolls"
|
||||||
|
LiesP2(5) = "beeps"
|
||||||
|
LiesP2(6) = "compulsion"
|
||||||
|
LiesP2(7) = "singularity engine"
|
||||||
|
LiesP2(8) = "boops"
|
||||||
|
LiesP2(9) = "the machine spirit"
|
||||||
|
LiesP2(10) = "observance"
|
||||||
|
LiesP2(11) = "splines"
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Subroutine runs when timer is enabled
|
||||||
|
Private Sub tmrLoading_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrLoading.Tick
|
||||||
|
'Runs the random number generator subroutine
|
||||||
|
Randomize()
|
||||||
|
|
||||||
|
'Declares the variable used for determining how big a step to take
|
||||||
|
Dim Tick As Integer
|
||||||
|
'Declares the variable used for keeping the timer from stepping out-of-bounds
|
||||||
|
Dim Check As Integer = 10
|
||||||
|
|
||||||
|
'If there is more than 10 counts remaining in the timer...
|
||||||
|
If progLoading.Value < 990 Then
|
||||||
|
'Sets the step size as a random number between 0-9
|
||||||
|
Tick = CInt(Int(10 * Rnd()))
|
||||||
|
'If there are only 10 counts remaining...
|
||||||
|
Else
|
||||||
|
'Sets the step size as a random number within the bounds of the timer
|
||||||
|
Tick = CInt(Int((1000 - progLoading.Value) * Rnd()) + 1)
|
||||||
|
End If
|
||||||
|
|
||||||
|
'On each tick of the timer, 'Count' is increased by the step size
|
||||||
|
Count = Count + Tick
|
||||||
|
'Along with this, the progress bar increments by the step size
|
||||||
|
progLoading.Value = progLoading.Value + Tick
|
||||||
|
|
||||||
|
'If the timer is at a value divisible by 10...
|
||||||
|
If Count Mod Check = 0 Then
|
||||||
|
'Declares the variable used for the first half of the loading phrases
|
||||||
|
Dim Lie1 As Integer = CInt(Int(5 * Rnd()) + 1)
|
||||||
|
'Declares the variable used for the second half of the loading phrases
|
||||||
|
Dim Lie2 As Integer = CInt(Int(5 * Rnd()) + 1)
|
||||||
|
|
||||||
|
'Creates a loading phrase
|
||||||
|
lblLies.Text = LiesP1(Lie1) & " " & LiesP2(Lie2)
|
||||||
|
|
||||||
|
''Check' increments by 10
|
||||||
|
Check = Check + 10
|
||||||
|
End If
|
||||||
|
|
||||||
|
'If the timer has reached its limit...
|
||||||
|
If Count = 1000 Then
|
||||||
|
'Disable the timer
|
||||||
|
tmrLoading.Enabled = False
|
||||||
|
'Show the login form
|
||||||
|
frmLogin.Show()
|
||||||
|
End If
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
End Class
|
84
mdlPublicVars.vb
Normal file
84
mdlPublicVars.vb
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
'Add a reference to COM Microsoft ActiveX Data Objects 6.1
|
||||||
|
Imports MySql.Data.MySqlClient
|
||||||
|
|
||||||
|
Module mdlPublicVars
|
||||||
|
|
||||||
|
'//Connect Four\\
|
||||||
|
'Declares the variable used for storing the current player of a game of Connect Four
|
||||||
|
Public C4Player As String
|
||||||
|
'Declares the variables used for determining the questions to display in a game of Connect Four
|
||||||
|
Public C4HSubject, C4HDifficulty, C4HTopic As String
|
||||||
|
|
||||||
|
'//Noughts and Crosses\\
|
||||||
|
'Declares the variable used for storing the current player of a game of Noughts and Crosses
|
||||||
|
Public NaCPlayer As String
|
||||||
|
'Declares the variables used for determining the questions to display in a game of Noughts and Crosses
|
||||||
|
Public NaCSubject, NaCDifficulty, NaCTopic As String
|
||||||
|
|
||||||
|
'//Rock, Paper, Scissors\\
|
||||||
|
'Declares the variable used for storing the current player of a game of Rock, Paper, Scissors
|
||||||
|
Public RPSPlayer As String
|
||||||
|
'Declares the variables used for determining the questions to display in a game of Rock, Paper, Scissors
|
||||||
|
Public RPSSubject, RPSDifficulty, RPSTopic As String
|
||||||
|
'Declares the variables used to store the selected weapons of each player
|
||||||
|
Public LoggedInWeapon, OppWeapon As Integer
|
||||||
|
|
||||||
|
'//General\\
|
||||||
|
|
||||||
|
'/General\
|
||||||
|
|
||||||
|
'Declares the variable used for storing the path to the database
|
||||||
|
Public DBPath As String
|
||||||
|
'Declares the variable used to connect to mySQL database
|
||||||
|
Public DBConn As MySqlConnection
|
||||||
|
'Subroutine runs when called
|
||||||
|
Public Sub OpenDB()
|
||||||
|
Try
|
||||||
|
'Builds the connection string for the database
|
||||||
|
DBConn = New MySqlConnection
|
||||||
|
DBConn.ConnectionString = "STUFF"
|
||||||
|
DBConn.Open()
|
||||||
|
Catch ex As Exception
|
||||||
|
MsgBox("Database is borked")
|
||||||
|
End Try
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
|
||||||
|
'Declares the variable used for storing the GameID for network play
|
||||||
|
Public GameID As String
|
||||||
|
|
||||||
|
'/Students\
|
||||||
|
|
||||||
|
'Declares the variables used for storing the details of both players
|
||||||
|
Public FnameStudent, LnameStudent, FnameOppStudent, LnameOppStudent, Form, ImageStudentLoc, ImageOppStudentLoc As String
|
||||||
|
'Declares the variable used for storing the StudentID of a player
|
||||||
|
Public StudentID As Integer
|
||||||
|
'Declares the class used for both players
|
||||||
|
Public Class Student
|
||||||
|
'Declares the variables used for storing the details of the student
|
||||||
|
Public Fname, Lname, Form, Username, C4Player, NaCPlayer As String
|
||||||
|
Public StudentID, Wins, Losses, Draws, RPSPlayer As Integer
|
||||||
|
End Class
|
||||||
|
'Creates two objects of the student class
|
||||||
|
Public LoggedInStudent As New Student
|
||||||
|
Public OppStudent As New Student
|
||||||
|
'Used to populate the Student Account form with the correct data
|
||||||
|
Public Viewing As Integer = 1
|
||||||
|
|
||||||
|
'/Teachers\
|
||||||
|
|
||||||
|
'Declares the variables used for storing the details of the teacher
|
||||||
|
Public FnameTeacher, LnameTeacher, imageteacherloc As String
|
||||||
|
'Declares the variable used for storing the TeacherID
|
||||||
|
Public TeacherID As Integer
|
||||||
|
'Declares the class used for the teacher
|
||||||
|
Public Class Teacher
|
||||||
|
'Declares the variables used for storing the details of the teacher
|
||||||
|
Public Fname, Lname, Username As String
|
||||||
|
Public TeacherID As Integer
|
||||||
|
End Class
|
||||||
|
'Creates an object of the teacher class
|
||||||
|
Public LoggedInTeacher As New Teacher
|
||||||
|
|
||||||
|
End Module
|
||||||
|
|
Reference in a new issue