コード例 #1
0
        static void Main(string[] args)
        {
            Console.SetBufferSize(120, 30);
            Walls walls = new Walls(mapWidght, mapHeight);

            walls.Draw();


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

            snake.Draw();

            FoodCreator foodCreator = new FoodCreator(mapWidght, mapHeight, '@');
            Point       food        = foodCreator.CreateFood();

            food.Draw();


            while (true)
            {
                if (walls.IsHit(snake) || snake.HitHisTail())
                {
                    //if (walls.IsHit(snake))
                    //{
                    Console.WriteLine("You LOOOSE");
                    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.ReadLine();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: GARRO1994/Snake
        static void Main(string[] args)
        {
            Console.SetBufferSize(120, 30);
            HorizontLine upline  = new HorizontLine(0, 78, 0, '*');
            HorizontLine dowline = new HorizontLine(0, 78, 24, '*');
            VerticalLine left    = new VerticalLine(0, 24, 0, '*');
            VerticalLine right   = new VerticalLine(0, 24, 78, '*');

            upline.Drow();
            dowline.Drow();
            left.Drow();
            right.Drow();

            Point p     = new Point(4, 5, '@');
            Snake snake = new Snake(p, 4, Derection.RIGHT);

            snake.Drow();

            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();
                }
                Thread.Sleep(100);

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

            Console.ReadLine();
        }
コード例 #3
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 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();
        }