Game of Nim Program

I'm relatively new to the world of VB, and computer languages in general. As a project for my High School computer class, I've been asked to create an application that allows a user to play the game of Nim against a computer so that the player can never win. When the form loads, it gives the user instructions on how to play, then is sets a value for the number of coins in the pile to 16. When the user selects a number of coins to remove from the pile (using a combobox) and clicks the Move button, the program is supposed to subtract 4 from the number of coins in the pile and tell the user how many coins the computer removed from the pile. Well, it doesn't do anything when the user clicks the Move button. It's probably something really easy, but I just don't see it. I've inserted the code I'm using below. If you can tell me what I did wrong, please e-mail me at kryptospaz@yahoo.com.

[code]Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim Pile As Integer
MessageBox.Show("There are 16 coins in a pile, and two players. The players take alternate turns. A turn consists of removing 1 to 3 coins from the pile. The player who removes the last coin wins.", "How To Play The Game Of Nim", MessageBoxButtons.OK, MessageBoxIcon.Information)
Pile = 16
End Sub

Private Sub btnNewGame_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNewGame.Click
Dim Pile As Integer
Pile = 16
cboNumber.Text = ""
End Sub

Private Sub btnInstructions_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInstructions.Click
MessageBox.Show("There are 16 coins in a pile, and two players. The players take alternate turns. A turn consists of removing 1 to 3 coins from the pile. The player who removes the last coin wins.", "How To Play The Game Of Nim", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub

Private Sub btnStrategy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStrategy.Click
MessageBox.Show("The way the compy always beats you is that it emsures that between your move and its, the two moves take four coins from the pile. Since you can only remove 3 coins at one time, the compy will always win! If you'd like to play a similar version of this game with the chance of winning, you can visit http://www.dotsphinx.com/games/nim/.")
End Sub

Private Sub btnExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExit.Click
End
End Sub

Private Sub btnMove_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnMove.Click
Dim Pile, NewPile As Integer, PlayerMove As String
PlayerMove = cboNumber.Text
Select Case PlayerMove
Case PlayerMove = "1"
NewPile = Pile - 4
MessageBox.Show("You removed 1 coin from the pile. The compy removes 3 coins from the pile. This leaves " & NewPile & " coins in the pile.", "Results")
Pile = NewPile
If Pile = 0 Then
MessageBox.Show("The compy removed the last coin. You lose!", "Results")
End If
Case PlayerMove = "2"
NewPile = Pile - 4
MessageBox.Show("You removed 2 coins from the pile. The compy removes 2 coins from the pile. This leaves " & NewPile & " coins in the pile.", "Results")
Pile = NewPile
If Pile = 0 Then
MessageBox.Show("The compy removed the last coin. You lose!", "Results")
End If
Case PlayerMove = "3"
NewPile = Pile - 4
MessageBox.Show("You removed 3 coins from the pile. The compy removes 1 coin from the pile. This leaves " & NewPile & " coins in the pile.", "Results")
Pile = NewPile
If Pile = 0 Then
MessageBox.Show("The compy removed the last coin. You lose!", "Results")
End If
End Select
End Sub[/code]
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories