eg: Player 1 can put an "x" in the middle (1, 1) and "o" can put his own sign there if he wants.
Is there anyway to "lock" a label when it changes its caption from "" to "x" or "o", so that the other user doesnt change input of the previous user?
Here is the code: (Improve it and repost it here if you have nothing to do)
scrof and skid are names for P1 and P2. Everything else is self explanatory.
Dim scrof, skid As String 'Declaring scrof = P1, skid = P2
Dim row(2), col(2) As Integer 'Considering array to count the number of row and col entries
Dim diag1, diag2, control As Integer 'Considering array to count the number of diag entries
'A datatype to hold value of the current player
Dim nowPlaying, notPlaying As String 'Two strings to hold names of players who are playing
Dim cnt As Integer 'Holds number of times clicks have happened
Private Sub cmdClear_Click()
'Erase all the previous captions
For x = 0 To 8
Label1(x).Caption = ""
Next
'Erase all the previous counter data
For x = 0 To 2
row(x) = 0
col(x) = 0
Next
diag1 = 0
diag2 = 0
cnt = 0
'Erase all data in the boxes
For x = 0 To 2
rowBox(x).Text = ""
colBox(x).Text = ""
Next
diag1.Text = ""
diag2.Text = ""
controlText.Text = ""
End Sub
Private Sub Label1_Click(Index As Integer)
Dim rowNo, colNo As Integer
'Decide who is the player playing currently and who's playing next
If (control = -1) Then
nowPlaying = scrof
notPlaying = skid
ElseIf (control = 1) Then
nowPlaying = skid
notPlaying = scrof
End If
'Calculate the row number and the col number of the clicked box
rowNo = Index \ 3
colNo = Index Mod 3
row(rowNo) = row(rowNo) + control
col(colNo) = col(colNo) + control
If (rowNo = colNo) Then
diag1 = diag1 + control
ElseIf (rowNo + colNo = 2) Then
diag2 = diag2 + control
End If
'Switch the control over to the next player
control = control * (-1)
If (nowPlaying = scrof) Then
Label1(Index).Caption = "x"
ElseIf (nowPlaying = skid) Then
Label1(Index).Caption = "o"
End If
'Check win/lose
'Linear result display
For x = 0 To 2
rowBox(x).Text = row(x) 'Comment these
colBox(x).Text = col(x) 'two lines
If (row(x) = 3 Or row(x) = -3 Or col(x) = 3 Or col(x) = -3) Then
controlText.Text = nowPlaying + " wins!"
MsgBox (nowPlaying + " wins!")
End If
Next
diag1Box.Text = diag1 'Comment these
diag2Box.Text = diag2 'two lines
'Diag result display
If (diag1 = 3 Or diag1 = -3 Or diag2 = 3 Or diag2 = -3) Then
controlText.Text = nowPlaying + " wins!"
MsgBox (nowPlaying + " wins!")
End If
cnt = cnt + 1
If cnt = 9 Then
controlText.Text = "Draw!!!"
MsgBox ("Draw!!!")
End If
End Sub
Private Sub cmdExit_Click()
End
End Sub
Private Sub Form_Load()
'scrof = InputBox("Name player 1: ")
'skid1 = InputBox("Name player 2: ")
'Temp values
scrof = "Meow"
skid = "Love"
control = -1
If (control = -1) Then
controlText.Text = scrof + " plays"
ElseIf (control = 1) Then
controlText.Text = skid + " plays"
End If
End Sub

New Topic/Question
Reply




MultiQuote





|