P.S. Ignore the crappy comments. They're to please my professor. I tried. But, comments are annoying to place on things that are nearly self-explanatory. Eventually, I just stop caring.
Public Class Form1
Dim matchsticks As Integer
Dim matchsticksLabel As String
Dim playing As Boolean = False
Dim playerTurn As Boolean = False
'Give the Rules of the Game button
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'Declare a constant so it doesn't fill up the line MsgBox() is on.
Const rules As String = "The object of this game is to pick up sticks. But, that's not all. Here is how the game is played. You choose the number of matchsticks (from 5 to 40) to place in a pile. Then, the computer will choose who goes first. When your turn comes, you can remove 1 - 3 matchsticks from the pile. The contestant who removes the last matchstick loses."
'Show the rules to the user
MsgBox(rules, , "Da Rules")
End Sub
'Begin a New Game button
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
If playing Then
If MsgBox("Do you really want to start a new game?", vbQuestion + vbYesNo) = vbNo Then
Return
End If
End If
'Constants for min/max sticks
Const minSticks As Integer = 5
Const maxSticks As Integer = 40
'Reset the matchsticks label
matchsticksLabel = ""
'Display input box and prompt the user properly.
If Integer.TryParse(InputBox("How many matchsticks do you want to place in a pile? (A number:" & minSticks.ToString() & " - " & maxSticks.ToString() & ")", "Starting Matchsticks", minSticks), matchsticks) Then
'The user has entered a valid entry.
If matchsticks >= minSticks And matchsticks <= maxSticks Then
playing = True
For index As Integer = 1 To matchsticks
matchsticksLabel += "| "
Next
TextBox1.Text = matchsticksLabel
If (matchsticks Mod 4) = 1 Then
playerTurn = True
MsgBox("The computer has chosen for you to go first.", , "Player Turn")
Else
playerTurn = False
MsgBox("The computer has chosen the be the first to go.", , "Player Turn")
CheckIfWon(CInt(Int((3 * Rnd()) + 1)))
End If
Else
'The user has entered a number out of range. Reset the program.
playing = False
matchsticks = 0
TextBox1.Text = matchsticksLabel
Return
End If
End If
End Sub
'Remove 1 matchstick
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Dim draw As Integer = 1
If draw > matchsticks Then
draw = matchsticks
End If
matchsticks -= 1
If Not CheckIfWon(draw) Then
playerTurn = Not playerTurn
TextBox1.Text = matchsticksLabel.Substring(0, matchsticks * 2)
CheckIfWon(CInt(Int((3 * Rnd()) + 1)))
End If
End Sub
'Remove 2 matchstick
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
Dim draw As Integer = 2
If draw > matchsticks Then
draw = matchsticks
End If
matchsticks -= draw
If Not CheckIfWon(draw) Then
playerTurn = Not playerTurn
TextBox1.Text = matchsticksLabel.Substring(0, matchsticks * 2)
CheckIfWon(Int((3 * Rnd()) + 1))
End If
End Sub
'Remove 3 matchstick
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
Dim draw As Integer = 3
If draw > matchsticks Then
draw = matchsticks
End If
matchsticks -= draw
If Not CheckIfWon(draw) Then
playerTurn = Not playerTurn
TextBox1.Text = matchsticksLabel.Substring(0, matchsticks * 2)
CheckIfWon(Int((3 * Rnd()) + 1))
End If
End Sub
'Check if the user has one or whether or not they are playing.
Private Function CheckIfWon(draw As Integer) As Boolean
'If there are no matchsticks to begin with or they are not playing... do nothing.
If (draw <= 0) Or (Not playing) Then
Return True
End If
'Whether or not the computer is drawing
If playerTurn = False Then
If draw >= matchsticks Then
If matchsticks <> 1 Then
draw = matchsticks - 1
Else
draw = matchsticks
End If
End If
matchsticks -= draw
TextBox1.Text = matchsticksLabel.Substring(0, matchsticks * 2)
End If
'End game results.
If matchsticks <= 0 Then
If playerTurn = False Then
MsgBox("The computer selects " & draw.ToString() & " matchsticks. I win.", , "Hooray")
Return True
Else
MsgBox("I select " & draw.ToString() & " matchsticks. I lose.", , "Boo")
Return True
End If
End If
'Post game results, whenever any contestant draws.
If playerTurn = True Then
MsgBox("I select " & draw.ToString() & "matchsticks. There are " & matchsticks.ToString() & " matchsticks left.", , "Drawing")
Else
MsgBox("The computer selects " & draw.ToString() & "matchsticks. There are " & matchsticks.ToString() & " matchsticks left.", , "Drawing")
playerTurn = Not playerTurn
End If
Return False
End Function
End Class
That language looks like Python and Assembly had a baby.