Example #1
0
        static int game(int width, int height, string[] alltext, int state)
        {
            Console.WriteLine("Press Any key");
            const int PLAYER_TIMEOUT = 3;

            int counter = 0;

            Field grid = new Field(width, height, 0, 0, 10, 0, alltext[10]);


            Shape figure = new Shape(grid);

            ConsoleKeyInfo input = Console.ReadKey(true);

            grid.render();

            while (grid.exit == false)
            {
                if (grid.gameover == true)
                {
                    Console.Clear();
                    Console.WriteLine(alltext[15] + "\n Press Any key");
                    Console.ReadKey();
                    Console.Clear();
                    main_menu(alltext, state);
                    return(4);   //game over state
                }

                grid.render();

                Task <int> task_update = new Task <int>(() => grid.update(input, PLAYER_TIMEOUT, grid, figure));
                task_update.Start();

                while (grid.pause == true)
                {
                    if (grid.exit)
                    {
                        Console.Clear();
                        Console.WriteLine(alltext[15] + "\n Press Any key");
                        Console.ReadKey();
                        Console.Clear();
                        main_menu(alltext, state);
                        return(3);
                    }      //quit
                    System.Threading.Thread.Sleep(500);
                }

                if ((counter % grid.period) == 0)
                {
                    figure.move_down(grid);  //giving time to react
                }

                counter++;
                System.Threading.Thread.Sleep(PLAYER_TIMEOUT);
            }


            Console.Clear();
            Console.WriteLine(alltext[15] + "\n Press Any key");
            Console.ReadKey();
            Console.Clear();
            main_menu(alltext, state);
            return(1); //game over
        }