我有一个基本的控制台应用程序,但它在我标记的几个地方给了我错误。这是我第一次尝试拆分字符串等,而且我无法弄清楚如何使用构造函数来随机吐出一组手。'
namespace PokerGame
{
public class Display
{
static void Main()
{
Console.WriteLine("Welcome to the Poker Game!");
Console.WriteLine("\t" + "Enter 'deal' to start game!");
Console.WriteLine("Hand is: {0}");
}
}
public class NewDeal
{
public string card;
public string[] suit = {"♥,♠,♦,♣"};
public char delimiter = ',';
public string[] rank = {"A,1,2,3,4,5,6,7,8,9,10,J,Q,K"};
public string dealer(string suit, string rank)
{
string[] singleSuit = suit.Split(delimiter);
string[] singleRank = rank.Split(delimiter);
foreach(string s in singleSuit)
{
string card = s + singleRank;
}
return card;
}
public NewDeal()
{
}
}
}
答案 0 :(得分:0)
Console.WriteLine("Pick a card?(\"no\" to exit): ");
string sentinelValue = Console.ReadLine();
NewDeal oNewDeal = new NewDeal();
Random newCard = new Random(System.DateTime.Now.Second);
string _newCard = "";
while (sentinelValue != "no")
{
_newCard = oNewDeal.getCards(newCard.Next(0, oNewDeal.suit.Length - 1), newCard.Next(0, oNewDeal.rank.Length - 1));
Console.Write("Card: {0}\n", _newCard);
Console.WriteLine("Pick a card?(\"no\" to exit): ");
sentinelValue = Console.ReadLine();
}
Console.Read();
}
}
public class NewDeal
{
public string card = "";
public string[] suit = new string[] { "♥","♠","♦","♣" };
public const char DELIMETER = ',';
public string[] rank = new string[] {"A","1","2","3","4","5","6","7","8","9","10","J","Q","K"};
public string getCards(int _suit, int _rank)
{
return card = rank[_rank] + suit[_suit];
}
}
}