打印本文 打印本文 关闭窗口 关闭窗口
举例通过VB编写猜拳游戏来讲述条件语句
作者:武汉SEO闵涛  文章来源:敏韬网  点击数3520  更新时间:2009/4/23 15:03:57  文章录入:mintao  责任编辑:mintao
''''剪刀'''' 电脑赢"

            Own = Own + 1

        End If

    Else ''''guess=""

        If playerGuess = "Rock" Then

            TitleLabel.Caption = "玩家出''''石头'''' 电脑出'''''''' 电脑赢"

            Own = Own + 1

        ElseIf playerGuess = "Forfex" Then

            TitleLabel.Caption = "玩家出''''剪刀'''' 电脑出'''''''' 玩家赢"

            Win = Win + 1

        Else ''''playerGuess="Cloth"

            TitleLabel.Caption = "玩家出'''''''' 电脑出'''''''' 双方平"

            Draw = Draw + 1

        End If

    End If

    ResultLabel.Caption = "赢:" & Win & "" & "平:" & Draw & "" & "负:" & Own & ""

 

同时我们统计赢,平,负的场数。

 

整个程序设计:

程序界面设计

程序源代码:

Private playerGuess As String

Private randGuess() As String

Private Win As Single

Private Own As Single

Private Draw As Single

 

Private Sub ClothCommand_Click()

    playerGuess = "Cloth"

    GuessTimer.Enabled = True

    TitleLabel.Caption = "玩家准备出''''''''"

End Sub

 

Private Sub ForfexCommand_Click()

    playerGuess = "Forfex"

    GuessTimer.Enabled = True

    TitleLabel.Caption = "玩家准备出''''剪刀''''"

End Sub

 

Private Sub Form_Load()

    ReDim randGuess(3)

    randGuess(1) = "石头"

    randGuess(2) = "剪刀"

    randGuess(3) = ""

    ResultLabel.Caption = "赢:" & Win & "" & "平:" & Draw & "" & "负:" & Own & ""

   

    Dim sum As Single

    sum = 0

    For i = 1 To 12

上一页  [1] [2] [3] [4]  下一页

打印本文 打印本文 关闭窗口 关闭窗口