VB 6.0 講義  怪獸卡遊戲

project1.vbp form1.frm

 

Dim cn, ca, cd, cs, p1, p2 As Variant

Private Sub Command1_Click()
Lb1.Caption = ""
Lb2.Caption = ""

env = Int(Rnd * 3) ' 亂數選擇戰場, 並決定加或減屬性
If p1(Lt1.ListIndex) \ 4 = env Then sp1 = 1
If p1(Lt1.ListIndex) \ 4 = env + 1 Or p1(Lt1.ListIndex) \ 4 + 2 = env Then sp1 = -1
If p2(Lt2.ListIndex) \ 4 = env Then sp2 = 1
If p2(Lt2.ListIndex) \ 4 = env + 1 Or p1(Lt2.ListIndex) \ 4 + 2 = env Then sp2 = -1

If env = 0 Then str1 = "水的戰場" & Chr(13) & "(水獸+1,火獸-1)" & Chr(13)
If env = 1 Then str1 = "火的戰場" & Chr(13) & "(火獸+1,木獸-1)" & Chr(13)
If env = 2 Then str1 = "木的戰場" & Chr(13) & "(木獸+1,水獸-1)" & Chr(13)
Lb1.Caption = Lb1.Caption & str1
Lb2.Caption = Lb2.Caption & str1

If Lt1.ListIndex = 0 Then
If Lt2.ListIndex = 0 Then ' 雙方不出
Lb1.Caption = Lb1.Caption & "雙方不出,平手" & Chr(13)
Lb2.Caption = Lb2.Caption & "雙方不出,平手" & Chr(13)
Else ' 小呆不出,小笨出
Lb1.Caption = Lb1.Caption & "小呆不出,小笨出,小笨勝" & Chr(13)
Lb2.Caption = Lb2.Caption & "小呆不出,小笨出,小笨勝" & Chr(13)
Text2.Text = Text2.Text + 1
End If
Else
If Lt2.ListIndex = 0 Then ' 小笨不出,小呆出
Lb1.Caption = Lb1.Caption & "小笨不出,小呆出,小呆勝" & Chr(13)
Lb2.Caption = Lb2.Caption & "小笨不出,小呆出,小呆勝" & Chr(13)
Text1.Text = Text1.Text + 1
Else ' 雙方都有出
a = p1(Lt1.ListIndex)
b = p2(Lt2.ListIndex)
Lb1.Caption = Lb1.Caption & "小笨出" & cn(a) & " " & ca(a) + sp1 & " " & cd(a) + sp1 & " " & cs(a) + sp1 & Chr(13)
Lb1.Caption = Lb1.Caption & "小呆出" & cn(b) & " " & ca(b) + sp2 & " " & cd(b) + sp2 & " " & cs(b) + sp2 & Chr(13)
Lb2.Caption = Lb2.Caption & "小呆出" & cn(b) & " " & ca(b) + sp2 & " " & cd(b) + sp2 & " " & cs(b) + sp2 & Chr(13)
Lb2.Caption = Lb2.Caption & "小笨出" & cn(a) & " " & ca(a) + sp1 & " " & cd(a) + sp1 & " " & cs(a) + sp1 & Chr(13)
Select Case (cs(a) + sp1 - (cs(b) + sp2))
Case Is < 0: '當play 2 的 card 速度較快
Lb1.Caption = Lb1.Caption & cn(b) & "先攻" & Chr(13)
Lb2.Caption = Lb2.Caption & cn(b) & "先攻" & Chr(13)
If (ca(b) + sp2 >= cd(a) + sp1) Then '當 play2 攻破 play1
str1 = cn(b) & "攻 >= " & cn(a) & "防," & Chr(13) & cn(a) & "被消滅" & Chr(13)
Lb1.Caption = Lb1.Caption & str1
Lb2.Caption = Lb2.Caption & str1
Text2.Text = Text2.Text + 1
For i = Lt1.ListIndex To 4 '持卡向前移
p1(i) = p1(i + 1)
Next i
Lt1.RemoveItem (Lt1.ListIndex)
Lt1.ListIndex = 0
Else
If (ca(a) + sp1 >= cd(b) + sp2) Then '當 play2 攻不破 play1 , 反被 play 1 攻破
str1 = cn(b) & " 無法消滅 " & cn(a) & Chr(13) & "換" & cn(a) & "進攻" & Chr(13) & cn(a) & "攻 >= " & cn(b) & "防," & Chr(13) & cn(b) & "被消滅" & Chr(13)
Lb1.Caption = Lb1.Caption & str1
Lb2.Caption = Lb2.Caption & str1
Text1.Text = Text1.Text + 1
For i = Lt2.ListIndex + 1 To 4 '持卡向前移
p2(i) = p2(i + 1)
Next i
Lt2.RemoveItem (Lt2.ListIndex)
Lt2.ListIndex = 0
Else '當雙方均無法消滅對方
Lb1.Caption = Lb1.Caption & "雙方均無法消滅對方,平手" & Chr(13)
Lb2.Caption = Lb2.Caption & "雙方均無法消滅對方,平手" & Chr(13)
End If
End If

