|
|
|
ช่วยด้วยครับ รบกวนช่วยอธิบายให้หน่อยครับ เกมส์ OX VB ครับ |
|
|
|
|
|
|
|
Code (VB 6)
Dim b1, b2, b3, b4, b5, b6, b7, b8, b9 As Integer
Dim result As String
Sub checkO()
If Command1.Caption = "O" And Command2.Caption = "O" And Command3.Caption = "O" Then
Label1.Caption = "ผู้เล่นที่ 2 ชนะ"
Option1.Enabled = False
Command4.Enabled = False
Command5.Enabled = False
Command6.Enabled = False
Command7.Enabled = False
Command8.Enabled = False
Command9.Enabled = False
ElseIf Command4.Caption = "O" And Command5.Caption = "O" And Command6.Caption = "O" Then
Label1.Caption = "ผู้เล่นที่ 2 ชนะ"
Option1.Enabled = False
Command1.Enabled = False
Command2.Enabled = False
Command3.Enabled = False
Command7.Enabled = False
Command8.Enabled = False
Command9.Enabled = False
ElseIf Command7.Caption = "O" And Command8.Caption = "O" And Command9.Caption = "O" Then
Label1.Caption = "ผู้เล่นที่ 2 ชนะ"
Option1.Enabled = False
Command1.Enabled = False
Command2.Enabled = False
Command3.Enabled = False
Command4.Enabled = False
Command5.Enabled = False
Command6.Enabled = False
ElseIf Command1.Caption = "O" And Command4.Caption = "O" And Command7.Caption = "O" Then
Label1.Caption = "ผู้เล่นที่ 2 ชนะ"
Option1.Enabled = False
Command2.Enabled = False
Command3.Enabled = False
Command5.Enabled = False
Command6.Enabled = False
Command8.Enabled = False
Command9.Enabled = False
ElseIf Command2.Caption = "O" And Command5.Caption = "O" And Command8.Caption = "O" Then
Label1.Caption = "ผู้เล่นที่ 2 ชนะ"
Option1.Enabled = False
Command1.Enabled = False
Command3.Enabled = False
Command4.Enabled = False
Command6.Enabled = False
Command7.Enabled = False
Command9.Enabled = False
ElseIf Command3.Caption = "O" And Command6.Caption = "O" And Command9.Caption = "O" Then
Label1.Caption = "ผู้เล่นที่ 2 ชนะ"
Option1.Enabled = False
Command1.Enabled = False
Command2.Enabled = False
Command4.Enabled = False
Command5.Enabled = False
Command7.Enabled = False
Command8.Enabled = False
ElseIf Command1.Caption = "O" And Command5.Caption = "O" And Command9.Caption = "O" Then
Label1.Caption = "ผู้เล่นที่ 2 ชนะ"
Option1.Enabled = False
Command2.Enabled = False
Command3.Enabled = False
Command4.Enabled = False
Command6.Enabled = False
Command7.Enabled = False
Command8.Enabled = False
ElseIf Command3.Caption = "O" And Command5.Caption = "O" And Command7.Caption = "O" Then
Label1.Caption = "ผู้เล่นที่ 2 ชนะ"
Option1.Enabled = False
Command1.Enabled = False
Command2.Enabled = False
Command4.Enabled = False
Command6.Enabled = False
Command8.Enabled = False
Command9.Enabled = False
End If
End Sub
Sub checkX()
If Command1.Caption = "X" And Command2.Caption = "X" And Command3.Caption = "X" Then
Label1.Caption = "ผู้เล่นที่ 1 ชนะ"
Option2.Enabled = False
Command4.Enabled = False
Command5.Enabled = False
Command6.Enabled = False
Command7.Enabled = False
Command8.Enabled = False
Command9.Enabled = False
ElseIf Command4.Caption = "X" And Command5.Caption = "X" And Command6.Caption = "X" Then
Label1.Caption = "ผู้เล่นที่ 1 ชนะ"
Option2.Enabled = False
Command1.Enabled = False
Command2.Enabled = False
Command3.Enabled = False
Command7.Enabled = False
Command8.Enabled = False
Command9.Enabled = False
ElseIf Command7.Caption = "X" And Command8.Caption = "X" And Command9.Caption = "X" Then
Label1.Caption = "ผู้เล่นที่ 1 ชนะ"
Option2.Enabled = False
Command1.Enabled = False
Command2.Enabled = False
Command3.Enabled = False
Command4.Enabled = False
Command5.Enabled = False
Command6.Enabled = False
ElseIf Command1.Caption = "X" And Command4.Caption = "X" And Command7.Caption = "X" Then
Label1.Caption = "ผู้เล่นที่ 1 ชนะ"
Option2.Enabled = False
Command2.Enabled = False
Command3.Enabled = False
Command5.Enabled = False
Command6.Enabled = False
Command8.Enabled = False
Command9.Enabled = False
ElseIf Command2.Caption = "X" And Command5.Caption = "X" And Command8.Caption = "X" Then
Label1.Caption = "ผู้เล่นที่ 1 ชนะ"
Option2.Enabled = False
Command1.Enabled = False
Command3.Enabled = False
Command4.Enabled = False
Command6.Enabled = False
Command7.Enabled = False
Command9.Enabled = False
ElseIf Command3.Caption = "X" And Command6.Caption = "X" And Command9.Caption = "X" Then
Label1.Caption = "ผู้เล่นที่ 1 ชนะ"
Option2.Enabled = False
Command1.Enabled = False
Command2.Enabled = False
Command4.Enabled = False
Command5.Enabled = False
Command7.Enabled = False
Command8.Enabled = False
ElseIf Command1.Caption = "X" And Command5.Caption = "X" And Command9.Caption = "X" Then
Label1.Caption = "ผู้เล่นที่ 1 ชนะ"
Option2.Enabled = False
Command2.Enabled = False
Command3.Enabled = False
Command4.Enabled = False
Command6.Enabled = False
Command7.Enabled = False
Command8.Enabled = False
ElseIf Command3.Caption = "X" And Command5.Caption = "X" And Command7.Caption = "X" Then
Label1.Caption = "ผู้เล่นที่ 1 ชนะ"
Option2.Enabled = False
Command1.Enabled = False
Command2.Enabled = False
Command4.Enabled = False
Command6.Enabled = False
Command8.Enabled = False
Command9.Enabled = False
End If
End Sub
Sub checkdraw()
If Command1.Caption <> "" And Command2.Caption <> "" And Command3.Caption <> "" And Command4.Caption <> "" And Command5.Caption <> "" And Command6.Caption <> "" And Command7.Caption <> "" And Command8.Caption <> "" And Command9.Caption <> "" And Label1.Caption = "" Then
Label1.Caption = "เสมอกัน"
Command1.Enabled = False
Command2.Enabled = False
Command3.Enabled = False
Command4.Enabled = False
Command5.Enabled = False
Command6.Enabled = False
Command7.Enabled = False
Command8.Enabled = False
Command9.Enabled = False
result = Label1.Caption
End If
End Sub
Private Sub Command1_Click()
If b1 = 0 Then
If Option1 = True Then
Command1.Caption = "X"
Option2 = True
Option1.Enabled = False
Option2.Enabled = True
Else
Command1.Caption = "O"
Option1 = True
Option2.Enabled = False
Option1.Enabled = True
End If
checkO
checkX
checkdraw
b1 = b1 + 1
result = Label1.Caption
Else
MsgBox "ช่องนี้ได้มีการกาไปเรียบร้อยแล้วครับ", vbCritical, "ผิดพลาด"
End If
End Sub
Private Sub Command2_Click()
If b2 = 0 Then
If Option1 = True Then
Command2.Caption = "X"
Option2 = True
Option1.Enabled = False
Option2.Enabled = True
Else
Command2.Caption = "O"
Option1 = True
Option2.Enabled = False
Option1.Enabled = True
End If
checkO
checkX
checkdraw
b2 = b2 + 1
result = Label1.Caption
Else
MsgBox "ช่องนี้ได้มีการกาไปเรียบร้อยแล้วครับ", vbCritical, "ผิดพลาด"
End If
End Sub
Private Sub Command3_Click()
If b3 = 0 Then
If Option1 = True Then
Command3.Caption = "X"
Option2 = True
Option1.Enabled = False
Option2.Enabled = True
Else
Command3.Caption = "O"
Option1 = True
Option2.Enabled = False
Option1.Enabled = True
End If
checkO
checkX
checkdraw
b3 = b3 + 1
result = Label1.Caption
Else
MsgBox "ช่องนี้ได้มีการกาไปเรียบร้อยแล้วครับ", vbCritical, "ผิดพลาด"
End If
End Sub
Private Sub Command4_Click()
If b4 = 0 Then
If Option1 = True Then
Command4.Caption = "X"
Option2 = True
Option1.Enabled = False
Option2.Enabled = True
Else
Command4.Caption = "O"
Option1 = True
Option2.Enabled = False
Option1.Enabled = True
End If
checkO
checkX
checkdraw
b4 = b4 + 1
result = Label1.Caption
Else
MsgBox "ช่องนี้ได้มีการกาไปเรียบร้อยแล้วครับ", vbCritical, "ผิดพลาด"
End If
End Sub
Private Sub Command5_Click()
If b5 = 0 Then
If Option1 = True Then
Command5.Caption = "X"
Option2 = True
Option1.Enabled = False
Option2.Enabled = True
Else
Command5.Caption = "O"
Option1 = True
Option2.Enabled = False
Option1.Enabled = True
End If
checkO
checkX
checkdraw
b5 = b5 + 1
result = Label1.Caption
Else
MsgBox "ช่องนี้ได้มีการกาไปเรียบร้อยแล้วครับ", vbCritical, "ผิดพลาด"
End If
End Sub
Private Sub Command6_Click()
If b6 = 0 Then
If Option1 = True Then
Command6.Caption = "X"
Option2 = True
Option1.Enabled = False
Option2.Enabled = True
Else
Command6.Caption = "O"
Option1 = True
Option2.Enabled = False
Option1.Enabled = True
End If
checkO
checkX
checkdraw
b6 = b6 + 1
result = Label1.Caption
Else
MsgBox "ช่องนี้ได้มีการกาไปเรียบร้อยแล้วครับ", vbCritical, "ผิดพลาด"
End If
End Sub
Private Sub Command7_Click()
If b7 = 0 Then
If Option1 = True Then
Command7.Caption = "X"
Option2 = True
Option1.Enabled = False
Option2.Enabled = True
Else
Command7.Caption = "O"
Option1 = True
Option2.Enabled = False
Option1.Enabled = True
End If
checkO
checkX
checkdraw
b7 = b7 + 1
result = Label1.Caption
Else
MsgBox "ช่องนี้ได้มีการกาไปเรียบร้อยแล้วครับ", vbCritical, "ผิดพลาด"
End If
End Sub
Private Sub Command8_Click()
If b8 = 0 Then
If Option1 = True Then
Command8.Caption = "X"
Option2 = True
Option1.Enabled = False
Option2.Enabled = True
Else
Command8.Caption = "O"
Option1 = True
Option2.Enabled = False
Option1.Enabled = True
End If
checkO
checkX
checkdraw
b8 = b8 + 1
result = Label1.Caption
Else
MsgBox "ช่องนี้ได้มีการกาไปเรียบร้อยแล้วครับ", vbCritical, "ผิดพลาด"
End If
End Sub
Private Sub Command9_Click()
If b9 = 0 Then
If Option1 = True Then
Command9.Caption = "X"
Option2 = True
Option1.Enabled = False
Option2.Enabled = True
Else
Command9.Caption = "O"
Option1 = True
Option2.Enabled = False
Option1.Enabled = True
End If
checkO
checkX
checkdraw
b9 = b9 + 1
result = Label1.Caption
Else
MsgBox "ช่องนี้ได้มีการกาไปเรียบร้อยแล้วครับ", vbCritical, "ผิดพลาด"
End If
End Sub
Private Sub Form_Load()
Option1 = True
Option2.Enabled = False
End Sub
Private Sub mmabout_Click(Index As Integer)
MsgBox "เกม XO เวอร์ชั่น 1.0 โดย ด.ช.ศิลป์ สัจจะวัฒนวิมล", vbInformation, "เกี่ยวกับ"
End Sub
Private Sub mmexit_Click(Index As Integer)
Dim answer As Integer
answer = MsgBox("คุณแน่ใจหรือว่าต้องการจะออกจากโปรแกรม ?", vbQuestion + vbOKCancel, "ออกจากโปรแกรม")
If answer = 1 Then
End
End If
End Sub
Private Sub mmlastscore_Click(Index As Integer)
If result <> "" Then
MsgBox "ในรอบที่ผ่านมา" + " " + result + " " + "ครับ", vbInformation, "ผลในรอบที่ผ่านมา"
Else
MsgBox "ยังไม่มีการเริ่มเล่นเกมครับ", vbInformation, "ผลในรอบที่ผ่านมา"
End If
End Sub
Private Sub mmnew_Click(Index As Integer)
Command1.Caption = ""
Command2.Caption = ""
Command3.Caption = ""
Command4.Caption = ""
Command5.Caption = ""
Command6.Caption = ""
Command7.Caption = ""
Command8.Caption = ""
Command9.Caption = ""
Label1.Caption = ""
Option1.Enabled = True
Option2.Enabled = False
Option1 = True
b1 = 0
b2 = 0
b3 = 0
b4 = 0
b5 = 0
b6 = 0
b7 = 0
b8 = 0
b9 = 0
Command1.Enabled = True
Command2.Enabled = True
Command3.Enabled = True
Command4.Enabled = True
Command5.Enabled = True
Command6.Enabled = True
Command7.Enabled = True
Command8.Enabled = True
Command9.Enabled = True
End Sub
กรุณาช่วยอธิบายหลักการ การทำงานของโค้ดแต่ล่ะบรรทัดให้ผมหน่อยครับ
ต้องการด่วนเลยครับ ถ้าไม่ได้ล่ะแย่แน่เลยครับ ต้องออกไปนำเสนอด้วย อิอิ
ช่วยหน่อยนะครับ
ขอบคุณโค้ดจาก http://www.vcharkarn.com/vcafe/34481
Tag : VBScript
|
ประวัติการแก้ไข 2011-08-10 21:01:47
|
|
|
|
|
Date :
2011-08-10 20:54:24 |
By :
dragon_ball_king |
View :
4071 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
....
|
ประวัติการแก้ไข 2011-08-10 21:01:08
|
|
|
|
Date :
2011-08-10 21:00:27 |
By :
dragon_ball_king |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
จะไหวเหรอครับ หลายบรรทัดน่ะครับ
|
|
|
|
|
Date :
2011-08-10 23:05:10 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณครับ ไม่เอาแล้วครับ เพื่อนผมเอาไปล่ะ ฮ่าๆๆๆ
หาใหม่ๆ
ใครพอมีโค้ดเกมส์ที่เป็น AI บ้างครับที่คล้ายๆกับตัวอย่างข้างต้น บ้างครับ ผมขอได้มั้ย อิอิ ส่งวันจันทร์แล้วซะด้วย ง่าๆๆ
|
|
|
|
|
Date :
2011-08-11 18:25:35 |
By :
dragon_ball_king |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|