Beispiel #1
0
 public void InitializeFrame()
 {
     // initialize frame
     if (frame != null)
     {
         frame.BulletDestroyed -= frame_BulletDestroyed;
         frame.BulletSpawned -= frame_BulletSpawned;
         frame.UnLoad();
         frame.Load(false);
         frame.BulletDestroyed += frame_BulletDestroyed;
         frame.BulletSpawned += frame_BulletSpawned;
     }
     else
     {
         frame = new BulletMatrix(dimension.Y, dimension.X);
         frame.Load(false);
         frame.BulletDestroyed += frame_BulletDestroyed;
         frame.BulletSpawned += frame_BulletSpawned;
     }
 }
        public static void Main()
        {
            Regex rex = new Regex("[0-1]?[0-9]x[0-1]?[0-9]");
            string command = "";

            var stuffs = Initialize(rex, command);

            BulletMatrix frame = new BulletMatrix(stuffs.Y, stuffs.X);

            frame.Load(false);
            //Console.Clear();
            frame.BalanceGrid(true, true);
            do
            {
                command = "";
                rex = new Regex("[0-9A-Z][0-9A-Z]x[0-9A-Z][0-9A-Z]|quit");
                command = PromptForCommand(rex, command, frame);

                frame.enablePrinting = true;

                if (!Regex.IsMatch(command, "quit"))
                {
                    KeyValuePair<string, string> stuff = ParseCommandIntoSwapCodes(command);
                    Position2D start = frame.CommandToPosition(stuff.Key);
                    Position2D end = frame.CommandToPosition(stuff.Value);

                    if (!frame.CanSwapPositions(start, end))
                    {
                        Console.WriteLine("these pieces can't be swapped...");
                        System.Threading.Thread.Sleep(750);
                        //Console.Clear();
                        continue;
                    }

                    //Console.Clear();
                    frame.Debug_PrintBulletMatrix();
                    System.Threading.Thread.Sleep(100);

                    frame.SwapPositions(start, end);
                    //Console.SetCursorPosition(0, 0);
                    frame.Debug_PrintBulletMatrix();
                    System.Threading.Thread.Sleep(100);

                    var matches = frame.CollectMatchedBullets();

                    if (matches.Count == 0)
                    {
                        Console.WriteLine();
                        Console.WriteLine("Bad Swap...");
                        System.Threading.Thread.Sleep(750);
                        frame.SwapPositions(start, end);
                        //Console.Clear();
                    }

                    frame.BalanceGrid(true, false);

                    //Console.SetCursorPosition(0, 0);
                    frame.Debug_PrintBulletMatrix();

                    if (!frame.CanMatchMore())
                    {
                        Console.WriteLine();
                        Console.WriteLine("No more available matches :'(...");
                        System.Threading.Thread.Sleep(750);
                        command = "";
                        rex = new Regex("[YyNn]");
                        do
                        {
                            Console.WriteLine();
                            Console.WriteLine("Would you like to play again?[(Y)es or (N)o]:");
                            command = Console.ReadLine();

                        } while (!rex.IsMatch(command));

                        if (Regex.IsMatch(command, "[Yy]"))
                        {
                            frame.UnLoad();
                            frame.Load(true);
                            frame.BalanceGrid(false, true);
                            command = "";
                        }
                        else
                        {
                            command = "quit";
                        }
                    }
                }
            } while (command != "quit");

            Console.WriteLine("GameOver!");
            Console.WriteLine("Press any key to continue...");
            //Console.ReadKey(true);
        }