Beispiel #1
0
        static void engine()
        {
            intro();

            ////////////////////prerequisites////////////////////////////

            Style styleP = new Style("  *  " +
                                     "     " +
                                     "*   *" +
                                     "     " +
                                     "  *  ", 5, 5);

            Style styleE = new Style("  **  " +
                                     " **** " +
                                     "**  **" +
                                     " **** " +
                                     "  **  ", 6, 5);

            Style styleG = new Style("  **  " +
                                     " **** " +
                                     "******" +
                                     "******" +
                                     " **** " +
                                     "  **  ", 6, 6);

            Style styleB = new Style("*", 1, 1);

            Random rng = new Random();

            Game game = new Game();

            Task.Delay(100).Wait();

            game.Render(true);

            Quadrant quadrant = (Quadrant)rng.Next(0, 4);

            Goal   goal   = new Goal(30, 50, game, styleG);
            Block  block  = new Block(4000, 4000, game, new Style(new string('*', 15 * 15), 15, 15));
            Player player = new Player(1, 1, 50, game, styleP);
            Enemy  enemy  = new Enemy(50, 50, 500, game, styleE, player);

            game.AddBlocks(3);

            ////////////////////////////////////////////////////////////////////

            /////////////////////////GoardLoop/Engine///////////////////////////////////

            MemoryCache cache    = MemoryCache.Default;
            DateTime    now      = new DateTime();
            DateTime    previous = new DateTime();
            TimeSpan    elapsed  = new TimeSpan();
            int         wait     = 0;

            while (true)
            {
                previous = now;
                now      = DateTime.Now;
                elapsed  = now - previous;

                ///////////////LoopCode///////////////
                game.InputProcessor();
                game.Update();

                object collision = cache.Get("collision");
                if (collision != null)
                {
                    break;
                }

                game.Render();

                ////////////////////////////////////////

                wait = 16 - elapsed.Milliseconds;

                if (!(wait < 0))
                {
                    Task.Delay(wait).Wait();
                }
            }

            //////////////////////////////////////////////////////////////////
        }