php井字游戏代码_vb井字游戏的程序怎么写

展开全部

在from中放8个command控件组成一组,再放一个command控件,名为32313133353236313431303231363533e78988e69d8331333262363134"重来",见图,复制如下代码

玩法:轮流用鼠标点击相应数字的格子,当O或X横竖斜排成一线就算赢了。

Dim ox(3, 3) As Integer

Dim condition As Integer

Dim result As Integer

Private Sub Command2_Click()

Dim i, j As Integer

result = 0: condition = 0

For i = 0 To 8

Command1(i).Caption = ""

Command1(i).Enabled = True

Next i

For i = 0 To 2

For j = 0 To 2

ox(i, j) = 0

Next j

Next i

End Sub

Private Sub Form_Load()

Dim i, j As Integer

condition = 0: result = 0

For i = 0 To 2

For j = 0 To 2

ox(i, j) = 0

Next j

Next i

End Sub

Private Sub Command1_Click(Index As Integer)

Dim i, j As Integer

Dim over As Boolean

i = Index \ 3

j = Index Mod 3

If ox(i, j) = 0 Then

If condition = 0 Then

Command1(Index).Caption = "O"

condition = 1

ox(i, j) = 1

Else

Command1(Index).Caption = "X"

condition = 0

ox(i, j) = 2

End If

Rem 判断是否连成一线

For i = 0 To 2

If ox(0, i) = 1 And ox(1, i) = 1 And ox(2, i) = 1 Then

result = 1

End If

If ox(i, 0) = 1 And ox(i, 1) = 1 And ox(i, 2) = 1 Then

result = 1

End If

If ox(0, i) = 2 And ox(1, i) = 2 And ox(2, i) = 2 Then

result = 2

End If

If ox(i, 0) = 2 And ox(i, 1) = 2 And ox(i, 2) = 2 Then

result = 2

End If

Next i

If ox(0, 0) = 1 And ox(1, 1) = 1 And ox(2, 2) = 1 Then

result = 1

End If

If ox(0, 0) = 2 And ox(1, 1) = 2 And ox(2, 2) = 2 Then

result = 2

End If

If ox(0, 2) = 1 And ox(1, 1) = 1 And ox(2, 0) = 1 Then

result = 1

End If

If ox(0, 2) = 2 And ox(1, 1) = 2 And ox(2, 0) = 2 Then

result = 2

End If

If result = 1 Then

MsgBox "O赢了"

End If

If result = 2 Then

MsgBox "X赢了"

End If

If result <> 0 Then

For i = 0 To 8

Command1(i).Enabled = False

Next i

Else

over = True

For i = 0 To 2

For j = 0 To 2

If ox(i, j) = 0 Then

over = False

End If

Next j

Next i

If over Then

MsgBox "结束"

End If

End If

End If

End Sub

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值