Hello everyone,
By the way im portuguese so , sorry for my english and im new in VB.net so sorry if i dont understand somethings.
I really need everyones help, you may think that my question is kind off easy for you , but for me its a bit hard to get it on code.
so that said , im developing a program in windows forms,acctually its a game "connect 4" my program its almost all done but i need the most important part of the code.
Ive done matrix (kind off a board where u can see save positionings, you may call it to bidemensional array) the game is 6*9. having 6 lines and 9 collums.
Im using PictureBoxes for my board .I already have a function that verifys if you can play in a certain picturebox. All the pictureboxes are in order (see below the code so
you can get it)so i think its easy for knowing were the player plays.I have 2 kinds of playing pieces, the red(PECAVERMELHA and PECAMARELA -->"its in portuguese the playing
pieces ones).
Some words in portuguese that i have in the programme.
Amarela = yellow
Vermelha= red
ganhar = Win
trancar = lock
marcardor = marker
quadro = board
So the question is how do i make a fuction or more that ill verify if it has 4 playing pieces in the horizontal , vertical and diagonal way?
I kinda know what i have to do so it would really help me if u programmers cold help me with code.
So, thank you everyone who can help me :D
Contact Me:
josepanike@gmail.com
All of our code
Public Class Form1
Public marcador, trancar(53) As Boolean
Public quadro(6, 9) As PictureBox
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim i As Integer
i = 0
marcador = True
For i = 0 To 53
trancar(i) = False
Next
' _______________________________________________________
' | |
' |Array bidimensional colunas por linhas do Connect 4 |
' |_______________________________________________________|
quadro(1, 1) = Me.PB11
quadro(1, 2) = Me.PB12
quadro(1, 3) = Me.PB13
quadro(1, 4) = Me.PB14
quadro(1, 5) = Me.PB15
quadro(1, 6) = Me.PB16
quadro(1, 7) = Me.PB17
quadro(1, 8) = Me.PB18
quadro(1, 9) = Me.PB19
quadro(2, 1) = Me.PB21
quadro(2, 2) = Me.PB22
quadro(2, 3) = Me.PB23
quadro(2, 4) = Me.PB24
quadro(2, 5) = Me.PB25
quadro(2, 6) = Me.PB26
quadro(2, 7) = Me.PB27
quadro(2, 8) = Me.PB28
quadro(2, 9) = Me.PB29
quadro(3, 1) = Me.PB31
quadro(3, 2) = Me.PB32
quadro(3, 3) = Me.PB33
quadro(3, 4) = Me.PB34
quadro(3, 5) = Me.PB35
quadro(3, 6) = Me.PB36
quadro(3, 7) = Me.PB37
quadro(3, 8) = Me.PB38
quadro(3, 9) = Me.PB39
quadro(4, 1) = Me.PB41
quadro(4, 2) = Me.PB42
quadro(4, 3) = Me.PB43
quadro(4, 4) = Me.PB44
quadro(4, 5) = Me.PB45
quadro(4, 6) = Me.PB46
quadro(4, 7) = Me.PB47
quadro(4, 8) = Me.PB48
quadro(4, 9) = Me.PB49
quadro(5, 1) = Me.PB51
quadro(5, 2) = Me.PB52
quadro(5, 3) = Me.PB53
quadro(5, 4) = Me.PB54
quadro(5, 5) = Me.PB55
quadro(5, 6) = Me.PB56
quadro(5, 7) = Me.PB57
quadro(5, 8) = Me.PB58
quadro(5, 9) = Me.PB59
quadro(6, 1) = Me.PB61
quadro(6, 2) = Me.PB62
quadro(6, 3) = Me.PB63
quadro(6, 4) = Me.PB64
quadro(6, 5) = Me.PB65
quadro(6, 6) = Me.PB66
quadro(6, 7) = Me.PB67
quadro(6, 8) = Me.PB68
quadro(6, 9) = Me.PB69
Label1.Text = ("Player's 1 turn")
End Sub
' Função para verificar se onde o utilizador deu o click tem alguma peça jogada.
'Se tiver nao pode jogar, se nao tiver verifica se tem alguma por baixo se nao tiver nao deixa o jogador jogar a peça.
Function verifica(ByVal x As Integer, ByVal y As Integer) As Boolean
Dim i As Integer
If quadro(x, y).Image Is Nothing And x = 1 Then
Return True
Else
For i = (x - 1) To 1 Step -1
If quadro(i, y).Image Is Nothing Then
Return False
End If
Next
Return True
End If
End Function
Function ganhar_amarelo(ByVal x As Integer, ByVal y As Integer) As Boolean
End Function
Function ganhar_vermelho(ByVal x As Integer, ByVal y As Integer) As Boolean
End Function
Private Sub PictureBox11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _
PB61.Click, PB62.Click, PB63.Click, PB64.Click, PB65.Click, PB66.Click, PB67.Click, PB68.Click, PB69.Click, _
PB51.Click, PB52.Click, PB53.Click, PB54.Click, PB55.Click, PB56.Click, PB57.Click, PB58.Click, PB59.Click, _
PB41.Click, PB42.Click, PB43.Click, PB44.Click, PB45.Click, PB46.Click, PB47.Click, PB48.Click, PB49.Click, _
PB31.Click, PB32.Click, PB33.Click, PB34.Click, PB35.Click, PB36.Click, PB37.Click, PB38.Click, PB39.Click, _
PB21.Click, PB22.Click, PB23.Click, PB24.Click, PB25.Click, PB26.Click, PB27.Click, PB28.Click, PB29.Click, _
PB11.Click, PB12.Click, PB13.Click, PB14.Click, PB15.Click, PB16.Click, PB17.Click, PB18.Click, PB19.Click
Dim x, y As Integer
Dim nome_picture As String
nome_picture = sender.name
x = nome_picture.Substring(2, 1)
y = nome_picture.Substring(3, 1)
If verifica(x, y) = True And quadro(x, y).Image Is Nothing Then
If marcador = True Then
Label1.Text = ("Player's 2 turn")
quadro(x, y).Image = My.Resources.PECAVERMELHA
ganhar_amarelo(x, y)
marcador = False
If quadro(1, 1).Image Is My.Resources.PECAVERMELHA And quadro(1, 2).Image Is My.Resources.PECAVERMELHA _
And quadro(1, 3).Image Is My.Resources.PECAVERMELHA And quadro(1, 4).Image Is My.Resources.PECAVERMELHA Then
MsgBox("Player's 2 WIN")
End If
Else
Label1.Text = ("Player's 1 turn")
quadro(x, y).Image = My.Resources.PECAMARELA
ganhar_vermelho(x, y)
marcador = True
If quadro(1, 1).Image Is My.Resources.PECAMARELA And quadro(1, 2).Image Is My.Resources.PECAMARELA _
And quadro(1, 3).Image Is My.Resources.PECAMARELA And quadro(1, 4).Image Is My.Resources.PECAMARELA Then
MsgBox("Player's 1 WIN")
End If
End If
End If
End Sub
End Class