Case 0: '當play 1 和 2 的 card 速度一樣
Lb1.Caption = Lb1.Caption & "速度一樣,雙方同時互打" & Chr(13)
Lb2.Caption = Lb2.Caption & "速度一樣,雙方同時互打" & Chr(13)
If (ca(b) + sp2 >= cd(a) + sp1) Then '當 play2 攻破 play1
str1 = cn(b) & "攻 >= " & cn(a) & "防," & Chr(13) & cn(a) & "被消滅" & Chr(13)
Lb1.Caption = Lb1.Caption & str1
Lb2.Caption = Lb2.Caption & str1
Text2.Text = Text2.Text + 1
For i = Lt1.ListIndex To 4 '持卡向前移
p1(i) = p1(i + 1)
Next i
Lt1.RemoveItem (Lt1.ListIndex)
Lt1.ListIndex = 0
End If
If (ca(a) + sp1 >= cd(b) + sp2) Then '當 play1 攻破 play2
str1 = cn(a) & "攻 >= " & cn(b) & "防," & Chr(13) & cn(b) & "被消滅" & Chr(13)
Lb1.Caption = Lb1.Caption & str1
Lb2.Caption = Lb2.Caption & str1
Text1.Text = Text1.Text + 1
For i = Lt2.ListIndex To 4 '持卡向前移
p2(i) = p2(i + 1)
Next i
Lt2.RemoveItem (Lt2.ListIndex)
Lt2.ListIndex = 0
End If

Case Is > 0: '當play 1 的 card 速度較快
Lb1.Caption = Lb1.Caption & cn(a) & "先攻" & Chr(13)
Lb2.Caption = Lb2.Caption & cn(a) & "先攻" & Chr(13)
If (ca(a) + sp1 >= cd(b) + sp2) Then '當 play1 攻破 play2
str1 = cn(a) & "攻 >= " & cn(b) & "防," & Chr(13) & cn(b) & "被消滅" & Chr(13)
Lb1.Caption = Lb1.Caption & str1
Lb2.Caption = Lb2.Caption & str1
Text1.Text = Text1.Text + 1
For i = Lt2.ListIndex To 4 '持卡向前移
p2(i) = p2(i + 1)
Next i
Lt2.RemoveItem (Lt2.ListIndex)
Lt2.ListIndex = 0
Else
If (ca(b) + sp2 >= cd(a) + sp1) Then '當 play1 攻不破 play2 , 反被 play 2 攻破
str1 = cn(a) & " 無法消滅 " & cn(b) & Chr(13) & "換" & cn(b) & "進攻" & Chr(13) & cn(b) & "攻 >= " & cn(a) & "防," & Chr(13) & cn(a) & "被消滅" & Chr(13)
Lb1.Caption = Lb1.Caption & str1
Lb2.Caption = Lb2.Caption & str1
Text2.Text = Text2.Text + 1
For i = Lt1.ListIndex + 1 To 4 '持卡向前移
p1(i) = p1(i + 1)
Next i
Lt1.RemoveItem (Lt1.ListIndex)
Lt1.ListIndex = 0
Else '當雙方均無法消滅對方
Lb1.Caption = Lb1.Caption & "雙方均無法消滅對方,平手" & Chr(13)
Lb2.Caption = Lb2.Caption & "雙方均無法消滅對方,平手" & Chr(13)
End If
End If

