コード例 #1
0
ファイル: Program.cs プロジェクト: Fkyeah/csharp
        static void Main(string[] args)
        {
            int Score = 0;

            Console.SetWindowSize(102, 28);
            Console.SetBufferSize(102, 28);
            Walls walls = new Walls(102, 27);

            walls.Draw();
            GameMenu    GameParams  = new GameMenu();
            Point       p           = new Point(4, 5, '*');
            Snake       snake       = new Snake(p, 5, Direction.RIGHT);
            FoodCreator foodCreator = new FoodCreator(100, 25, '$');
            Point       food        = foodCreator.CreateFood();
            Point       food2       = foodCreator.CreateFood();

            snake.Draw();
            food.Draw();
            while (true)
            {
                GameParams.WriteMenu();
                GameParams.Score(Score);
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.GetDirection(key.Key);
                }
                if (snake.Eat(food))
                {
                    food = foodCreator.CreateFood();
                    while (snake.CheckPositionFood(food))
                    {
                        food = foodCreator.CreateFood();
                    }
                    food.Draw();
                    Score++;
                    GameParams.Score(Score);
                }
                snake.Draw();

                if (snake.IsHitTail() || walls.HitinWall(snake))
                {
                    GameParams.WriteGameisOver(Score);
                    break;
                }
                else
                {
                    Thread.Sleep(100);
                }
                snake.Move();
            }
            Console.ReadLine();
        }
コード例 #2
0
        static void Main(string[] args)
        {
            Console.SetBufferSize(80, 27);                                  //Bufer size

            Walls       wall        = new Walls(80, 25);                    //Create all Wals
            Point       point       = new Point(4, 5, '*');                 //Create point
            Snake       snake       = new Snake(point, 2, Direction.right); //Create first state of snake
            FoodCreator foodCreator = new FoodCreator(80, 25, '$');         //Function for generate state of food
            Point       food        = foodCreator.CreateFood();             //Create state of food

            wall.Draw();
            snake.Draw();
            food.Draw();



            while (true)
            {
                if (wall.IsHit(snake) || snake.IsHitTail()) //Protect to crash with wall or tail
                {
                    break;                                  //Out from circle
                }

                if (snake.Eat(food))
                {
                    food = foodCreator.CreateFood();
                    food.Draw();
                    snake.speed = snake.speed * 2;
                }
                else
                {
                    snake.Move();
                }

                Thread.Sleep(100 / snake.speed + 90);

                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.HandlKey(key.Key);
                }// End first if

                // Thread.Sleep(100);
                //snake.Move();
            }//End while



            Console.ReadKey();
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: roottoorroot/Snake
        static void Main(string[] args)
        {
            Console.SetBufferSize(80, 27);                         //Bufer size

            Walls wall = new Walls(80,25);                         //Create all Wals
            Point point = new Point(4, 5, '*');                    //Create point
            Snake snake = new Snake(point, 2, Direction.right);    //Create first state of snake
            FoodCreator foodCreator = new FoodCreator(80, 25, '$');//Function for generate state of food
            Point food = foodCreator.CreateFood();                 //Create state of food

            wall.Draw();
            snake.Draw();
            food.Draw();

            while (true)
            {
                if (wall.IsHit(snake) || snake.IsHitTail()) //Protect to crash with wall or tail
                {
                    break;       //Out from circle
                }

                if (snake.Eat(food))
                {
                    food = foodCreator.CreateFood();
                    food.Draw();
                    snake.speed = snake.speed * 2;
                }
                else
                {
                    snake.Move();
                }

                Thread.Sleep(100/snake.speed + 90);

                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.HandlKey(key.Key);
                }// End first if

               // Thread.Sleep(100);
                //snake.Move();

            }//End while

            Console.ReadKey();
        }