Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Class frmHumanVSComputer
- Private strSpeler1, strSpeler2 As String
- Private strOXO As String = "O"
- Private strX As String = "X"
- Private blnBoolean As Boolean = False
- Private objRandom As New Random
- Private intRandom As Integer
- Private Sub btnTerug_Click(sender As System.Object, e As System.EventArgs) Handles btnTerug.Click
- Me.Close()
- frmBegin.Show()
- End Sub
- Private Sub btn1_Click(sender As System.Object, e As System.EventArgs) Handles btn1.Click
- btn1.Text = strOXO
- btn1.Enabled = False
- WieWintM()
- If blnBoolean = False Then
- Computer()
- End If
- End Sub
- Private Sub btn2_Click(sender As System.Object, e As System.EventArgs) Handles btn2.Click
- btn2.Text = strOXO
- btn2.Enabled = False
- WieWintM()
- If blnBoolean = False Then
- Computer()
- End If
- End Sub
- Private Sub btn3_Click(sender As System.Object, e As System.EventArgs) Handles btn3.Click
- btn3.Text = strOXO
- btn3.Enabled = False
- WieWintM()
- If blnBoolean = False Then
- Computer()
- End If
- End Sub
- Private Sub btn4_Click(sender As System.Object, e As System.EventArgs) Handles btn4.Click
- btn4.Text = strOXO
- btn4.Enabled = False
- WieWintM()
- If blnBoolean = False Then
- Computer()
- End If
- End Sub
- Private Sub btn5_Click(sender As System.Object, e As System.EventArgs) Handles btn5.Click
- btn5.Text = strOXO
- btn5.Enabled = False
- WieWintM()
- If blnBoolean = False Then
- Computer()
- End If
- End Sub
- Private Sub btn6_Click(sender As System.Object, e As System.EventArgs) Handles btn6.Click
- btn6.Text = strOXO
- btn6.Enabled = False
- WieWintM()
- If blnBoolean = False Then
- Computer()
- End If
- End Sub
- Private Sub btn7_Click(sender As System.Object, e As System.EventArgs) Handles btn7.Click
- btn7.Text = strOXO
- btn7.Enabled = False
- WieWintM()
- If blnBoolean = False Then
- Computer()
- End If
- End Sub
- Private Sub btn8_Click(sender As System.Object, e As System.EventArgs) Handles btn8.Click
- btn8.Text = strOXO
- btn8.Enabled = False
- WieWintM()
- If blnBoolean = False Then
- Computer()
- End If
- End Sub
- Private Sub btn9_Click(sender As System.Object, e As System.EventArgs) Handles btn9.Click
- btn9.Text = strOXO
- btn9.Enabled = False
- WieWintM()
- If blnBoolean = False Then
- Computer()
- End If
- End Sub
- Private Sub btnOpnieuw_Click(sender As System.Object, e As System.EventArgs) Handles btnOpnieuw.Click
- btn1.Text = String.Empty
- btn2.Text = String.Empty
- btn3.Text = String.Empty
- btn4.Text = String.Empty
- btn5.Text = String.Empty
- btn6.Text = String.Empty
- btn7.Text = String.Empty
- btn8.Text = String.Empty
- btn9.Text = String.Empty
- btn1.Enabled = True
- btn2.Enabled = True
- btn3.Enabled = True
- btn4.Enabled = True
- btn5.Enabled = True
- btn6.Enabled = True
- btn7.Enabled = True
- btn8.Enabled = True
- btn9.Enabled = True
- lblWin.Text = String.Empty
- btn1.BackColor = Color.FromKnownColor(KnownColor.Control)
- btn2.BackColor = Color.FromKnownColor(KnownColor.Control)
- btn3.BackColor = Color.FromKnownColor(KnownColor.Control)
- btn4.BackColor = Color.FromKnownColor(KnownColor.Control)
- btn5.BackColor = Color.FromKnownColor(KnownColor.Control)
- btn6.BackColor = Color.FromKnownColor(KnownColor.Control)
- btn7.BackColor = Color.FromKnownColor(KnownColor.Control)
- btn8.BackColor = Color.FromKnownColor(KnownColor.Control)
- btn9.BackColor = Color.FromKnownColor(KnownColor.Control)
- blnBoolean = False
- End Sub
- Private Sub frmHumanVSComputer_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
- strSpeler1 = InputBox("Geef de naam van de speler in", "Speler 1")
- strSpeler2 = "Computer"
- lblSpeler1.Text = strSpeler1
- lblSpeler2.Text = strSpeler2
- btn1.BackColor = Color.FromKnownColor(KnownColor.Control)
- btn2.BackColor = Color.FromKnownColor(KnownColor.Control)
- btn3.BackColor = Color.FromKnownColor(KnownColor.Control)
- btn4.BackColor = Color.FromKnownColor(KnownColor.Control)
- btn5.BackColor = Color.FromKnownColor(KnownColor.Control)
- btn6.BackColor = Color.FromKnownColor(KnownColor.Control)
- btn7.BackColor = Color.FromKnownColor(KnownColor.Control)
- btn8.BackColor = Color.FromKnownColor(KnownColor.Control)
- btn9.BackColor = Color.FromKnownColor(KnownColor.Control)
- End Sub
- Function WieWintM()
- If btn1.Text = "X" And btn2.Text = "X" And btn3.Text = "X" Then
- lblWin.Text = strSpeler2 & " wint"
- pgb2.Increment(10)
- btnDisableM()
- btn1.BackColor = Color.Red
- btn2.BackColor = Color.Red
- btn3.BackColor = Color.Red
- blnBoolean = True
- End If
- If btn4.Text = "X" And btn5.Text = "X" And btn6.Text = "X" Then
- lblWin.Text = strSpeler2 & " wint"
- pgb2.Increment(10)
- btnDisableM()
- btn4.BackColor = Color.Red
- btn5.BackColor = Color.Red
- btn6.BackColor = Color.Red
- blnBoolean = True
- End If
- If btn7.Text = "X" And btn8.Text = "X" And btn9.Text = "X" Then
- lblWin.Text = strSpeler2 & " wint"
- pgb2.Increment(10)
- btnDisableM()
- btn7.BackColor = Color.Red
- btn8.BackColor = Color.Red
- btn9.BackColor = Color.Red
- blnBoolean = True
- End If
- If btn1.Text = "X" And btn4.Text = "X" And btn7.Text = "X" Then
- lblWin.Text = strSpeler2 & " wint"
- btnDisableM()
- btn1.BackColor = Color.Red
- btn4.BackColor = Color.Red
- btn7.BackColor = Color.Red
- blnBoolean = True
- End If
- If btn2.Text = "X" And btn5.Text = "X" And btn8.Text = "X" Then
- lblWin.Text = strSpeler2 & " wint"
- pgb2.Increment(10)
- btnDisableM()
- btn2.BackColor = Color.Red
- btn5.BackColor = Color.Red
- btn8.BackColor = Color.Red
- blnBoolean = True
- End If
- If btn3.Text = "X" And btn6.Text = "X" And btn9.Text = "X" Then
- lblWin.Text = strSpeler2 & " wint"
- pgb2.Increment(10)
- btnDisableM()
- btn3.BackColor = Color.Red
- btn6.BackColor = Color.Red
- btn9.BackColor = Color.Red
- blnBoolean = True
- End If
- If btn1.Text = "X" And btn5.Text = "X" And btn9.Text = "X" Then
- lblWin.Text = strSpeler2 & " wint"
- pgb2.Increment(10)
- btnDisableM()
- btn1.BackColor = Color.Red
- btn5.BackColor = Color.Red
- btn9.BackColor = Color.Red
- blnBoolean = True
- End If
- If btn3.Text = "X" And btn5.Text = "X" And btn7.Text = "X" Then
- lblWin.Text = strSpeler2 & " wint"
- pgb2.Increment(10)
- btnDisableM()
- btn3.BackColor = Color.Red
- btn5.BackColor = Color.Red
- btn7.BackColor = Color.Red
- blnBoolean = True
- End If
- If btn1.Text = "O" And btn2.Text = "O" And btn3.Text = "O" Then
- lblWin.Text = strSpeler1 & " wint"
- pgb1.Increment(10)
- btnDisableM()
- btn1.BackColor = Color.Yellow
- btn2.BackColor = Color.Yellow
- btn3.BackColor = Color.Yellow
- blnBoolean = True
- End If
- If btn4.Text = "O" And btn5.Text = "O" And btn6.Text = "O" Then
- lblWin.Text = strSpeler1 & " wint"
- pgb1.Increment(10)
- btnDisableM()
- btn4.BackColor = Color.Yellow
- btn5.BackColor = Color.Yellow
- btn6.BackColor = Color.Yellow
- blnBoolean = True
- End If
- If btn7.Text = "O" And btn8.Text = "O" And btn9.Text = "O" Then
- lblWin.Text = strSpeler1 & " wint"
- pgb1.Increment(10)
- btnDisableM()
- btn7.BackColor = Color.Yellow
- btn8.BackColor = Color.Yellow
- btn9.BackColor = Color.Yellow
- blnBoolean = True
- End If
- If btn1.Text = "O" And btn4.Text = "O" And btn7.Text = "O" Then
- lblWin.Text = strSpeler1 & " wint"
- pgb1.Increment(10)
- btnDisableM()
- btn1.BackColor = Color.Yellow
- btn4.BackColor = Color.Yellow
- btn7.BackColor = Color.Yellow
- blnBoolean = True
- End If
- If btn2.Text = "O" And btn5.Text = "O" And btn8.Text = "O" Then
- lblWin.Text = strSpeler1 & " wint"
- pgb1.Increment(10)
- btnDisableM()
- btn2.BackColor = Color.Yellow
- btn5.BackColor = Color.Yellow
- btn8.BackColor = Color.Yellow
- blnBoolean = True
- End If
- If btn3.Text = "O" And btn6.Text = "O" And btn9.Text = "O" Then
- lblWin.Text = strSpeler1 & " wint"
- pgb1.Increment(10)
- btnDisableM()
- btn3.BackColor = Color.Yellow
- btn6.BackColor = Color.Yellow
- btn9.BackColor = Color.Yellow
- blnBoolean = True
- End If
- If btn1.Text = "O" And btn5.Text = "O" And btn9.Text = "O" Then
- lblWin.Text = strSpeler1 & " wint"
- pgb1.Increment(10)
- btnDisableM()
- btn1.BackColor = Color.Yellow
- btn5.BackColor = Color.Yellow
- btn9.BackColor = Color.Yellow
- blnBoolean = True
- End If
- If btn3.Text = "O" And btn5.Text = "O" And btn7.Text = "O" Then
- lblWin.Text = strSpeler1 & " wint"
- pgb1.Increment(10)
- btnDisableM()
- btn3.BackColor = Color.Yellow
- btn5.BackColor = Color.Yellow
- btn7.BackColor = Color.Yellow
- blnBoolean = True
- End If
- If btn1.Text <> String.Empty And btn2.Text <> String.Empty And btn3.Text <> String.Empty And btn4.Text <> String.Empty And btn5.Text <> String.Empty And btn6.Text <> String.Empty And btn7.Text <> String.Empty And btn8.Text <> String.Empty And btn9.Text <> String.Empty And blnBoolean = False Then
- lblWin.Text = " Gelijkspel"
- pgb1.Increment(10)
- pgb2.Increment(10)
- btnDisableM()
- End If
- Return False
- End Function
- Function btnDisableM()
- btn1.Enabled = False
- btn2.Enabled = False
- btn3.Enabled = False
- btn4.Enabled = False
- btn5.Enabled = False
- btn6.Enabled = False
- btn7.Enabled = False
- btn8.Enabled = False
- btn9.Enabled = False
- Return False
- End Function
- Function Computer()
- intRandom = objRandom.Next(1, 10)
- If btn1.Enabled = False And btn2.Enabled = False And btn3.Enabled = False And btn4.Enabled = False And btn5.Enabled = False And btn6.Enabled = False And btn7.Enabled = False And btn8.Enabled = False And btn9.Enabled = False Then
- Exit Function
- End If
- If intRandom = 1 Then
- If btn1.Enabled = True Then
- btn1.Text = strX
- btn1.Enabled = False
- Exit Function
- ElseIf btn1.Enabled = False Then
- Computer()
- End If
- End If
- If intRandom = 2 Then
- If btn2.Enabled = True Then
- btn2.Text = strX
- btn2.Enabled = False
- Exit Function
- ElseIf btn2.Enabled = False Then
- Computer()
- End If
- End If
- If intRandom = 3 Then
- If btn3.Enabled = True Then
- btn3.Text = strX
- btn3.Enabled = False
- Exit Function
- ElseIf btn3.Enabled = False Then
- Computer()
- End If
- End If
- If intRandom = 4 Then
- If btn4.Enabled = True Then
- btn4.Text = strX
- btn4.Enabled = False
- Exit Function
- ElseIf btn4.Enabled = False Then
- Computer()
- End If
- End If
- If intRandom = 5 Then
- If btn5.Enabled = True Then
- btn5.Text = strX
- btn5.Enabled = False
- Exit Function
- ElseIf btn5.Enabled = False Then
- Computer()
- End If
- End If
- If intRandom = 6 Then
- If btn6.Enabled = True Then
- btn6.Text = strX
- btn6.Enabled = False
- Exit Function
- ElseIf btn6.Enabled = False Then
- Computer()
- End If
- End If
- If intRandom = 7 Then
- If btn7.Enabled = True Then
- btn7.Text = strX
- btn7.Enabled = False
- Exit Function
- ElseIf btn7.Enabled = False Then
- Computer()
- End If
- End If
- If intRandom = 8 Then
- If btn8.Enabled = True Then
- btn8.Text = strX
- btn8.Enabled = False
- Exit Function
- ElseIf btn8.Enabled = False Then
- Computer()
- End If
- End If
- If intRandom = 9 Then
- If btn9.Enabled = True Then
- btn9.Text = strX
- btn9.Enabled = False
- Exit Function
- ElseIf btn9.Enabled = False Then
- Computer()
- End If
- End If
- WieWintM()
- End Function
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement