C#赌场计划作业
下面列出的是我的程序。我应该拿两张牌,一张是庄家牌,另一张是玩家牌,然后评估谁的牌高。玩家用一定数量的现金下注,当然,如果他赢了,他就赢了,如果他输了,他就输了。我似乎正确地遵循了伪代码,但我不断收到错误。有人想告诉我我做错了什么吗?请并感谢您的回复。错误后面跟着代码C#赌场计划作业,c#,C#,下面列出的是我的程序。我应该拿两张牌,一张是庄家牌,另一张是玩家牌,然后评估谁的牌高。玩家用一定数量的现金下注,当然,如果他赢了,他就赢了,如果他输了,他就输了。我似乎正确地遵循了伪代码,但我不断收到错误。有人想告诉我我做错了什么吗?请并感谢您的回复。错误后面跟着代码 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Casino_War { c
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Casino_War
{
class Program
{
static void Main(string[] args)
{
string playerName;
double cash, betAmount;
int player, dealer;
Console.Write("Please Enter Player's Name: ");
playerName = Console.ReadLine();
Console.WriteLine("Please Enter {0}'s Cash Amount", playerName);
cash = double.Parse(Console.ReadLine());
Boolean more = "yes";
do
{
betAmount = 0;
Console.WriteLine("Please Enter The Bet Amount: ");
betAmount = double.Parse(Console.ReadLine());
if (betAmount > cash)
{
Console.WriteLine("You Do Not Have Enough Cash For That Bet Amount.");
Console.WriteLine("Cash: {0:C}", cash);
}
while (betAmount > cash)
{
Console.WriteLine("Press Enter To Draw A Card.");
Console.ReadKey();
Random r = new Random();
player = r.Next(1, 15);
DisplayCard(player, "Player");
Console.WriteLine("Press Enter To Draw A Dealer Card.");
Console.ReadKey();
Random r = new Random();
dealer = r.Next(1, 15);
DisplayCard(dealer, "Dealer");
}
private static void EvaluateCash(ref double betAmount, double cash, Boolean winner, string playerName)
{
if (winner)
{
Console.WriteLine("{0} You Won {1:C}!", playerName, betAmount);
cash = betAmount + cash;
}
else
{
Console.WriteLine("{0} You Lose {1:C}!", playerName, betAmount);
cash = cash - betAmount;
}
Console.WriteLine("You Now Have {0:C}", cash);
}
private static Boolean PlayAgain(double cash, double betAmount, string playerName, Boolean more)
{
if (cash > 0)
{
Console.WriteLine("You Have {0} Cash In Hand.", cash);
Console.WriteLine("\nPlay Again (Y/N)? ");
more = Console.ReadLine().ToUpper();
Console.WriteLine("\n\n");
}
while (more == "Y");
Console.WriteLine("Thanks For Playing!");
}
public static void DisplayCard(int card)
{
int card = r.Next(2, 14);
if (card == 14)
Console.WriteLine("Ace");
else if (card == 13)
Console.WriteLine("King");
else if (card == 12)
Console.WriteLine("Queen");
else if (card == 11)
Console.WriteLine("Jack");
else if (card >= 2 && card <= 10)
return card;
else
Console.WriteLine("Error: {0} Is Not Valid.", card);
return card;
}
static void Evaluate(int player, int dealer)
{
if (player > dealer)
winner = true;
else if (dealer > player)
winner = false;
else
Console.WriteLine("Tie. We Go To WAR!");
Console.WriteLine("Press Enter To Draw A Card.");
Console.ReadKey();
Random r = new Random();
player = r.Next(1, 15);
DisplayCard(player, "Player");
Console.WriteLine("Press Enter To Draw A Dealer Card.");
Console.ReadKey();
Random r = new Random();
dealer = r.Next(1, 15);
DisplayCard(dealer, "Dealer");
return Evaluate(player, dealer);
}
}
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
战争的名称空间
{
班级计划
{
静态void Main(字符串[]参数)
{
弦乐演奏者姓名;
双倍现金,双倍金额;
国际球员,经销商;
控制台。写(“请输入玩家姓名:”);
playerName=Console.ReadLine();
WriteLine(“请输入{0}的现金金额”,playerName);
cash=double.Parse(Console.ReadLine());
布尔more=“是”;
做
{
betAmount=0;
Console.WriteLine(“请输入下注金额:”);
betAmount=double.Parse(Console.ReadLine());
如果(金额>现金)
{
WriteLine(“您没有足够的现金支付该赌注金额。”);
Console.WriteLine(“现金:{0:C}”,现金);
}
同时(金额>现金)
{
控制台。WriteLine(“按Enter键抽卡”);
Console.ReadKey();
随机r=新随机();
player=r.Next(1,15);
显示卡(玩家,“玩家”);
控制台。WriteLine(“按Enter键绘制经销商卡”);
Console.ReadKey();
随机r=新随机();
经销商=r.Next(1,15);
显示卡(经销商,“经销商”);
}
私有静态void EvaluateCash(参考double betAmount、double cash、Boolean winner、string playerName)
{
国际单项体育联合会(优胜者)
{
WriteLine(“{0}你赢了{1:C}!”,playerName,betAmount);
现金=金额+现金;
}
其他的
{
WriteLine(“{0}你失去了{1:C}!”,playerName,betAmount);
现金=现金-金额;
}
WriteLine(“您现在有{0:C}”,现金);
}
私有静态布尔值播放(双现金、双betAmount、字符串播放名称、布尔值更多)
{
如果(现金>0)
{
WriteLine(“您手头有{0}个现金。”,Cash);
Console.WriteLine(“\N再次显示(Y/N)?”;
more=Console.ReadLine().ToUpper();
Console.WriteLine(“\n\n”);
}
而(more="Y);;
Console.WriteLine(“谢谢玩!”);
}
公共静态无效显示卡(int卡)
{
int card=r.Next(2,14);
如果(卡==14)
控制台写入线(“Ace”);
否则,如果(卡==13)
控制台。书写线(“国王”);
否则,如果(卡==12)
控制台。WriteLine(“女王”);
否则,如果(卡==11)
控制台。写线(“杰克”);
否则如果(卡>=2和卡经销商)
胜利者=真;
否则如果(经销商>玩家)
胜利者=假;
其他的
Console.WriteLine(“领带,我们去打仗!”);
控制台。WriteLine(“按Enter键抽卡”);
Console.ReadKey();
随机r=新随机();
player=r.Next(1,15);
显示卡(玩家,“玩家”);
控制台。WriteLine(“按Enter键绘制经销商卡”);
Console.ReadKey();
随机r=新随机();
经销商=r.Next(1,15);
显示卡(经销商,“经销商”);
返回评估(玩家、经销商);
}
}
}
我将您的代码复制并粘贴到Visual Studio中 在担心{括号语法错误之前,您需要考虑并修复:
- 布尔more=“是”;(没有意义)
- Random r=新的Random();(已定义)
- 返回DisplayCard()中的卡片,因为它是一个void函数
- 在Evaluate()中定义赢家
CTRL-k CTRL-d
你可以让Visual Studio正确缩进你的整个文件-至少在没有语法错误的情况下。因此,在将来经常使用此功能;尤其是在与他人共享代码之前,因为这样可以更轻松地阅读你的代码。感谢提示。我真的不知道。感谢大家迄今为止的帮助。我确实看到了一些我做过的蠢事ning random两次。Boolean more应该读为true,没有引号,而不是yes。我想我被psuedocode和我的教授自己所做的事情缠住了,并试图将两者结合起来。我将尝试逐行编写,然后从那里开始。至于我的循环语句,它们还好吗?当然,没问题。如果你我相信你的问题已经解决了