コード例 #1
0
        public static void OpenPack()
        {
            List <Card> opened = new List <Card>();

            //Na początku czyścimy konsole;
            kc.cls();
            //Reszta;
            GenerateCards();
            kc.wl("Wybierz booster: ");
            kc.wl("--------------------");
            int cn = 0;

            string[] choice = new string[10];
            try
            {
                foreach (var dir in Directory.GetDirectories("Boosters/"))
                {
                    string dirName = dir.Split('/')[1];
                    choice[cn] = dirName;
                    kc.wl(cn + 1 + ". " + dirName);
                    cn++;
                }
            }
            catch
            {
                kc.wl("Brak boosterów");
                kc.rk();
                return;
            }

            string name = kc.rl();
            //inicjalizaja paczki
            Pack pack = new Pack(choice[Convert.ToInt32(name) - 1]);

            kc.cls();
            try
            {
                CImage.ConsoleWriteImage(new System.Drawing.Bitmap(APP_PATH + @"Boosters\" + pack.name + @"\cover.png"));
            }
            catch
            {}

            kc.wl("--------------------------------");
            kc.wl("");
            kc.ww("Ilość kart w zestawie:");
            kc.wl(pack.size, ConsoleColor.Red);
            kc.ww("Ile paczek chcesz otworzyć?[Max: 10]: ");
            int count = Convert.ToInt32(kc.rl());

            if (count <= 0)
            {
                count = 1;
            }
            else if (count > 10)
            {
                count = 10;
            }

            kc.wl("Prędkość otwierania? [Od 10 = najszybciej do 100 = najwoleniej] ");
            int initSpeed = Convert.ToInt32(kc.rl());

            if (initSpeed < 10)
            {
                initSpeed = 10;
            }
            else if (initSpeed > 100)
            {
                initSpeed = 100;
            }

            kc.cls();

            for (int x = 0; x < count; x++)
            {
                List <Card> cards = pack.Open();

                kc.wl("");
                kc.wl("Otwieramy booster...");
                kc.wl("");

                int speed = initSpeed;

                foreach (Card c in cards)
                {
                    opened.Add(c);
                    kc.ww(c.id + ". Typ:");
                    if (c.type == "Common")
                    {
                        Console.ForegroundColor = ConsoleColor.Green;
                        kc.wl(c.type, ConsoleColor.Green);
                        Console.ForegroundColor = ConsoleColor.White;
                    }
                    if (c.type == "Energy")
                    {
                        Console.ForegroundColor = ConsoleColor.DarkGray;
                        kc.wl(c.type, ConsoleColor.DarkGray);
                        Console.ForegroundColor = ConsoleColor.White;
                    }
                    if (c.type == "Uncommon")
                    {
                        Console.ForegroundColor = ConsoleColor.Magenta;
                        kc.wl(c.type, ConsoleColor.Magenta);
                        Console.ForegroundColor = ConsoleColor.White;
                    }
                    if (c.type == "Rare")
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        kc.wl(c.type, ConsoleColor.Red);
                        Console.ForegroundColor = ConsoleColor.White;
                    }
                    if (c.type == "UltraRare")
                    {
                        Console.ForegroundColor = ConsoleColor.Yellow;
                        kc.wl(c.type, ConsoleColor.Yellow);
                        Console.ForegroundColor = ConsoleColor.White;
                    }
                    Thread.Sleep(speed);
                    speed += initSpeed;
                }
            }

            foreach (Card c in opened)
            {
                string json = JsonConvert.SerializeObject(c);
                File.AppendAllText("save.tcgs", json + Environment.NewLine);
            }

            kc.rk();
        }