Увеличение карточной игры за некоторое время (c#) - PullRequest
0 голосов
/ 12 апреля 2020

Я застрял в этом упражнении, создав массив карт, а затем выбрал случайную карту из первого массива и затем сохранил ее во втором. Мой выбор l oop является делом, когда я увеличиваю 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);





    }

1 Ответ

0 голосов
/ 12 апреля 2020

Я был дураком sh

Размер массива фиксируется сразу после его инициализации. Я абсолютный новичок, прости меня за трату времени, это мое решение.

    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 arrayposition = 0;
        bool stopPlaying= true;

        string[] arrDeckOfCardsPulled;
        arrDeckOfCardsPulled = new string[52];





        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, valueOfMycard)) {

                switch (playOrNot)
            {

                case "A":
                    {

                        arrDeckOfCardsPulled[arrayposition] = 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));
                        arrayposition++;
                    }

                        break;


                case "B":
                        string[]yourpulls=new string[arrayposition+1];
                        Array.Copy(arrDeckOfCardsPulled, 0, yourpulls,0, arrayposition);
                        Console.WriteLine();
                        Console.Write("These are the cards that you pulled: ");

                        foreach (string card in yourpulls)
                        {
                            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||(arrayposition)<53);





    }
}

}

...