Example #1
0
        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();
        }
Example #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();
        }
Example #3
0
        static void Main(string[] args)
        {
            Console.SetBufferSize(80, 25);

            //отрисоква рамки
            HorLine upLine    = new HorLine(0, 78, 0, '+');
            HorLine downLine  = new HorLine(0, 78, 24, '+');
            VerLine leftLine  = new VerLine(0, 0, 24, '+');
            VerLine rightLine = new VerLine(78, 0, 24, '+');

            upLine.Draw();
            downLine.Draw();
            leftLine.Draw();
            rightLine.Draw();

            Point p = new Point(4, 5, '*');

            Snake snake = new Snake(p, 4, Direction.right);

            snake.Draw();

            AddFood foodC = new AddFood(80, 25, '$');
            Point   food  = foodC.CreateFood();

            food.Draw();


            while (true)
            {
                if (snake.Eat(food))
                {
                    food = foodC.CreateFood();
                    food.Draw();
                }
                else
                {
                    snake.Move();
                }

                Thread.Sleep(200);

                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.HandleKey(key.Key);
                }
            }
        }
Example #4
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();
        }