玩家类卡牌游戏

时间:2018-03-09 15:20:52

标签: c# class playing-cards

我正在制作一张由32张牌组成的纸牌游戏。卡值为10(最高),9,8,7,国王,皇后,杰克(最低)。它是四个玩家的纸牌游戏。必须有五个级别,包括球员和锦标赛。我制作的第一堂课是卡片课程:

public class Cards
{
    private string face;
    private string suit;

    public Cards(string cardFace, string cardSuit)
    {
        face = cardFace;
        suit = cardSuit;
    }
    public override string ToString()
    {
        return face + " van " + suit;
    }
}

然后我将这些卡片定义在另一个我称之为Deck的课程中,但是卡片中没有任何附加值,在甲板课程内部还有洗牌活动,这应该发生在每一轮之后

public class Deck
{
    private Cards[] deck;
    private int currentCard;
    private const int NUMBER_OF_CARDS = 32;
    private Random ranNum;

    public Deck()
    {
        string[] faces = { "Jack", "Queen", "King", "Ace", "seven", "eight", "Nine", "Ten" };
        string[] suits = { "Diamonds", "Hearts", "Spades", "Clubs" };
        deck = new Cards[NUMBER_OF_CARDS];
        currentCard = 0; 
        ranNum = new Random();
        for (int count = 0; count < deck.Length; count++) 
            deck[count] = new Cards(faces[count % 8], suits[count / 8]);
    }

    public void shuffel()
    {
        int currentCard = 0;
        for (int first = 0; first < deck.Length; first++)
        {
            int second = ranNum.Next(NUMBER_OF_CARDS);
            Cards temp = deck[first];
            deck[first] = deck[second];
            deck[second] = temp;

        }
    }

    public Cards DealCards()
    {
        if (currentCard < deck.Length)
            return deck[currentCard++];
        else
            return null;
    }    
}

这是程序类:

public class Program
{
    public static void Main(string[] args)
    {
        Deck deck1 = new Deck();
        deck1.shuffel();
        for (int i = 0; i < 16; i++)
        {
            Console.WriteLine(deck1.DealCards());
            if ((i + 1) % 4 == 0)
                Console.WriteLine();
        }
        Console.ReadLine();
    }
}

我遇到麻烦如何将其作为用户输入的玩家名称为4,发牌应该去,因为每个玩家将有四张牌,我可以用这个代码制作四手牌而不分配给玩家的名称,以及应该有用户输入用户想要播放的卡。任何有价值的帮助都将受到高度赞赏。

0 个答案:

没有答案