Beispiel #1
0
        private static void testRender()
        {
            Game game2 = new Game(60, 25);

            game2.Spawn(GameObjectType.SnakeHead);
            game2.Spawn(GameObjectType.Apple);
            SnakeSegment seg = new SnakeSegment(new Point(14, 14));

            game2.Render();
            seg.Render();
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            Game game = new Game(20, 20);

            Console.WriteLine("Welcome to Snake Game. Prepare To Die\n\n\n\n\n");
            game.Render();


            while (true)
            {
                game.GetUserMovement();
            }
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            // initialize the game
            Stopwatch sw = new Stopwatch();
            long      wait;
            long      speed = 250;
            Game      game  = new Game(60, 25);

            game.Spawn(GameObjectType.SnakeHead);
            game.Spawn(GameObjectType.Apple);
            Console.CursorVisible = false;
            //testRender();

            //Console.ReadLine();
            //testGameOver();
            sw.Start();
            while (!game.Finished)
            {
                // wait for t time if facing north or south
                // wait for t/2 time if facing east or west
                if (game.Dir == Direction.east || game.Dir == Direction.west)
                {
                    wait = speed / 2;
                }
                else
                {
                    wait = speed;
                }
                long now = sw.ElapsedMilliseconds;
                // Read input at all times even while waiting
                while (now + wait > sw.ElapsedMilliseconds)
                {
                    game.ReadInput();
                }

                // Update the game
                game.Update();
                // Render the game
                game.Render();
            }
            game.GameOverScreen();
        }
Beispiel #4
0
        public override void Loop(Game game, LoopState state)
        {
            state.Tick();
            accumulatedTime += state.NanoSeconds;
            updateCount = 0;

            while (accumulatedTime >= frameRate && updateCount < maxCount)
            {
                game.Update(state);
                updateCount++;
                accumulatedTime -= frameRate;
            }

            state.Interpolation = accumulatedTime/frameRate;

            game.Render(state);

            //var sleepTime = (frameRate - state.MilliSeconds);

            //if(sleepTime > 0)
            //    Thread.Sleep((int)sleepTime);
        }
Beispiel #5
0
        static public void Tick(Object stateInfo)
        {
            if (_isDrawing)
            {
                return;
            }

            _isDrawing = true;

            if (Console.KeyAvailable)
            {
                ConsoleKeyInfo cki = Console.ReadKey(false);
                _exit = _game.ControllCallback(cki.Key);
            }

            Console.Clear();
            _game.Tick();
            _game.Render();
            DrawScreen();

            _isDrawing = false;
        }
Beispiel #6
0
 public override void Loop(Game game, LoopState state)
 {
     state.Tick();
     game.Update(state);
     game.Render(state);
 }