为什么我的代码不会回到主菜单?

时间:2015-10-13 14:50:12

标签: vb.net

我正在猜测VB.Net中的数字游戏。我已经到了我要问玩家是否愿意在他们赢了之后再玩的地步。当我尝试将它们发送回主菜单时,如果他们选择再次播放,则只退出该程序。

 Sub MainMenu()
        Console.WriteLine("Main Menu")
        Console.WriteLine("1) Play Game")
        Console.WriteLine("2) Instructions")
        Console.WriteLine("3) View Score")
        Console.WriteLine("4) Exit")
        Console.WriteLine()
    End Sub

If UserGuess = CorrectNumber Then 
            PlayerScore = PlayerScore + 1
            Console.WriteLine("...CORRECT!!! You win!")
            Console.WriteLine("You took " & NOfGuesses & " guesses!")
            Console.WriteLine("Press Enter to Continue")
            Console.ReadLine()
            Console.Clear()
            PlayAgainSub()
        End If

Sub PlayAgainSub()
        Dim PlayAgain As Char
        Console.Clear()
        Console.WriteLine("Would you like to play again? (Y/N)")
        PlayAgain = Console.ReadLine.ToUpper
        If PlayAgain = "Y" Then
            MainMenu()
        ElseIf PlayAgain = "N" Then
            Quit()
        Else
            Console.WriteLine("Option not valid!")
            REM Next line waits for 0.5 seconds so the user has time to see the error message.
            Threading.Thread.Sleep(500)
            Console.Clear()
            PlayAgainSub()
        End If
    End Sub

这不是所有的代码,只是我认为相关的代码,如果您需要其余的代码,我会更新帖子。

1 个答案:

答案 0 :(得分:0)

为递归示例设置变量 暗淡重现为Char 然后使用Do .. loop while