예제 #1
0
파일: game.cs 프로젝트: zsonbi/snake
        //-----------------------------------------------------------------------
        //Starts the game
        public async void run()
        {
            //So that we can't start multiple games
            if (isRunning)
            {
                return;
            }//if
            isRunning = true;

            Player = new Snake(maxXsize, maxYsize);
            //The first food
            SpawnFood();

            while (!Player.Dead)
            {
                //Updates the game
                Update();
                //Moves the snake
                Player.Move(direction, eaten);
                //Detects if it went to itself
                Player.DetectCollision();
                //if it eaten a food
                eaten = Player.head.xcord == Foodcord[0] && Player.head.ycord == Foodcord[1];
                if (eaten)
                {
                    score++;
                    //spawn new food
                    SpawnFood();
                }//if

                //A bit of delay
                await Task.Delay(150);
            }//while
            isRunning = false;
        }