Exemple #1
0
 static void Loop(object obj)
 {
     if (walls.IsHit(snake.Head) || snake.IsHitItself)
     {
         gg.WriteTextLine();
         time.Dispose();
         ConsoleKeyInfo k;
         do
         {
             k = Console.ReadKey();
         }while (k.Key != ConsoleKey.Enter);
         Init();
     }
     else if (FoodFactory.IsEaten(snake.Head))
     {
         foodFactory.CreateFood();
     }
     else
     {
         snake.Move();
         if (snake.counter >= snake.str.Length)
         {
             TextLine won = new TextLine("YOU WIN!!! :)", (x - "YOU WIN!!! :)".Length) / 2, y / 2 - 1);
             TextLine w   = new TextLine(snake.str, (x - snake.str.Length) / 2, y / 2 + 1);
             time.Dispose();
             snake.Dispose();
             won.WriteTextLine();
             w.WriteTextLine();
         }
     }
 }
Exemple #2
0
        static void Main(string[] args)
        {
            Console.SetBufferSize(80, 25);

            Walls walls = new Walls(80, 25);

            walls.Draw();

            //Отрисовка точек
            Point p     = new Point(4, 5, '*');
            Snake snake = new Snake(p, 4, Direction.RIGHT);

            snake.Drow();

            FoodCreator foodCreator = new FoodCreator(80, 25, '$');
            Point       food        = foodCreator.CreateFood();

            food.Draw();


            while (true)
            {
                if (walls.IsHit(snake) || snake.IsHitTail())
                {
                    break;
                }

                if (snake.Eat(food))
                {
                    food = foodCreator.CreateFood();
                    food.Draw();
                }
                else
                {
                    snake.Move();
                }
                Thread.Sleep(100);
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.HandleKey(key.Key);
                }
            }

            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.SetCursorPosition(33, 11);
            Console.WriteLine("GAME OVER");
            Console.SetCursorPosition(33, 12);
            Console.WriteLine("Thanks for Watching");
            Console.SetCursorPosition(33, 13);
            Console.WriteLine("Maks EMS production with GeekBrains");
            Console.SetCursorPosition(33, 14);
            Console.WriteLine("Press Enter for exit");
            Console.ReadLine();
        }
Exemple #3
0
        static void Main(string[] args)
        {
            Console.SetBufferSize(88, 25);

            //Отрисовка стен - рамочки
            Walls walls = new Walls(88, 25);

            walls.Draw();

            //Отрисовка змейки
            Point p     = new Point(4, 5, '*');
            Snake snake = new Snake(p, 4, Direction.RIGHT);

            snake.Draw();

            FoodCreator foodCreator = new FoodCreator(80, 25, '$');
            Point       food        = foodCreator.CreateFood();

            food.Draw();

            //Управление змейкой
            while (true)
            {
                if (walls.IsHit(snake) || snake.IsHitTail()) //если змейка натолкнулась на препятствие или хвост, то гейм овер
                {
                    break;
                }
                if (snake.Eat(food)) // если змейка поела, то создаем новую еду, иначе змейка двигается дальше
                {
                    food = foodCreator.CreateFood();
                    food.Draw();
                }
                else //иначе - двигаемся дальше
                {
                    snake.Move();
                }

                Thread.Sleep(100);

                if (Console.KeyAvailable)                   // была ли нажата какая-либо клавиша
                {
                    ConsoleKeyInfo key = Console.ReadKey(); // получаем значение нажатой клавиши
                    snake.HandleKey(key.Key);               // изменяем направление змейки
                }
            }

            //Чтобы не отображался курсор
            Console.CursorVisible = false;
        }
Exemple #4
0
        static void Main(string[] args)
        {
            // создаем границы консоли Arkasha
            Console.SetBufferSize(80, 25);

            Walls walls = new Walls(80, 25);

            walls.Draw();


            //отрисовка точек
            Point p     = new Point(10, 10, '*');
            Snake snake = new Snake(p, 3, Direction.RIGHT);

            snake.Draw();

            FoodCreator foodCreator = new FoodCreator(80, 25, '$');
            Point       food        = foodCreator.CreateFood();

            food.Draw();

            while (true)
            {
                if (walls.IsHit(snake) || snake.IsHitTail())
                {
                    break;
                }
                if (snake.Eat(food))
                {
                    food = foodCreator.CreateFood();
                    food.Draw();
                }
                else
                {
                    snake.Move();
                }

                Thread.Sleep(100);

                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.HandleKey(key.Key);
                }
            }
            WriteGameOver();
            Console.ReadLine();
        }
Exemple #5
0
        static void Main(string[] args)
        {
            Console.SetWindowSize(80, 25);
            Console.SetBufferSize(80, 25);
            Console.CursorVisible = false;

            Walls walls = new Walls(80, 25);

            walls.Draw();

            //Отрисовка точек
            Point p     = new Point(4, 5, '*');
            Snake snake = new Snake(p, 4, Direction.RIGHT);

            snake.Draw();

            FoodCreator foodCreator = new FoodCreator(80, 25, '$');
            Point       food        = foodCreator.CreateFood();

            food.Draw();

            while (true)
            {
                if (walls.IsHit(snake) || snake.IsHitTail())
                {
                    break;
                }
                if (snake.Eat(food))
                {
                    food = foodCreator.CreateFood();
                    food.Draw();
                }
                else
                {
                    snake.Move();
                }

                Thread.Sleep(100);

                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.HandleKey(key.Key);
                }
            }
        }
