[英]How to select a word from a set of 2 randomly and display it?
THIS IS A CONSOLE APPLICATION 这是一个控制台应用程序
How do I display text randomly but that of which I have put into the program? 如何随机显示文本,但我已将其显示在程序中?
Example: I am making a heads or tails game. 示例:我正在制作正面或反面游戏。 I want to make it so you input your choice (Heads/Tails), and it randomly says "Heads" or "Tails", and on the next line, it says "You win" or "You lose" based on the match. 我要这样做,以便您输入选择(正面/反面),然后随机说“正面”或“反面”,并在下一行根据匹配结果说“您赢了”或“您输了”。
I just don't know how to make it select text from the program at random and display it. 我只是不知道如何使它从程序中随机选择文本并显示它。
Something like this 像这样
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.