C#控制台 - 字符串拆分/连接

时间:2014-04-12 01:38:49

标签: c#

我有一个基本的控制台应用程序,但它在我标记的几个地方给了我错误。这是我第一次尝试拆分字符串等,而且我无法弄清楚如何使用构造函数来随机吐出一组手。'

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()
    {

    }
}

}

1 个答案:

答案 0 :(得分:0)

命名空间PokerGame {     公共类显示     {         static void Main()         {             Console.WriteLine(“欢迎来到扑克游戏!”);

        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];
    }


}

}