写好了
Public Class Form1
Friend WithEvents pic As PictureBox
Private turn As Boolean = True
Private PicArray(15, 15) As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Table()
End Sub
Private Sub Table()
For row As Integer = 0 To 14 '横排
For col As Integer = 0 To 14 '竖排
pic = New PictureBox() '定义一个图片框
pic.Size = New Size(25, 25) '设置图片框大小
pic.BorderStyle = BorderStyle.FixedSingle '单行边框
pic.Location = New Point(row * 25, col * 25) '设置图片位置
pic.Tag = New Point(row, col) '记录图片自身的坐标
pic.BackColor = Color.Moccasin '颜色
AddHandler DirectCast(pic, PictureBox).Click, AddressOf Pic_Click
Me.Controls.Add(pic) '添加
Next
Next
End Sub
Private Sub Pic_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pic.Click
If PicArray(sender.Tag.X, sender.Tag.Y) = 0 Then
If turn Then '如果turn=true就黑棋
sender.Image = New Bitmap("D:\Documents and Settings\Administrator\Desktop\Black.png")
PicArray(sender.Tag.X, sender.Tag.Y) = 1 '黑棋赋值1
turn = False
Check(sender.Tag.X, sender.Tag.Y, 1)
Else '反之白棋
sender.Image = New Bitmap("D:\Documents and Settings\Administrator\Desktop\White.png")
PicArray(sender.Tag.X, sender.Tag.Y) = 2 '白棋赋值2
turn = True
Check(sender.Tag.X, sender.Tag.Y, 2)
End If
End If
End Sub
Private Sub Check(ByVal picX As Integer, ByVal picY As Integer, ByVal turn As Integer)
Dim count As Integer = -1
Dim R_X = picX
Dim R_Y = picY
'竖直下边
While (PicArray(picX, picY) = turn)
picY -= 1
count += 1
End While
picX = R_X
picY = R_Y
'竖直上边
While (PicArray(picX, picY) = turn)
picY += 1
count += 1
End While
If count >= 5 Then
MsgBox(turn.ToString() & "胜利")
End If
count = -1
picX = R_X
picY = R_Y
'水平左边
While (PicArray(picX, picY) = turn)
picX -= 1
count += 1
End While
picX = R_X
picY = R_Y
'水平右边
While (PicArray(picX, picY) = turn)
picX += 1
count += 1
End While
If count >= 5 Then
MsgBox(turn.ToString() & "胜利")
End If
count = -1
picX = R_X
picY = R_Y