纸牌游戏在do while(c#)中递增

问题描述 投票:0回答:1

我一直被困在制作纸牌阵列,然后从第一张纸牌中随机挑选一张纸牌,然后将其存储在第二张纸牌中的练习中。我选择循环是在我递增I(第二张阵列中卡的位置)时执行的。虽然似乎我并没有像我想的那样增加。有人可以告诉我我这次练习错在哪里了,这应该是一个很容易解决的问题。预先感谢。

static void Main(string[] args)
    {
        string[] myCards = new string [52] {"H1","H2","H3","H4","H5","H6","H7","H8","H9","HT","HJ","HQ","HK",
        "D1", "D2","D3","D4","D5","D6","D7","D8","D9","DT","DJ","DQ","DK",
        "C1", "C2","C3","C4","C5","C6","C7","C8","C9","CT","CJ","CQ","CK",
        "S1", "S2","S3","S4","S5","S6","S7","S8","S9","ST","SJ","SQ","SK"};

        int i=0;
        bool stopPlaying= true;

        string[] arrDeckOfCardsPulled;
        arrDeckOfCardsPulled = new string[i+1];





        do
        {

            Console.Write("Choose one of the following options:");
            Console.WriteLine("\t'A' : To pick a card.");
            Console.WriteLine("\t\t\t\t\t"+"'B' : To fold the deck and END the game.");
            string playOrNot = Console.ReadLine();

            Random random = new Random();
            int randomCard = random.Next(0,52);
            string valueOfMycard = myCards[randomCard];

            if (randomCard != Array.IndexOf(arrDeckOfCardsPulled, randomCard)) {




                switch (playOrNot)
            {

                case "A":
                    {
                        arrDeckOfCardsPulled[i] = valueOfMycard;

                        Console.WriteLine();
                        Console.WriteLine("This is the card you picked: " + myCards[randomCard]);
                        Console.WriteLine();
                        Console.WriteLine("This is the position of your card in the first array: " + Array.IndexOf(myCards, valueOfMycard));
                        Console.WriteLine();
                        Console.WriteLine("This is the position of your card in the second array: " + Array.IndexOf(arrDeckOfCardsPulled, valueOfMycard));
                        i ++;
                        }

                        break;


                case "B":
                        Console.WriteLine();
                        Console.Write("These are the cards that you pulled:");

                        foreach (string card in arrDeckOfCardsPulled)
                        {
                            Console.Write(card+" ");
                        }

                    Console.WriteLine();
                    Console.Write("I am folding the deck.");
                    Console.WriteLine();

                    Console.Write("\n\t\t\t\t\t\t THE END");
                    Console.WriteLine("\n");

                    Console.ReadKey();
                    stopPlaying = false;
                    break;


                default:
                    break;

            }
            Console.WriteLine("\n");
            }

        } while (stopPlaying||(i)<52);





    }
c# arrays do-while
1个回答
0
投票

我很愚蠢

数组大小在初始化后即被固定。我完全是一个初学者,请原谅我浪费您的时间,这是我的解决方案。

© www.soinside.com 2019 - 2024. All rights reserved.