本文介绍了C#程序赌场大战的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮助我将此伪代码转换为VB 2005的C#吗?

Can anyone help me convert this pseudo code into C# for VB 2005 ?

Start Main( )
	Get name of player
	Get cash (starting cash amout)
	Set more = "yes"
	Start Loop
		Set betAmount = 0;
		Start Loop
Get betAmount
If( betAmount > cash )
	Display "You do not have enough cash for that bet amount."
Display "Cash: " & cash
			End If
While( betAmount > cash ), continue looping
		Display "Press Enter to draw a card."
		Generate a random number from 2 to 14 and place in player variable
		Call DisplayCard( player )
		Display "Press Enter to see the dealer’s card."
		Create a random number between 2 and 14 and place in dealer variable
		Call DisplayCard( dealer )
		Call Evaluate( player, dealer ) that returns a boolean (true if player wins)
		If player wins then
			Display name & ", you win!"
			Increase cash by the betAmount
		Otherwise
			Display name & ", you lose"
			Decrease cash by the betAmount
		End If
		If cash > 0 then
Display "You have " & cash & " cash in hand."
			Get more with prompt "Play again? (yes/no): "
		Otherwise
			Display "You are out of cash."
			Set more = "no"
		End If
	While more = "yes", continue looping
	Display "Thanks for playing."
Stop


Start DisplayCard( card as integer )
	If card = 14 then
		Display "Ace"
	Otherwise if card = 13 then
		Display "King"
	Otherwise if card = 12 then
		Display "Queen"
	Otherwise if card = 11 then
		Display "Jack"
	Otherwise if card >= 2 AND card <= 10 then
		Display card
	Otherwise
		Display "Error: " & card & "is not valid."
	End If
Stop


Start Evaluate( player, dealer )
	If player > dealer then
		Return true
	Otherwise if dealer > player then
		Return false
	Otherwise
		Display "Tie.  We go to WAR!"
		Display "Press Enter to draw a card."
		Generate a random number between 2 and 14 and place in player variable
		Call DisplayCard( player )
		Display "Press Enter to see the dealer’s card."
		Create a random number between 2 and 14 and place in dealer variable
		Call DisplayCard( dealer )
		Return result of Evaluate( player, dealer ) –recursion will continue until someone wins
	End If	
Stop

推荐答案



这篇关于C#程序赌场大战的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 08:58