发信人: tonycl(凉风月亮)
整理人: winsy(2004-06-21 09:46:01), 站内信件
|
form1:
VERSION 5.00
Begin VB.Form Form1
BorderStyle = 1 'Fixed Single
Caption = "井字游戏"
ClientHeight = 3915
ClientLeft = 150
ClientTop = 540
ClientWidth = 3510
Icon = "Form1.frx":0000
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 3915
ScaleWidth = 3510
StartUpPosition = 2 '屏幕中心
Begin VB.CommandButton Command2
Caption = "玩家对战(&P)"
Height = 1455
Left = 120
TabIndex = 12
Top = 2280
Width = 3255
End
Begin VB.CommandButton Comp
Caption = "对电脑(&C)"
Height = 1455
Left = 120
TabIndex = 11
Top = 840
Width = 3255
End
Begin VB.CommandButton Retry
Caption = "再来(&R)"
Height = 375
Left = 1080
TabIndex = 10
Top = 3480
Visible = 0 'False
Width = 1215
End
Begin VB.CommandButton Command1
Caption = "33"
Height = 975
Index = 33
Left = 2280
TabIndex = 8
Top = 2760
Width = 1095
End
Begin VB.CommandButton Command1
Caption = "32"
Height = 975
Index = 32
Left = 1200
TabIndex = 7
Top = 2760
Width = 1095
End
Begin VB.CommandButton Command1
Caption = "31"
Height = 975
Index = 31
Left = 120
TabIndex = 6
Top = 2760
Width = 1095
End
Begin VB.CommandButton Command1
Caption = "23"
Height = 975
Index = 23
Left = 2280
TabIndex = 5
Top = 1800
Width = 1095
End
Begin VB.CommandButton Command1
Caption = "22"
Height = 975
Index = 22
Left = 1200
TabIndex = 4
Top = 1800
Width = 1095
End
Begin VB.CommandButton Command1
Caption = "21"
Height = 975
Index = 21
Left = 120
TabIndex = 3
Top = 1800
Width = 1095
End
Begin VB.CommandButton Command1
Caption = "13"
Height = 975
Index = 13
Left = 2280
TabIndex = 2
Top = 840
Width = 1095
End
Begin VB.CommandButton Command1
Caption = "12"
Height = 975
Index = 12
Left = 1200
TabIndex = 1
Top = 840
Width = 1095
End
Begin VB.CommandButton Command1
Caption = "11"
Height = 975
Index = 11
Left = 120
TabIndex = 0
Top = 840
Width = 1095
End
Begin VB.Label Lab1
Caption = "请选择:"
BeginProperty Font
Name = "宋体"
Size = 26.25
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 735
Left = 120
TabIndex = 9
Top = 120
Width = 3135
End
Begin VB.Menu MnuFile
Caption = "文件(&F)"
Begin VB.Menu MnuC
Caption = "对电脑(&C)"
End
Begin VB.Menu MnuP
Caption = "对玩家(&P)"
End
Begin VB.Menu MnuL1
Caption = "-"
End
Begin VB.Menu MnuExit
Caption = "退出(&X)"
End
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim Player As Integer
Dim A(1 To 3, 1 To 3) As Boolean
Dim B(1 To 3, 1 To 3) As Integer
Dim Counter As Integer
Dim Winner As Integer
Dim Computer As Boolean
Private Sub Command1_Click(Index As Integer)
Comp.Visible = False
X = Index \ 10
Y = Index - X * 10
If Not Winner = 0 Then Beep: Exit Sub
If A(X, Y) = False Then
A(X, Y) = True
Else
'Beep
Exit Sub
End If
Counter = Counter + 1
If Player = 1 Then
Command1(Index).Caption = "O"
B(X, Y) = 1
Player = 2
If Not Computer Then Lab1.Caption = "玩家" & Player
Chck
If Computer Then Call CompWork
Else
Command1(Index).Caption = "X"
B(X, Y) = 2
Player = 1
If Not Computer Then Lab1.Caption = "玩家" & Player
Chck
End If
'Command1(Index).Enabled = False
If Counter = 9 And Winner = 0 Then
Winner = 3
Lab1.Caption = "平局!! :("
Beep
Retry.Visible = True
For i = 1 To 3
For j = 1 To 3
Command1(i * 10 + j).Enabled = False
Next
Next
End If
End Sub
Private Sub CompWork()
Randomize (Timer)
If Not Winner = 0 Then Exit Sub
Do Until Player = 1
If Not Winner = 0 Then Exit Sub
i = Int((3 * Rnd) + 1)
j = Int((3 * Rnd) + 1)
Call Command1_Click(i * 10 + j)
If Counter = 9 And Winner = 0 Then
Winner = 3
Lab1.Caption = "平局!! :("
Beep
Retry.Visible = True
For i = 1 To 3
For j = 1 To 3
Command1(i * 10 + j).Enabled = False
Next
Next
End If
Loop
End Sub
Private Sub Command2_Click()
MnuP.Enabled = False
MnuC.Enabled = True
Me.Caption = "玩家对战"
Computer = False
Command2.Visible = False
Comp.Visible = False
Lab1.Caption = "玩家1"
End Sub
Private Sub Comp_Click()
MnuC.Enabled = False
MnuP.Enabled = True
Me.Caption = "无逻辑电脑"
Computer = True
Command2.Visible = False
Comp.Visible = False
Lab1.Caption = "对电脑"
End Sub
Private Sub Form_Load()
Counter = 0
Winner = 0
Player = 1
For i = 1 To 3
For j = 1 To 3
A(i, j) = False
Command1(i * 10 + j).Enabled = True
Command1(i * 10 + j).Caption = ""
B(i, j) = i * 10 + j
Next
Next
Retry.Visible = False
End Sub
Private Sub Chck()
If Not Winer = 0 Then Exit Sub
If B(1, 1) = B(1, 2) And B(1, 1) = B(1, 3) Then Win
If B(1, 1) = B(2, 2) And B(1, 1) = B(3, 3) Then Win
If B(1, 1) = B(2, 1) And B(1, 1) = B(3, 1) Then Win
If B(1, 2) = B(2, 2) And B(1, 2) = B(3, 2) Then Win
If B(1, 3) = B(2, 3) And B(1, 3) = B(3, 3) Then Win
If B(2, 1) = B(2, 2) And B(2, 1) = B(2, 3) Then Win
If B(3, 1) = B(3, 2) And B(3, 1) = B(3, 3) Then Win
If B(3, 1) = B(2, 2) And B(3, 1) = B(1, 3) Then Win
End Sub
Private Sub Win()
If Not Winner = 0 Then Exit Sub
Winner = -Player + 3
'If Winner = 2 And Computer Then Winner = "-电脑-"
If Computer Then
If Winner = 1 Then
Lab1.Caption = "你赢了!! :)"
MsgBox "你赢了!! :)", vbOKOnly, "win"
Else
Lab1.Caption = "你输了!! :("
MsgBox "你输了!! :(", vbOKOnly, "win"
End If
Else
Lab1.Caption = "玩家" & Winner & "赢了!!"
MsgBox "玩家" & Winner & "赢了!!", vbOKOnly, "win"
End If
Retry.Visible = True
For i = 1 To 3
For j = 1 To 3
Command1(i * 10 + j).Enabled = False
Next
Next
End Sub
Private Sub MnuC_Click()
Call Comp_Click
Call Form_Load
End Sub
Private Sub MnuExit_Click()
End
End Sub
Private Sub MnuP_Click()
Call Command2_Click
Call Form_Load
End Sub
Private Sub Retry_Click()
If Not Computer Then Lab1.Caption = "玩家1" Else Lab1.Caption = "对电脑"
Form_Load
End Sub

----
宣传大使 No.100
          |
|