2 Replies - 1072 Views - Last Post: 21 May 2014 - 06:17 PM Rate Topic: -----

#1 6435232  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 17-May 14

Adjacency Game

Posted 17 May 2014 - 11:58 AM

I'm making a game for class, and I don't know how to go about it for this part of the game... How do I make the program detect the command buttons around it?

The game is a 8x8 board that looks like this:

http://s27.postimg.o...shovn/image.png

When it is a player's turn (player x) and they put an x right beside one of the O's, then it changes to X.

http://s28.postimg.o...inhsd/image.png

My code is here.

Option Explicit
Private Const playerx As String = "X"
Private Const playero As String = "O"
Private nextplayer As String

Private Sub cmd1_Click(Index As Integer)
    Dim intIndex As Integer
    Dim intIndex2 As Integer
    
    'Take turns
    If nextplayer = "X" Then
        cmd1(Index).Caption = nextplayer
        nextplayer = playero
        lblAnswer.Caption = "Player O turn"
    ElseIf nextplayer = "O" Then
        cmd1(Index).Caption = nextplayer
        nextplayer = playerx
        lblAnswer.Caption = "Player X turn"
    End If
    
    'Check for other x/o beside or above placed x/o
    If cmd1(Index) = nextplayer Then
        If cmd1(Index + 1) <> nextplayer Then
            If cmd1(Index - 9) <> nextplayer Then
                cmd1(Index + 1).Caption = nextplayer
                cmd1(Index - 9).Caption = nextplayer
            End If
        End If
    End If
    
    'Disable buttons with stuff in them
    For intIndex = 0 To 63
        If cmd1(intIndex).Caption <> "" Then
            cmd1(intIndex).Enabled = False
        Else
            cmd1(intIndex).Enabled = True
        End If
    Next

End Sub

Private Sub cmdNewGame_Click()
    Call Form_Load
End Sub

Private Sub Form_Load()
    Dim intIndex As Integer
    
    'Make board blank
    For intIndex = 0 To 63
        cmd1(intIndex).Caption = ""
    Next
    
    'Make board have x and o
    cmd1(7).Caption = "O"
    cmd1(6).Caption = "O"
    cmd1(15).Caption = "O"
    cmd1(14).Caption = "O"
    
    cmd1(56).Caption = "X"
    cmd1(57).Caption = "X"
    cmd1(49).Caption = "X"
    cmd1(48).Caption = "X"
    
    'Disable buttons with stuff in them
    For intIndex = 0 To 63
        If cmd1(intIndex).Caption <> "" Then
            cmd1(intIndex).Enabled = False
        Else
            cmd1(intIndex).Enabled = True
        End If
    Next
    
    If nextplayer = "" Then
        nextplayer = playerx
        lblAnswer.Caption = "Player X turn"
    End If
End Sub


Is This A Good Question/Topic? 0
  • +

Replies To: Adjacency Game

#2 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: Adjacency Game

Posted 21 May 2014 - 05:00 PM

I don't know. Suppose you pretend that you know nothing about your program, and I have written this post to explain it to you. Would you understand what I was talking about?

This post has been edited by BobRodes: 21 May 2014 - 05:03 PM

Was This Post Helpful? 0
  • +
  • -

#3 6435232  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 17-May 14

Re: Adjacency Game

Posted 21 May 2014 - 06:17 PM

View PostBobRodes, on 21 May 2014 - 08:00 PM, said:

I don't know. Suppose you pretend that you know nothing about your program, and I have written this post to explain it to you. Would you understand what I was talking about?


I would like it if you could explain it simply step by step.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1