Esempio n. 1
0
        static void Main(string[] args)
        {
            hLine upLine = new hLine( 0, 78, 0, '#' );
            hLine downLine = new hLine(0, 78, 24, '#');
            vLine leftLine = new vLine(0, 24, 0, '#');
            vLine rightLine = new vLine(0, 24, 78, '#');

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

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

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

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

            Console.ReadLine();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            //Console.SetBufferSize(999, 25);

            // Draw frame

            HorizontalLine upLine = new HorizontalLine(0, 78, 0, '+');
            HorizontalLine downLine = new HorizontalLine(0, 78, 24, '+');
            VerticalLine leftLine = new VerticalLine(0, 24, 0, '+');
            VerticalLine rightLine = new VerticalLine(0, 24, 78, '+');
            upLine.Drow();
            downLine.Drow();
            leftLine.Drow();
            rightLine.Drow();

            Point p = new Point(2, 5, '*');
            Snake snake = new Snake(p, 4, Direction.RIGHT);
            snake.Drow();

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

            Console.ReadLine();
        }
Esempio n. 3
0
 static void Main(string[] args)
 {
     // рисую рамочку по краям
     HorizontalLine line = new HorizontalLine(0,78,0,'%');
     HorizontalLine line2 = new HorizontalLine(0, 78, 24, '%');
     VerticalLine line3 = new VerticalLine(0, 24, 0, '%');
     VerticalLine line4 = new VerticalLine(0, 24, 78, '%');
     line.Draw();
     line2.Draw();
     line3.Draw();
     line4.Draw();
     //рисую змейку
     Point p = new Point(4, 5, '*');
     Snake snake = new Snake(p, 4, Direction.RIGHT   );
     snake.Draw();
     //moving
     while (true)
     {
         if (Console.KeyAvailable)
         {
             ConsoleKeyInfo key = Console.ReadKey();
             snake.HandleKey(key.Key);
         }
         Thread.Sleep(100);
         snake.Move();
     }
 }
Esempio n. 4
0
 /// <summary>
 /// The main entry point for the application.
 /// </summary>
 static void Main(string[] args)
 {
     using (Snake game = new Snake())
     {
         game.Run();
     }
 }
Esempio n. 5
0
        static void Main(string[] args)
        {
            Point p1 = new Point(1, 2, '*');
            p1.Draw();

            Point p2 = new Point(4, 5, '#');
            p2.Draw();

            Console.SetBufferSize(80, 25);

            HorizontalLine upLine = new HorizontalLine(0, 78, 0, '+');
            HorizontalLine downLine = new HorizontalLine(0, 78, 24, '+');
            upLine.Draw();
            downLine.Draw();

            VerticalLine leftLine = new VerticalLine(0, 24, 0, '+');
            VerticalLine rightLine = new VerticalLine(78, 24, 0, '+');
            leftLine.Draw();
            rightLine.Draw();

            Point p = new Point(4, 5, '*');
            Snake snake = new Snake(p, 6, Direction.RIGHT);
            snake.Draw();

            while(true)
            {
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.HandleKey(key.Key);
                }
                Thread.Sleep(100);
                snake.Move();
            }
        }
Esempio n. 6
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();
        }
Esempio n. 7
0
        static void Main(string[] args)
        {
            Console.SetBufferSize(80, 25);

            HorizontalLine top = new HorizontalLine(1, 78, 1, '+');
            top.Draw();
            HorizontalLine bottom = new HorizontalLine(1, 78, 24, '+');
            bottom.Draw();
            VerticalLine left = new VerticalLine(1, 1, 24, '+');
            left.Draw();
            VerticalLine right = new VerticalLine(78, 1, 24, '+');
            right.Draw();

            Point p = new Point(4, 5, '*');
            Snake snake = new Snake(p, 6, Direction.RIGHT);
            snake.Draw();

            for (int i = 0; i < 10; i++)
            {
                snake.Move();
                Thread.Sleep(300);
            }

            while (true)
            {
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    if (key.Key == ConsoleKey.LeftArrow)
                        snake.direction = Direction.LEFT;
                    else if (key.Key == ConsoleKey.RightArrow)
                        snake.direction = Direction.RIGHT;
                    else if (key.Key == ConsoleKey.UpArrow)
                        snake.direction = Direction.UP;
                    else if (key.Key == ConsoleKey.DownArrow)
                        snake.direction = Direction.DOWN;
                    else if (key.Key == ConsoleKey.Escape)
                        break;

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

            }
        }