Exemple #6
0
        static void Main(string[] args)
        {
            Console.SetBufferSize(120, 30);

            Walls walls = new Walls(120, 30);

            walls.Draw();


            //Отрисовка точек
            point p     = new point(4, 5, '*');
            Snake snake = new Snake(p, 4, Direction.right);

            snake.Draw();

            FoodCreator foodCreator = new FoodCreator(120, 30, '$');
            point       food        = foodCreator.CreateFood();

            food.Draw();

            while (true)
            {
                if (walls.IsHit(snake) || snake.IsHitTail())
                {
                    break;
                }
                if (snake.Eat(food))
                {
                    food = foodCreator.CreateFood();
                    food.Draw();
                }
                else
                {
                    snake.Move();
                }
                Thread.Sleep(100);

                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.HandleKey(key.Key);
                }
            }
            WriteGameOver();
            Console.ReadLine();
        }
Exemple #7
0
        static void Main(string[] args)
        {
            Console.SetBufferSize(80,25); //установить размер окна и убрать возможность перемотки

            Walls walls = new Walls(80, 25);
            walls.Draw();

            //Отрисовка змеи
            Point p = new Point(4, 5, '*');
            Snake snake = new Snake(p, 4, Direction.RIGHT);
            snake.Draw();

            FoodCreator foodCreator = new FoodCreator(80, 25, '$');
            Point food = foodCreator.CreateFood();
            food.Draw();

            while(true)
            {
                if (walls.IsHit(snake) || snake.IsHitTail())
                {
                    Console.Clear();
                    Console.SetCursorPosition(37, 7);
                    Console.Write("YOU LOSE");
                    break;
                }
                if(snake.Eat(food))
                {
                    food = foodCreator.CreateFood();
                    food.Draw();
                }
                else
                {
                    snake.Move();
                }

                Thread.Sleep(100);

                if (Console.KeyAvailable) //нажата ли какая-либо клавиша
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.HandleKey(key.Key);
                }
            }

            Console.ReadKey();
        }
Exemple #8
0
        static void Main(string[] args)
        {
            // Console.SetBufferSize(60, 20);

            Walls walls = new Walls(60, 20);

            walls.Draw();

            //отрисовка точек
            Point p     = new Point(4, 5, '*');
            Snake snake = new Snake(p, 4, Direction.Right);

            snake.Draw();

            FoodCreator foodCreator = new FoodCreator(60, 20, '$');
            Point       food        = foodCreator.CreateFood();

            food.Draw();

            while (true)
            {
                if (walls.IsHit(snake) || snake.IsHitTail())
                {
                    break;
                }
                else if (snake.Eat(food))
                {
                    food = foodCreator.CreateFood();
                    food.Draw();
                }
                else
                {
                    snake.Move();
                }
                Thread.Sleep(150);

                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.HandleKey(key.Key);
                }
            }
        }
Exemple #9
0
        static void Main(string[] args)
        {
            Console.SetBufferSize(80, 25);

            Walls walls = new Walls(80, 25);
            walls.Drow();

            //Отрисовка точек
            Point p = new Point(4, 5, '*');
            Snake snake = new Snake(p, 4, Direction.RIGHT);
            snake.Drow();

            FoodCreator foodCreator = new FoodCreator(80, 25, '$');
            Point food = foodCreator.CreateFood();
            food.Drow();

            while (true)
            {
                if (walls.IsHit(snake) || snake.IsHitTail())
                {
                    break;
                }
                if (snake.Eat(food))
                {
                    food = foodCreator.CreateFood();
                    food.Drow();
                }
                else
                {
                    snake.Move();
                }

                Thread.Sleep(100);

                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.HandleKey(key.Key);
                }
            }
        }
Exemple #10
0
        static void Main(string[] args)
        {
            Walls walls = new Walls(80, 25);

            walls.Draw();

            //рисуем точки
            Point p     = new Point(4, 5, '*');
            Snake snake = new Snake(p, 4, Direction.RIGHT);

            snake.Draw();
            FoodCreator foodcreat = new FoodCreator(80, 25, '&');
            Point       food      = foodcreat.CreateFood();

            food.Draw();

            while (true)
            {
                if (walls.IsHit(snake) || snake.IsHitTail())
                {
                    break;
                }
                if (snake.Eat(food))
                {
                    food = foodcreat.CreateFood();
                    food.Draw();
                }
                else
                {
                    snake.Move();
                }
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.Go(key.Key);
                }
                Thread.Sleep(100);
                snake.Move();
            }
        }
Exemple #11
0
        static void Main(string[] args)
        {
            //Ограничение окна
            //Console.SetBufferSize(80, 25);
            #region Wall

            Walls walls = new Walls(80, 25);
            walls.Draw();


            #endregion

            #region SnakeBody

            point  p     = new point(4, 5, '*');
            Snakee snake = new Snakee(p, 4, Direction.RIGHT);
            snake.DrawLine();
            #endregion

            #region Food

            foodCreator foodCreator = new foodCreator(80, 25, '$');
            point       food        = foodCreator.CreateFood();
            food.Draw();

            #endregion

            while (true)
            {
                if (walls.IsHit(snake) || snake.IsHitTail())
                {
                    break;
                    //Console.Write("Game OVER");
                }
                if (snake.Eat(food))
                {
                    food = foodCreator.CreateFood();
                    food.Draw();
                }
                else
                {
                    snake.Move();
                }

                Thread.Sleep(100);

                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.HandleKey(key.Key);
                }
            }

            #region Handle Key

            while (true)
            {
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.HandleKey(key.Key);
                }
                Thread.Sleep(100);
                snake.Move();
            }
            #endregion



            //Console.ReadKey();
        }