这是我的代码:
using System.Reflection.Metadata.Ecma335;
Random random = new Random();
List<string> deck = new List<string>()
{
//club
"┌─────────┐\r\n│A │\r\n│ │\r\n│ │\r\n│ ♣ │\r\n│ │\r\n│ │\r\n│ A│\r\n└─────────┘\r\n",
"┌─────────┐\r\n│2 │\r\n│ │\r\n│ │\r\n│ ♣ │\r\n│ │\r\n│ │\r\n│ 2│\r\n└─────────┘\r\n",
"┌─────────┐\r\n│3 │\r\n│ │\r\n│ │\r\n│ ♣ │\r\n│ │\r\n│ │\r\n│ 3│\r\n└─────────┘\r\n",
"┌─────────┐\r\n│4 │\r\n│ │\r\n│ │\r\n│ ♣ │\r\n│ │\r\n│ │\r\n│ 4│\r\n└─────────┘\r\n",
"┌─────────┐\r\n│5 │\r\n│ │\r\n│ │\r\n│ ♣ │\r\n│ │\r\n│ │\r\n│ 5│\r\n└─────────┘\r\n",
"┌─────────┐\r\n│6 │\r\n│ │\r\n│ │\r\n│ ♣ │\r\n│ │\r\n│ │\r\n│ 6│\r\n└─────────┘\r\n",
"┌─────────┐\r\n│7 │\r\n│ │\r\n│ │\r\n│ ♣ │\r\n│ │\r\n│ │\r\n│ 7│\r\n└─────────┘\r\n",
"┌─────────┐\r\n│8 │\r\n│ │\r\n│ │\r\n│ ♣ │\r\n│ │\r\n│ │\r\n│ 8│\r\n└─────────┘\r\n",
"┌─────────┐\r\n│9 │\r\n│ │\r\n│ │\r\n│ ♣ │\r\n│ │\r\n│ │\r\n│ 9│\r\n└─────────┘\r\n",
"┌─────────┐\r\n│10 │\r\n│ │\r\n│ │\r\n│ ♣ │\r\n│ │\r\n│ │\r\n│ 10│\r\n└─────────┘\r\n",
"┌─────────┐\r\n│J │\r\n│ │\r\n│ │\r\n│ ♣ │\r\n│ │\r\n│ │\r\n│ J│\r\n└─────────┘\r\n",
"┌─────────┐\r\n│Q │\r\n│ │\r\n│ │\r\n│ ♣ │\r\n│ │\r\n│ │\r\n│ Q│\r\n└─────────┘\r\n",
"┌─────────┐\r\n│K │\r\n│ │\r\n│ │\r\n│ ♣ │\r\n│ │\r\n│ │\r\n│ K│\r\n└─────────┘\r\n",
//diamonds
"┌─────────┐\r\n│A │\r\n│ │\r\n│ │\r\n│ ♦ │\r\n│ │\r\n│ │\r\n│ A│\r\n└─────────┘\r\n",
"┌─────────┐\r\n│2 │\r\n│ │\r\n│ │\r\n│ ♦ │\r\n│ │\r\n│ │\r\n│ 2│\r\n└─────────┘\r\n",
"┌─────────┐\r\n│3 │\r\n│ │\r\n│ │\r\n│ ♦ │\r\n│ │\r\n│ │\r\n│ 3│\r\n└─────────┘\r\n",
"┌─────────┐\r\n│4 │\r\n│ │\r\n│ │\r\n│ ♦ │\r\n│ │\r\n│ │\r\n│ 4│\r\n└─────────┘\r\n",
"┌─────────┐\r\n│5 │\r\n│ │\r\n│ │\r\n│ ♦ │\r\n│ │\r\n│ │\r\n│ 5│\r\n└─────────┘\r\n",
"┌─────────┐\r\n│6 │\r\n│ │\r\n│ │\r\n│ ♦ │\r\n│ │\r\n│ │\r\n│ 6│\r\n└─────────┘\r\n",
"┌─────────┐\r\n│7 │\r\n│ │\r\n│ │\r\n│ ♦ │\r\n│ │\r\n│ │\r\n│ 7│\r\n└─────────┘\r\n",
"┌─────────┐\r\n│8 │\r\n│ │\r\n│ │\r\n│ ♦ │\r\n│ │\r\n│ │\r\n│ 8│\r\n└─────────┘\r\n",
"┌─────────┐\r\n│9 │\r\n│ │\r\n│ │\r\n│ ♦ │\r\n│ │\r\n│ │\r\n│ 9│\r\n└─────────┘\r\n",
"┌─────────┐\r\n│10 │\r\n│ │\r\n│ │\r\n│ ♦ │\r\n│ │\r\n│ │\r\n│ 10│\r\n└─────────┘\r\n",
"┌─────────┐\r\n│J │\r\n│ │\r\n│ │\r\n│ ♦ │\r\n│ │\r\n│ │\r\n│ J│\r\n└─────────┘\r\n",
"┌─────────┐\r\n│Q │\r\n│ │\r\n│ │\r\n│ ♦ │\r\n│ │\r\n│ │\r\n│ Q│\r\n└─────────┘\r\n",
"┌─────────┐\r\n│K │\r\n│ │\r\n│ │\r\n│ ♦ │\r\n│ │\r\n│ │\r\n│ K│\r\n└─────────┘\r\n",
//spades
"┌─────────┐\r\n│A │\r\n│ │\r\n│ │\r\n│ ♠ │\r\n│ │\r\n│ │\r\n│ A│\r\n└─────────┘\r\n",
"┌─────────┐\r\n│2 │\r\n│ │\r\n│ │\r\n│ ♠ │\r\n│ │\r\n│ │\r\n│ 2│\r\n└─────────┘\r\n",
"┌─────────┐\r\n│3 │\r\n│ │\r\n│ │\r\n│ ♠ │\r\n│ │\r\n│ │\r\n│ 3│\r\n└─────────┘\r\n",
"┌─────────┐\r\n│4 │\r\n│ │\r\n│ │\r\n│ ♠ │\r\n│ │\r\n│ │\r\n│ 4│\r\n└─────────┘\r\n",
"┌─────────┐\r\n│5 │\r\n│ │\r\n│ │\r\n│ ♠ │\r\n│ │\r\n│ │\r\n│ 5│\r\n└─────────┘\r\n",
"┌─────────┐\r\n│6 │\r\n│ │\r\n│ │\r\n│ ♠ │\r\n│ │\r\n│ │\r\n│ 6│\r\n└─────────┘\r\n",
"┌─────────┐\r\n│7 │\r\n│ │\r\n│ │\r\n│ ♠ │\r\n│ │\r\n│ │\r\n│ 7│\r\n└─────────┘\r\n",
"┌─────────┐\r\n│8 │\r\n│ │\r\n│ │\r\n│ ♠ │\r\n│ │\r\n│ │\r\n│ 8│\r\n└─────────┘\r\n",
"┌─────────┐\r\n│9 │\r\n│ │\r\n│ │\r\n│ ♠ │\r\n│ │\r\n│ │\r\n│ 9│\r\n└─────────┘\r\n",
"┌─────────┐\r\n│10 │\r\n│ │\r\n│ │\r\n│ ♠ │\r\n│ │\r\n│ │\r\n│ 10│\r\n└─────────┘\r\n",
"┌─────────┐\r\n│J │\r\n│ │\r\n│ │\r\n│ ♠ │\r\n│ │\r\n│ │\r\n│ J│\r\n└─────────┘\r\n",
"┌─────────┐\r\n│Q │\r\n│ │\r\n│ │\r\n│ ♠ │\r\n│ │\r\n│ │\r\n│ Q│\r\n└─────────┘\r\n",
"┌─────────┐\r\n│K │\r\n│ │\r\n│ │\r\n│ ♠ │\r\n│ │\r\n│ │\r\n│ K│\r\n└─────────┘\r\n",
//hearts
"┌─────────┐\r\n│A │\r\n│ │\r\n│ │\r\n│ ♥ │\r\n│ │\r\n│ │\r\n│ A│\r\n└─────────┘\r\n",
"┌─────────┐\r\n│2 │\r\n│ │\r\n│ │\r\n│ ♥ │\r\n│ │\r\n│ │\r\n│ 2│\r\n└─────────┘\r\n",
"┌─────────┐\r\n│3 │\r\n│ │\r\n│ │\r\n│ ♥ │\r\n│ │\r\n│ │\r\n│ 3│\r\n└─────────┘\r\n",
"┌─────────┐\r\n│4 │\r\n│ │\r\n│ │\r\n│ ♥ │\r\n│ │\r\n│ │\r\n│ 4│\r\n└─────────┘\r\n",
"┌─────────┐\r\n│5 │\r\n│ │\r\n│ │\r\n│ ♥ │\r\n│ │\r\n│ │\r\n│ 5│\r\n└─────────┘\r\n",
"┌─────────┐\r\n│6 │\r\n│ │\r\n│ │\r\n│ ♥ │\r\n│ │\r\n│ │\r\n│ 6│\r\n└─────────┘\r\n",
"┌─────────┐\r\n│7 │\r\n│ │\r\n│ │\r\n│ ♥ │\r\n│ │\r\n│ │\r\n│ 7│\r\n└─────────┘\r\n",
"┌─────────┐\r\n│8 │\r\n│ │\r\n│ │\r\n│ ♥ │\r\n│ │\r\n│ │\r\n│ 8│\r\n└─────────┘\r\n",
"┌─────────┐\r\n│9 │\r\n│ │\r\n│ │\r\n│ ♥ │\r\n│ │\r\n│ │\r\n│ 9│\r\n└─────────┘\r\n",
"┌─────────┐\r\n│10 │\r\n│ │\r\n│ │\r\n│ ♥ │\r\n│ │\r\n│ │\r\n│ 10│\r\n└─────────┘\r\n",
"┌─────────┐\r\n│J │\r\n│ │\r\n│ │\r\n│ ♥ │\r\n│ │\r\n│ │\r\n│ J│\r\n└─────────┘\r\n",
"┌─────────┐\r\n│Q │\r\n│ │\r\n│ │\r\n│ ♥ │\r\n│ │\r\n│ │\r\n│ Q│\r\n└─────────┘\r\n",
"┌─────────┐\r\n│K │\r\n│ │\r\n│ │\r\n│ ♥ │\r\n│ │\r\n│ │\r\n│ K│\r\n└─────────┘\r\n",
};
List<int> cardValues = new List<int>()
{
//clubs
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10,
//diamonds
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10,
//spades
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10,
//hearts
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10,
};
int cardnumber;
int cardnumber1;
int cardnumber2;
int cardnumber3;
int hit;
int dealerHit;
int dealerValue;
double usermoney = 50;
int cardValue = 0;
double userBet = 0;
string answer = "";
string answer1 = "";
int value = 0;
string dealerCard = "┌─────────┐\r\n│░░░░░░░░░│\r\n│░░░░░░░░░│\r\n│░░░░░░░░░│\r\n│░░░░░░░░░│\r\n│░░░░░░░░░│\r\n│░░░░░░░░ ░│\r\n│░░░░░░░░░│\r\n└─────────┘\r\n";
Console.WriteLine("welcome to \n\r\noooooooooo. oooo oooo oooo oooo \r\n`888' `Y8b `888 `888 `888 `888 \r\n 888 888 888 .oooo. .ooooo. 888 oooo 888 .oooo. .ooooo. 888 oooo \r\n 888oooo888' 888 `P )88b d88' `\"Y8 888 .8P' 888 `P )88b d88' `\"Y8 888 .8P' \r\n 888 `88b 888 .oP\"888 888 888888. 888 .oP\"888 888 888888. \r\n 888 .88P 888 d8( 888 888 .o8 888 `88b. 888 d8( 888 888 .o8 888 `88b. \r\no888bood8P' o888o `Y888\"\"8o `Y8bod8P' o888o o888o .o. 88P `Y888\"\"8o `Y8bod8P' o888o o888o \r\n `Y888P \r\n \r\n \r\n");
Console.WriteLine("Do you want to see the rules?");
while (true)
{
answer = Console.ReadLine().ToLower();
if (answer == "yes")
{
rules();
}
else if (answer == "no")
{
randomCardDraw();
}
else
{
Console.WriteLine("Please enter yes or no");
}
}
void rules()
{
Console.WriteLine("\nGoal: get closer to 21 than the dealer withou going over.\n\nGameplay: you will be given two cards and you must hit or stand.\nHit: when you hit you will be given another card that will add on to your other two to bring your value closer to 21.\nStand: when you say stand the cards you have will be locked in and you can't get more cards.\n\nDealer: the dealer must stand at 17 or above.\n\nTie: if you and the dealers cards add up to the same value the you will get your bet back without losing or winning any money.\n");
Console.WriteLine("\npress ENTER to continue");
Console.ReadLine();
randomCardDraw();
}
void mainCode()
{
while (true)
{
Console.WriteLine("You now have ${0:00.00}", usermoney + " in your account");
if (usermoney <= 0) { endOfGame(); }
Thread.Sleep(1000);
// playGame();
Console.WriteLine("would you like to keep playing");
answer = Console.ReadLine().ToLower();
if (answer == "yes")
{
randomCardDraw();
}
else if (answer == "no")
{
endOfGame();
}
else
{
Console.WriteLine("please enter yes or no");
}
}
}
randomCardDraw();
int randomCardDraw()
{
Console.Clear();
Console.WriteLine("You now have ${0:00.00}", usermoney + " in your account");
Console.WriteLine("how much would you like to bet?");
try
{
userBet = Convert.ToInt32(Console.ReadLine());
}
catch
{
Console.WriteLine("please enter a whole number");
usermoney = 50;
}
// dealer
// cardNumber2 = dealerCard
Console.WriteLine("Dealer:");
cardnumber2 = random.Next(0, deck.Count);
cardnumber3 = random.Next(0, deck.Count);
Console.WriteLine("the dealer drew \n" + dealerCard + "&\n" + deck[cardnumber3]);
// player
Console.WriteLine("You:");
cardnumber = random.Next(0, deck.Count);
cardnumber1 = random.Next(0, deck.Count);
Console.WriteLine("You drew \n" + deck[cardnumber] + "&\n" + deck[cardnumber1]);
value = cardValues[cardnumber] + cardValues[cardnumber1];
Console.WriteLine("Those have the value of " + value);
cardValue = cardValues[cardnumber];
playGame();
return cardValue;
}
void playGame()
{
while (true)
{
Console.WriteLine("\nDo you want to hit or stand?");
answer1 = Console.ReadLine().ToLower();
if (answer1 == "hit")
{
hit = random.Next(0, deck.Count);
Console.WriteLine("You drew \n" + deck[hit]);
value = value + cardValues[hit];
Console.WriteLine("Your cards add up to " + value);
if (value < 21)
{
continue;
}
else if (value == 21)
{
Console.WriteLine("BLACKJACK!!!!");
usermoney = usermoney + userBet;
mainCode();
}
else if (value > 21)
{
Console.WriteLine("Bust! You Lost");
usermoney = usermoney - userBet;
mainCode();
}
}
else if (answer1 == "stand")
{
break;
}
else
{
Console.WriteLine("Please enter hit or stand!");
continue;
}
}
Console.WriteLine("Lets see what the dealer had");
Console.WriteLine("the dealer had \n" + deck[cardnumber2] + "&\n" + deck[cardnumber3]);
dealerValue = cardValues[cardnumber2] + cardValues[cardnumber3];
Console.WriteLine("that has a value of " + dealerValue);
if (dealerValue < 17)
{
dealerHit = random.Next(0, deck.Count);
Console.WriteLine("The dealer hit and got a \n" + deck[dealerHit]);
dealerValue = dealerValue + cardValues[dealerHit];
Console.WriteLine("The dealer's cards add up to " + dealerValue);
}
else if (dealerValue >= 17)
{
Console.WriteLine("The dealer stands");
}
}
void endOfGame()
{
}
每当我尝试运行我的代码时,符号都不会显示在控制台上,我知道这些符号可以工作,因为它们在我朋友的电脑上运行良好。
我尝试了
Console.WriteLine("♥");
,但没有打印出符号
我真的需要帮助,因为这是一项学校作业。
这是我在这里发表的第一篇文章,如果不好的话很抱歉
正如有人评论的那样,您可以像这样启用 Unicode:
Console.OutputEncoding = Encoding.Unicode;
一个有用的注意事项:您可以使用原始字符串文字。它们允许您以自然的方式包含换行符。示例:
string s = """
┌─────────┐
│A │
│ │
│ │
│ ♣ │
│ │
│ │
│ A│
└─────────┘
""";
// ^ white spaces to the left of the closing `"""` are not included in the string.