Esempio n. 8
0
        static void Main(string[] args)
        {
            Console.SetBufferSize(80, 25);
            HorizontalLine upLine = new HorizontalLine(0,78,0,'+');
            HorizontalLine downLine = new HorizontalLine(0, 78, 24, '+');
            VerticalLine leftLine = new VerticalLine(0, 24, 0, '+');
            VerticalLine rightLine = new VerticalLine(0, 24, 78, '+');

            upLine.Draw();
            downLine.Draw();
            leftLine.Draw();
            rightLine.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 (snake.Eat(food))
                {
                    food = foodCreator.CreateFood();
                    food.Draw();
                }
                else
                {
                    snake.Move();
                }

                //if (Console.KeyAvailable)
                //{
                //    ConsoleKeyInfo key = Console.ReadKey();
                //    snake.HandleKey(key.Key);
                //}
                Thread.Sleep(300);
                //snake.Move();
            }
        }
Esempio n. 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);
                }
            }
        }
Esempio n. 10
0
        static void Main(string[] args)
        {
            int points = 3;

            Console.CursorVisible = false;
            Random rnd = new Random();
            int    width = Console.WindowWidth, height = Console.WindowHeight;

            Snake[] snakearray = new Snake[100];
            Point   point      = new Point(rnd.Next(window), 0);

            for (int i = 0; i < snakearray.Length; i++)
            {
                if (i < 3)
                {
                    snakearray[i] = new Snake(width / 2 + i, height / 2);
                }
                else
                {
                    snakearray[i] = new Snake(0, 0);
                }
            }
            do
            {
                switch (Console.ReadKey(true).Key)
                {
                case ConsoleKey.UpArrow:
                    follow();
                    snakearray[0].y--;
                    break;

                case ConsoleKey.DownArrow:
                    follow();
                    snakearray[0].y++;
                    break;

                case ConsoleKey.RightArrow:
                    follow();
                    snakearray[0].x++;
                    break;

                case ConsoleKey.LeftArrow:
                    follow();
                    snakearray[0].x--;
                    break;
                }
                update();
            } while (true);
            void update()
            {
                Console.Clear();

                for (int i = 0; i < points; i++)
                {
                    Console.SetCursorPosition(snakearray[i].x, snakearray[i].y);
                    Console.Write("O");
                }
            }

            void follow()
            {
                for (int i = 3; i > 0; i--)
                {
                    snakearray[i] = new Snake(snakearray[i - 1].x, snakearray[i - 1].y);
                }
            }
        }
Esempio n. 11
0
        static void Main(string[] args)
        {
            int   winner = -1;
            Arena arena  = new Arena(ARENA_SIZE_X, ARENA_SIZE_Y);

            Snake[] snakes = new Snake[2];
            snakes[0] = new Snake(arena, 10, 8, PLAYER1, ConsoleKey.W, ConsoleKey.S, ConsoleKey.A, ConsoleKey.D);
            snakes[1] = new Snake(arena, 20, 8, PLAYER2, ConsoleKey.UpArrow, ConsoleKey.DownArrow, ConsoleKey.LeftArrow, ConsoleKey.RightArrow);
            apple[] apples = new apple[3];
            for (int i = 0; i < apples.Length; i++)
            {
                apples[i] = new apple(arena);
            }

            for (int i = 0; i < apples.Length; i++)
            {
                apples[i].spawnApple();
            }

            DrawArena(arena);

            ConsoleKeyInfo keyInfo;

            int snakeIndex, appleIndex;

            isGameOn = true;
            while (isGameOn)
            {
                if (Console.KeyAvailable) /* só lê a tecla se ela já foi pressionada */
                {
                    keyInfo = Console.ReadKey(true);
                    if (keyInfo.Key == ConsoleKey.Escape)
                    {
                        isGameOn = false;
                    }
                    else
                    {
                        for (snakeIndex = 0; snakeIndex < 2; snakeIndex++)
                        {
                            snakes[snakeIndex].OnKeyPressed(keyInfo.Key);
                        }
                    }
                }


                for (snakeIndex = 0; snakeIndex < 2; snakeIndex++)
                {
                    if (!snakes[snakeIndex].IsAlive)
                    {
                        isGameOn = false;
                        winner   = snakeIndex + 1;
                        return;
                    }
                    snakes[snakeIndex].Move();
                }

                for (appleIndex = 0; appleIndex < apples.Length; appleIndex++)
                {
                    apples[appleIndex].spawnApple();
                }

                DrawArena(arena);
            }


            Console.ResetColor();
            Console.WriteLine("Player {0} venceu!", winner);
        }