0

这是一个控制台应用程序

我如何随机显示文本但我已放入程序中的文本?

示例:我正在制作正面或反面游戏。我想让它让你输入你的选择(正面/反面),它随机显示“正面”或“反面”,在下一行,它会根据比赛显示“你赢”或“你输”。

我只是不知道如何让它从程序中随机选择文本并显示它。

4

1 回答 1

1

像这样的东西

Dim prng As New Random
Dim done As Boolean = False

Sub Main()
    Do
        Dim toss As Integer = prng.Next(2) '0=heads, 1=tails
        Console.WriteLine(Environment.NewLine & "Enter (h)eads, (t)ails, or e(x)it")
        Dim inp As String = Console.ReadLine.ToLower
        Dim choice As Integer
        Select Case inp
            Case "h", "head", "heads"
                choice = 0
            Case "t", "tail", "tails"
                choice = 1
            Case "x", "exit"
                choice = -1
                done = True
            Case Else
                choice = 2 'input error
        End Select
        If choice = toss Then
            Console.WriteLine("Winner, winner, chicken dinner!")
        ElseIf choice = 2 Then
            Console.WriteLine("Input error, try again")
        ElseIf choice = -1 Then
            'exit
        Else
            Console.WriteLine("You lose")
        End If
    Loop While Not done
End Sub
于 2013-06-02T16:38:11.820 回答