End Select
End If
End If
If Text1.Text > 5 Or Lt2.ListCount = 1 Then ' 當 play 1 分數超過 5 分, 或 play 2 沒卡了
Lb1.Caption = Lb1.Caption & Chr(13) & Chr(13) & " WIN !!"
Lb2.Caption = Lb2.Caption & Chr(13) & Chr(13) & " LOSE !!"
Command1.Enabled = False
End If
If Text2.Text > 5 Or Lt1.ListCount = 1 Then ' 當 play 2 分數超過 5 分, 或 play 1 沒卡了
Lb2.Caption = Lb2.Caption & Chr(13) & Chr(13) & " WIN !!"
Lb1.Caption = Lb1.Caption & Chr(13) & Chr(13) & " LOSE !!"
Command1.Enabled = False
End If
End Sub

Private Sub Command2_Click() '結束不玩了
End
End Sub

Private Sub Command3_Click() '再玩一次
Lt1.Clear
Lt2.Clear
Lb1.Caption = ""
Lb2.Caption = ""
Text1.Text = 0
Text2.Text = 0
Command1.Enabled = True
Call Form_Load
End Sub

Private Sub Form_Load()
cn = Array("水母", "章魚", "海鯊", "巨鯨", "火炬", "火箭", "火鳳", "火龍", "木刀", "木頭人", "木馬", "巨木車")
ca = Array(3, 4, 5, 5, 2, 4, 6, 7, 3, 3, 5, 6) ' 攻擊
cd = Array(3, 4, 4, 7, 3, 3, 4, 6, 2, 4, 5, 7) ' 防禦
cs = Array(2, 2, 4, 3, 3, 4, 5, 4, 3, 3, 3, 3) ' 速度
p1 = Array(99, 99, 99, 99, 99, 99) ' play 1 手中的牌
p2 = Array(99, 99, 99, 99, 99, 99) ' play 2 手中的牌
Randomize
For i = 1 To 5 ' play 1 抽牌
p1(i) = Int(Rnd * 12)
For j = 1 To i - 1 ' 抽牌 抽中重覆的, 則重抽
If p1(i) = p1(j) Then i = i - 1
Next
Next
For i = 1 To 5 ' play 2 抽牌
p2(i) = Int(Rnd * 12)
For j = 1 To 5 ' 抽牌 抽中 play 1 重覆的, 則重抽
If p2(i) = p1(j) Then i = i - 1
Next
For j = 1 To i - 1 ' 抽牌 抽中 play 2 重覆的, 則重抽
If p2(i) = p2(j) Then i = i - 1
Next
Next
Lt1.AddItem ("不出")
Lt2.AddItem ("不出")


For i = 1 To 5 ' 加入清單方塊中
Lt1.AddItem (cn(p1(i)) & " " & ca(p1(i)) & " " & cd(p1(i)) & " " & cs(p1(i)))
Lt2.AddItem (cn(p2(i)) & " " & ca(p2(i)) & " " & cd(p2(i)) & " " & cs(p2(i)))
Next
Lt1.ListIndex = 0 ' 預選為 不出牌
Lt2.ListIndex = 0 ' 預選為 不出牌
End Sub