如何从一组2个单词中随机选择一个单词并显示它



这是一个控制台应用

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

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

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

像这样

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

最新更新