level 7
不需要电脑和网络,就是一台机子,点第一下黑色,第二下白色,时间什么的可以省略,就是有和连着5个黑或者白的时候提示胜利,有从新开始,和认输就行了,求大神把原代码复制过来…还有步骤,界面怎么坐…麻烦教教…
2013年11月19日 02点11分
1
level 6
Visual Basic范例开发大全 其中有一节讲五子棋 但是VB6.0 做的
2013年11月21日 13点11分
10
可是老师要求是2010旗舰版的vb做…
2013年11月22日 03点11分
回复 无聊有么有药 :主要是思路 变成自己写啊
2013年11月22日 04点11分
回复 w243818310 :哦哦,谢了,我去看看,可以给我网站吗
2013年11月22日 05点11分
回复 无聊有么有药 :《Visual Basic范例开发大全》.(隋丽娜,迟剑,郭立峰,) 你自己搜索一下吧
2013年11月22日 14点11分
level 13
不会vb.net的事件
搞了好久终于做出来
先发一下整个的思路
首先要循环创建15*15个PictureBox来当棋盘
然后记录每一个PictureBox的坐标 并且绑定事件
当点到图片框时触发事件 得到Tag
再把黑棋或白棋放上去
这时进行判断是否连成5子
————来自贴吧"境"客户端
2013年11月22日 08点11分
11
大神我爱死你了…
2013年11月22日 14点11分
@无聊有么有药 15*15个picturebox,大神你太可爱了。根本没必要,Gdi+用for循环画16+16条线,然后落子也用Gdi+画成球形(或者你用ps画个棋子加载后用gdi+画上去就行),五子棋最难的部分是电脑下子的算法
2016年05月07日 07点05分
@阎彼岸花 gdi+不用设置,已经集成在vs的ide里面了,只需要导入命名空间System.Drawing就可以用啦
2016年06月29日 23点06分
level 13
先写了一点
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) '记录图片自身的坐标
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
'MsgBox(sender.Tag.ToString())此处获取单击图片的坐标
End Sub
————来自贴吧"境"客户端
2013年11月22日 08点11分
12
level 13
写好了
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
'左上边斜
While (PicArray(picX, picY) = turn)
picX -= 1
picY -= 1
count += 1
End While
picX = R_X
picY = R_Y
'右下边斜
While (PicArray(picX, picY) = turn)
picX += 1
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
picY -= 1
count += 1
End While
picX = R_X
picY = R_Y
'左下边斜
While (PicArray(picX, picY) = turn)
picX -= 1
picY += 1
count += 1
End While
If count >= 5 Then
MsgBox(turn.ToString() & "胜利")
End If
End Sub
End Class
————来自贴吧"境"客户端
2013年11月22日 09点11分
14
用了1.5个小时
2013年11月22日 09点11分
level 13
黑棋白棋的图片要自己做
位置也要改一下
建议做成透明的
大小:25像素*25像素
————来自贴吧"境"客户端
2013年11月22日 09点11分
16
这个要用什么做呢?我大概能看懂,就是问一下,是用ps之类的吗?
2013年11月22日 15点11分
回复 无聊有么有药 :对 我就是用ps做的
2013年11月22日 15点11分
level 13
发现了一个bug 当棋子落在边界上时 检查算法会超出数组界限
为了方便我就加了 Try代码段
我再把代码重新发一遍
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.LightSteelBlue '颜色
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("E:\编程\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("E:\编程\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
Try
'竖直下边
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
If turn = 1 Then
MsgBox("黑棋" & "胜利")
Else
MsgBox("白棋" & "胜利")
End If
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
If turn = 1 Then
MsgBox("黑棋" & "胜利")
Else
MsgBox("白棋" & "胜利")
End If
End If
count = -1
picX = R_X
picY = R_Y
'左上边斜
While (PicArray(picX, picY) = turn)
picX -= 1
picY -= 1
count += 1
End While
picX = R_X
picY = R_Y
'右下边斜
While (PicArray(picX, picY) = turn)
picX += 1
picY += 1
count += 1
End While
If count >= 5 Then
If turn = 1 Then
MsgBox("黑棋" & "胜利")
Else
MsgBox("白棋" & "胜利")
End If
End If
count = -1
picX = R_X
picY = R_Y
'右上边斜
While (PicArray(picX, picY) = turn)
picX += 1
picY -= 1
count += 1
End While
picX = R_X
picY = R_Y
'左下边斜
While (PicArray(picX, picY) = turn)
picX -= 1
picY += 1
count += 1
End While
If count >= 5 Then
If turn = 1 Then
MsgBox("黑棋" & "胜利")
Else
MsgBox("白棋" & "胜利")
End If
End If
Catch
'当棋子落在边界时发生错误
End Try
End Sub
End Class
2013年11月26日 10点11分
18
回复 末日V4 :我想了很多种复杂方法解决 但是都失败了 最后想到简单的预留4排空间 就成功了
2013年11月26日 11点11分
level 13
要创建一个17*17的二维数组 这非常难想啊
Public Class Form1
Friend WithEvents pic As PictureBox
Private turn As Boolean = True
Private PicArray(17, 17) 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 = 1 To 15 '横排
For col As Integer = 1 To 15 '竖排
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.LightSteelBlue '颜色
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("E:\编程\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("E:\编程\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
If turn = 1 Then
MsgBox("黑棋" & "胜利")
Else
MsgBox("白棋" & "胜利")
End If
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
If turn = 1 Then
MsgBox("黑棋" & "胜利")
Else
MsgBox("白棋" & "胜利")
End If
End If
count = -1
picX = R_X
picY = R_Y
'左上边斜
While (PicArray(picX, picY) = turn)
picX -= 1
picY -= 1
count += 1
End While
picX = R_X
picY = R_Y
'右下边斜
While (PicArray(picX, picY) = turn)
picX += 1
picY += 1
count += 1
End While
If count >= 5 Then
If turn = 1 Then
MsgBox("黑棋" & "胜利")
Else
MsgBox("白棋" & "胜利")
End If
End If
count = -1
picX = R_X
picY = R_Y
'右上边斜
While (PicArray(picX, picY) = turn)
picX += 1
picY -= 1
count += 1
End While
picX = R_X
picY = R_Y
'左下边斜
While (PicArray(picX, picY) = turn)
picX -= 1
picY += 1
count += 1
End While
If count >= 5 Then
If turn = 1 Then
MsgBox("黑棋" & "胜利")
Else
MsgBox("白棋" & "胜利")
End If
End If
End Sub
End Class
2013年11月26日 11点11分
19
level 13
'详细注释
Public Class Form1
Friend WithEvents pic As PictureBox '声明一个带有事件的PictureBox
Private turn As Boolean = True '声明turn表示当前是哪一个回合
Private PicArray(17, 17) 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 = 1 To 15 '横排循环
For col As Integer = 1 To 15 '竖排循环
pic = New PictureBox() '实例化pic
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.LightSteelBlue '设置背景颜色
AddHandler DirectCast(pic, PictureBox).Click, AddressOf Pic_Click '绑定事件
Me.Controls.Add(pic) '添加到Form1
Next
Next
End Sub
Private Sub Pic_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pic.Click 'pic的单击事件
'senger参数为发起事件者(控件)
If PicArray(sender.Tag.X, sender.Tag.Y) = 0 Then '如果数组中这个位置是空的(0)
If turn Then '如果turn=true就黑棋
sender.Image = New Bitmap("E:\编程\Black.png") '把sender的显示的图片设为黑棋图片
PicArray(sender.Tag.X, sender.Tag.Y) = 1 '黑棋赋值1
turn = False '下一次该白棋
Check(sender.Tag.X, sender.Tag.Y, 1) '检查黑棋是否连成5子
Else '反之白棋
sender.Image = New Bitmap("E:\编程\White.png") '把sender的显示的图片设为黑棋图片
PicArray(sender.Tag.X, sender.Tag.Y) = 2 '白棋赋值2
turn = True '下一次是黑棋
Check(sender.Tag.X, sender.Tag.Y, 2) '检查白棋是否连成5子
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 '这里备份picX
Dim R_Y = picY '这里备份picY
'竖直上边
While (PicArray(picX, picY) = turn) '循环 往上面检测是否有和它相同颜色的棋子
picY -= 1 '纵坐标-1 用来传给接下来的循环
count += 1 '连成的棋子个数+1
End While
picX = R_X '还原备份
picY = R_Y '还原备份
'竖直下边
While (PicArray(picX, picY) = turn) '循环 往下面检测是否有和它相同颜色的棋子
picY += 1 '纵坐标+1 用来传给接下来的循环
count += 1 '连成的棋子个数+1
End While
If count >= 5 Then '当连成的棋子>=5
If turn = 1 Then '如果该黑棋就黑棋赢
MsgBox("黑棋" & "胜利")
Else
MsgBox("白棋" & "胜利") '如果该白棋就白棋赢
End If
End If
count = -1 '还原备份
picX = R_X
picY = R_Y
'水平左边
While (PicArray(picX, picY) = turn) '循环 往左面检测是否有和它相同颜色的棋子
picX -= 1 '横坐标-1 用来传给接下来的循环
count += 1 '连成的棋子个数+1
End While
picX = R_X '还原备份
picY = R_Y
'水平右边
While (PicArray(picX, picY) = turn) '循环 往右面检测是否有和它相同颜色的棋子
picX += 1 '横坐标+1 用来传给接下来的循环
count += 1
End While
If count >= 5 Then '同上
If turn = 1 Then
MsgBox("黑棋" & "胜利")
Else
MsgBox("白棋" & "胜利")
End If
End If
count = -1 '还原备份
picX = R_X
picY = R_Y
'左上边斜
While (PicArray(picX, picY) = turn) '循环 往左上方向检测是否有和它相同颜色的棋子
picX -= 1 '横坐标-1 用来传给接下来的循环
picY -= 1 '纵坐标-1 用来传给接下来的循环
count += 1
End While
picX = R_X
picY = R_Y
'右下边斜
While (PicArray(picX, picY) = turn) '循环 往右下方向检测是否有和它相同颜色的棋子
picX += 1 '横坐标+1 用来传给接下来的循环
picY += 1 '纵坐标+1 用来传给接下来的循环
count += 1
End While
If count >= 5 Then
If turn = 1 Then
MsgBox("黑棋" & "胜利")
Else
MsgBox("白棋" & "胜利")
End If
End If
count = -1 '还原备份
picX = R_X
picY = R_Y
'右上边斜
While (PicArray(picX, picY) = turn) '循环 往右上方向检测是否有和它相同颜色的棋子
picX += 1 '横坐标+1 用来传给接下来的循环
picY -= 1 '纵坐标-1 用来传给接下来的循环
count += 1
End While
picX = R_X
picY = R_Y
'左下边斜
While (PicArray(picX, picY) = turn) '循环 往左下方向检测是否有和它相同颜色的棋子
picX -= 1 '横坐标-1 用来传给接下来的循环
picY += 1 '纵坐标+1 用来传给接下来的循环
count += 1
End While
If count >= 5 Then
If turn = 1 Then
MsgBox("黑棋" & "胜利")
Else
MsgBox("白棋" & "胜利")
End If
End If
End Sub
End Class
2013年12月03日 13点12分
21
求问为什么点了pic之后没反应呢
2018年06月08日 08点06分