424,952 Members | 916 Online
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

# Tic Tac Toe on a 4x4

 P: 2 I have the task of creating a tic tac toe game on a 4x4 board. It is a one player game with the computer as the opponent. The player (blue) clicks on a button and the computer (red) should automatically select a random positon on the board until there is a win lose or draw. I can't quite figure out how to setup the code for the colors or creating random number selection using this CInt(Int(Rnd() * 16 + 1)). Here is what I have so far: Expand|Select|Wrap|Line Numbers 'Project: Tic Tac Toe 'Programmer: Paige Mims 'Date: 04/20/2007 'Description: This project plays Tic Tac Toe.   Public Class Tictactoe       Private Sub Random()           Randomize()         Dim RandomClass As New Random()  'Declare RandomClass.Next(0, 17) 'Generates the random number between a range: 0 to 17          Dim RandomNumber As Integer         'RandomNumber = RandomClass.Next'         Randomize()         RandomNumber = CInt(Int(Rnd() * 16 + 1))         'Seed Random number generator         'Initialize the random # generator         Dim Board(4, 4) As String       End Sub     Private Sub SetPiece(ByVal Row As Integer, ByVal Column As Integer, ByVal pic As PictureBox)         If Board(Row, Column) = Red Or Board(Row, Column) = Blue Then             ' Do nothing if Red or Blue already in square               If IsBlue Then                 Board(Row, Column) = color.blue                 Me.Text = "Player:" & red             Else                 Board(Row, Column) = color.red                 Me.Text = "Player:" & blue             End If         End If     End Sub     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button2.Click, _     Button3.Click, Button4.Click, Button5.Click, Button6.Click, Button7.Click, Button8.Click, Button9.Click, Button10.Click, _     Button11.Click, Button12.Click, Button13.Click, Button14.Click, Button15.Click, Button16.Click             sender.Backcolor = Color.Blue           'Turns a square blue           If sender.BackColor = Color.Blue Then               Do                   Select Case sender.backcolor                       Case Is = 1 And Button1.BackColor = Color.Red                         Button1.BackColor = Color.Blue                       Case Is = 2 And Button2.BackColor = Color.Red                         Button2.BackColor = Color.Blue                       Case Is = 3 And Button3.BackColor = Color.Red                         Button3.BackColor = Color.Blue                       Case Is = 4 And Button4.BackColor = Color.Red                         Button4.BackColor = Color.Blue                       Case Is = 5 And Button5.BackColor = Color.Red                         Button5.BackColor = Color.Blue                       Case Is = 6 And Button6.BackColor = Color.Red                         Button6.BackColor = Color.Blue                       Case Is = 7 And Button7.BackColor = Color.Red                         Button7.BackColor = Color.Blue                       Case Is = 8 And Button8.BackColor = Color.Red                         Button8.BackColor = Color.Blue                       Case Is = 9 And Button9.BackColor = Color.Red                         Button9.BackColor = Color.Blue                       Case Is = 10 And Button10.BackColor = Color.Red                         Button10.BackColor = Color.Blue                       Case Is = 11 And Button11.BackColor = Color.Red                         Button11.BackColor = Color.Blue                       Case Is = 12 And Button12.BackColor = Color.Red                         Button12.BackColor = Color.Blue                       Case Is = 13 And Button13.BackColor = Color.Red                         Button13.BackColor = Color.Blue                       Case Is = 14 And Button14.BackColor = Color.Red                         Button14.BackColor = Color.Blue                       Case Is = 15 And Button15.BackColor = Color.Red                         Button15.BackColor = Color.Blue                       Case Is = 16 And Button16.BackColor = Color.Red                         Button16.BackColor = Color.Blue                   End Select               Loop Until True           End If       End Sub         Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button2.Click, _     Button3.Click, Button4.Click, Button5.Click, Button6.Click, Button7.Click, Button8.Click, Button9.Click, Button10.Click, _     Button11.Click, Button12.Click, Button13.Click, Button14.Click, Button15.Click, Button16.Click           Button1.BackColor = Color.Gray         Button2.BackColor = Color.Gray         Button3.BackColor = Color.Gray         Button4.BackColor = Color.Gray         Button5.BackColor = Color.Gray         Button6.BackColor = Color.Gray         Button7.BackColor = Color.Gray         Button8.BackColor = Color.Gray         Button9.BackColor = Color.Gray         Button10.BackColor = Color.Gray         Button11.BackColor = Color.Gray         Button12.BackColor = Color.Gray         Button13.BackColor = Color.Gray         Button14.BackColor = Color.Gray         Button15.BackColor = Color.Gray         Button16.BackColor = Color.Gray           End Sub End Class Where have I gone wrong???? Apr 20 '07 #1