コード例 #1
0
ファイル: Program.cs プロジェクト: TrueFalseTF/SnakeRelease
        static void Main(string[] args)
        {
            Console.SetBufferSize(80, 25);

            Walls walls = new Walls(80, 25);

            walls.Draw();

            Point p     = new Point(1, 5, '*');
            Snake snake = new Snake(p, 20, Direktion.RIGHT);

            snake.Drow();

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

            food.Draw();

            while (true)
            {
                Thread.Sleep(100);

                if (Console.KeyAvailable && walls.IsHit(snake) == false)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.HendleKey(key.Key);
                }

                if (snake.IsHitTail())
                {
                    break;
                }

                if (snake.Eat(food, -77, -23))
                {
                    food = foodCreator.CreateFood(snake);
                    food.Draw();
                }

                if (snake.Eat(food, 1, 1))
                {
                    food = foodCreator.CreateFood(snake);
                    food.Draw();
                }

                if (walls.IsHit(snake))
                {
                    snake.Move(-77, -23);
                    walls.Draw();
                }
                else
                {
                    snake.Move(1, 1);
                }
            }

            WriteGameOver();
            Console.ReadLine();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: ipARTEM/Snake
        static void Main(string[] args)
        {
            //Console.SetBufferSize(80,25);

            //Отрисовка рамки
            Walls walls = new Walls(80, 25);

            walls.Draw();

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

                snake.Move();
            }
        }
コード例 #3
0
        static void Main(string[] args)
        {
            Console.OutputEncoding = Encoding.UTF8;

            Console.Write("Enter your name: ");
            string name = Console.ReadLine();

            Console.SetWindowSize(75, 25);

            Walls walls = new Walls(62, 25);

            walls.Draw();

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

            snake.Draw();

            FoodCreator foodCreator = new FoodCreator(62, 25, '$', ConsoleColor.Green);
            Point       food        = foodCreator.CreateFood();

            food.Draw();
            Score score = new Score(0, 1);            //score-0, level-1

            score.speed = 50;
            score.ScoreWrite();

            while (true)
            {
                if (walls.IsHit(snake) || snake.IsHitTail())
                {
                    break;
                }
                if (snake.Eat(food))
                {
                    score.ScoreUp();
                    score.ScoreWrite();
                    food = foodCreator.CreateFood();
                    food.Draw();
                    if (score.ScoreUp())
                    {
                        score.speed -= 10;
                    }
                }
                else
                {
                    snake.Move();
                }

                Thread.Sleep(score.speed);
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.HandleKey(key.Key);
                }
            }
            WriteGameOver(name);
            Console.ReadLine();
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: Dan4ikM/snake
        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())
                {
                    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);
                }
            }
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: sknilpler/snake
        static void Main(string[] args)
        {
            int points = 0;

            //Установка размера окна консоли (блокировка изменения размера окна и прокрутки)
            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();

                    points++;
                    food.Draw();
                }
                else
                {
                    snake.Move();
                }
                //скорость движения змейки
                if (points <= 25)
                {
                    Thread.Sleep(300 - (points * 10));
                }
                else
                {
                    Thread.Sleep(50);
                }

                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.HandleKey(key.Key);
                }
            }
            WriteGameOver(points);
            Console.ReadLine();
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: ON02/gitTestSnakeGame
        static void Main(string[] args)
        {
            //Point FirstPoint = new Point(10, 5, '*');
            //FirstPoint.drawPoint();
            //Console.ReadLine();

            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();

            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.DrawPoint();


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

                Thread.Sleep(100);

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

            //Console.ReadLine();
        }
コード例 #7
0
        static void Main(string[] args)
        {
            int timeSleep = 100;

            Console.CursorVisible = false;

            Console.SetWindowSize(80, 25);
            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())
                {
                    break;
                }

                if (snake.Eat(food))
                {
                    food = foodCreator.CreateFood();
                    food.Draw();

                    timeSleep -= 15;

                    if (timeSleep < 1)
                    {
                        timeSleep = 10;
                    }
                }
                else
                {
                    snake.Move();
                }

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

            WriteGameOver();
            Console.ReadLine();
        }
コード例 #8
0
ファイル: Program.cs プロジェクト: Jhoonny/Snake
        public static void Main(string[] args)
        {
            // size of map
            int MaxMapWidth = 80;
            int MaxMapHeight = 25;

            Console.SetBufferSize(MaxMapWidth, MaxMapHeight);

            // drow frame
            Walls walls = new Walls(MaxMapWidth, MaxMapHeight);
            walls.Draw();

            // drow point draw snake

            Point point = new Point(5, 10, '*');
            Snake snake = new Snake (point, 5, Direction.RIGHT);
            snake.Draw ();

            // draw food

            FoodCreater foodCreator = new FoodCreater (MaxMapWidth, MaxMapHeight, '$');
            Point food = foodCreator.CreateFood ();
            //Console.ForegroundColor = ConsoleColor.Cyan;
            food.Draw ();

            while (true) {
                // data de perete
                if (walls.IsHit (snake) || snake.IsHitTail()) break;

                // daca maninca

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

                Thread.Sleep (200);

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

                    if (key.Key == ConsoleKey.Escape)
                        break;
                }

            }
            // END

            Console.ForegroundColor = ConsoleColor.Red;
            Console.SetCursorPosition(MaxMapWidth/3 , 10);
            Console.WriteLine ("--=***=--  E N D  --=***=--");
            Console.SetCursorPosition(MaxMapWidth/3 , 12);
            //Thread.Sleep (300);
            //Console.ReadLine ();
        }
コード例 #9
0
ファイル: Program.cs プロジェクト: Janika2201/Snake
        static void Main(string[] args)
        {
            Music music = new Music();

            music.MainMusic();

            Walls walls = new Walls(100, 25);

            walls.Draw();

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

            snake.Draw();

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

            food.Draw();

            int xOffsetO4ki = 40;
            int yOffsetO4ki = 26;

            int o4ki = 0;

            WriteText("Баллы:" + o4ki, xOffsetO4ki, yOffsetO4ki);

            while (true)
            {
                if (walls.IsHit(snake) || snake.IsHitTail())
                {
                    break;
                }
                if (snake.Eat(food))
                {
                    music.EatSound();
                    food = foodCreator.CreateFood();
                    food.Draw();
                    o4ki++;
                    Console.SetCursorPosition(xOffsetO4ki, yOffsetO4ki);
                    WriteText("Баллы:" + o4ki, xOffsetO4ki, yOffsetO4ki);
                }
                else
                {
                    snake.Move();
                }

                Thread.Sleep(100);
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.HandleKey(key.Key);
                }
            }
            music.GameOver();
            WriteGameOver(o4ki);
            Console.ReadLine();
        }
コード例 #10
0
ファイル: Program.cs プロジェクト: noname-r/repoTest
        static void Main(string[] args)
        {
            //Console.WriteLine(Console.BufferHeight.ToString());
            //Console.WriteLine(Console.BufferWidth.ToString());
            //Console.WriteLine(Console.SetWindowSize);
            //Console.WriteLine(Console.LargestWindowWidth);
            //Console.SetBufferSize(80, 25);
            Console.SetWindowSize(80, 25);
            Console.CursorVisible = false;

            Walls walls = new Walls(80, 25);

            walls.Draw();

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

            snake.Draw(ConsoleColor.Green);

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

            food.Draw(ConsoleColor.Yellow);

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

                if (snake.Eat(food))
                {
                    food = foodCreator.CreateFood();
                    food.Draw(ConsoleColor.Yellow);
                }
                else
                {
                    snake.Move();
                }

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

            Console.SetCursorPosition(35, 12);
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("Game over!");
            Console.ReadKey();
        }
コード例 #11
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())
                {
                    break;
                }

                // змейка кушает
                if (snake.Eat(food))
                {
                    food = foodCreator.CreateFood();
                    food.Draw();
                }
                else
                {
                    snake.Move();
                }

                Thread.Sleep(200);

                // проверка на нажатие какой либо клавиши
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.HandlKey(key.Key);
                }
            }

            WriteGameOver();
            Console.ReadKey();
        }
コード例 #12
0
ファイル: Program.cs プロジェクト: serega888/git-rep888
        static void Main(string[] args)
        {
            Console.SetBufferSize(80, 25);
            Walls walls = new Walls(80, 25);

            walls.Draw();


            HorisontalLine lowLine = new HorisontalLine(0, 78, 0, '+');

            lowLine.Drow();
            HorisontalLine upperLine = new HorisontalLine(0, 78, 24, '+');

            upperLine.Drow();
            VerticalLine leftLine = new VerticalLine(0, 0, 24, '+');

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

            rightLine.Drow();

            Point p1    = new Point(4, 4, '*');
            Snake snake = new Snake(p1, 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);
                }
            }
        }
コード例 #13
0
ファイル: Program.cs プロジェクト: Mershik/Snake
        static void Main(string[] args)
        {
            Walls walls = new Walls(1, 80);

            walls.Draw();

            //Отрисовка рамки
            //HotizontalLine line = new HotizontalLine(1,60,0,'-');
            //line.Drow();
            //HotizontalLine line1 = new HotizontalLine(1, 60, 25, '-');
            //line1.Drow();

            //VerticalLine line2 = new VerticalLine(1, 24, 1, '|');
            //line2.Drow();
            //VerticalLine line3 = new VerticalLine(1, 24, 60, '|');
            //line3.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.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);
                }
            }
        }
コード例 #14
0
        static void Main()
        {
            Console.SetBufferSize(150, 50);
            Console.WindowHeight  = 50;
            Console.WindowWidth   = 150;
            Console.CursorVisible = false;

            Walls walls = new Walls(148, 49);

            walls.Draw();

            Point p1    = new Point(10, 10, '*');
            Snake snake = new Snake(p1, 7, Direction.RIGHT);

            snake.Draw();
            snake.Move();


            FoodCreator foodCreator = new FoodCreator(149, 48, '$');
            Point       food        = foodCreator.CreateFood();

            food.Draw();



            while (true)
            {
                if (walls.IsHit(snake) || snake.IsHitTail())
                {
                    Console.Clear();
                    Console.SetCursorPosition(75, 25);
                    Console.WriteLine("GAME OVER");
                    Console.ReadKey();
                }

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


                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.HandleKey(key);
                }
                Thread.Sleep(100);
            }
        }
コード例 #15
0
ファイル: Program.cs プロジェクト: ArtjomKabilov/Snake2
        public void game_draw()
        {
            Console.Clear();
            Console.Title = "Snake";
            Console.SetWindowSize(101, 26);

            Walls walls = new Walls(101, 26);

            walls.Draw();


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

            snake.Draw();
            FoodCreator foodCreator = new FoodCreator(101, 26, '¤', ConsoleColor.Green);
            Point       food        = foodCreator.CreateFood();

            food.Draw();
            Score score = new Score(0, 1);//score =0, level=1

            score.speed = 135;
            score.ScoreWrite();

            while (true)
            {
                if (walls.IsHit(snake) || snake.IsHitTail())
                {
                    break;
                }
                if (snake.Eat(food))
                {
                    score.ScoreUp();
                    score.ScoreWrite();
                    food = foodCreator.CreateFood();
                    food.Draw();
                    //sound.Stop("stardust.mp3");
                    if (score.ScoreUp())
                    {
                        score.speed -= 10;
                    }
                }
                else
                {
                    snake.Move();
                }
                Thread.Sleep(score.speed);
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey(true);
                    snake.HandleKey(key.Key);
                }
            }
        }
コード例 #16
0
        static void Main(string[] args)
        {
            Walls walls = new Walls(80, 25);

            walls.Draw();

            //*ОТРИСОВКА РАМОЧКИ
            //HorizontalLine upLine = new HorizontalLine(0, Console.BufferWidth - 1, 0, 'X');
            //HorizontalLine downLine = new HorizontalLine(0, Console.BufferWidth - 1, 28, 'X');
            //VerticalLine leftLine = new VerticalLine(0, 28, 0, 'X');
            //VerticalLine rightLine = new VerticalLine(0, 28, Console.BufferWidth - 1, 'X');
            //upLine.Drow();
            //downLine.Drow();
            //leftLine.Drow();
            //rightLine.Drow();


            //Отрисовка точек
            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);
                }
            }
        }
コード例 #17
0
        public Game()
        {
            Console.SetWindowSize(100, 30);
            Walls walls = new Walls(80, 25);

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

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

            food.Draw();
            Params settings = new Params();
            Sounds sound    = new Sounds(settings.GetResourceFolder());

            sound.PlayBackground();
            Score count = new Score(0);

            count.ScoreInGame();
            Sounds soundEat = new Sounds(settings.GetResourceFolder());

            while (true)
            {
                if (walls.IsHit(snake) || snake.IsHitTail())
                {
                    break;
                }
                if (snake.Eat(food))
                {
                    food = foodCreator.CreateFood();
                    food.Draw();
                    count.ScoreUp();
                    count.ScoreInGame();
                    soundEat.PlayEat();
                }
                else
                {
                    snake.Move();
                }
                Thread.Sleep(100);
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.Button(key.Key);
                }
            }
            new GameOverSnake();
            sound.PlayEnd();
            Thread.Sleep(5000);
            new EndScore(count.GetScore(), settings.GetResourceFolder());
        }
コード例 #18
0
        static void Main(string[] args)
        {
            const int MAP_WIDTH  = 80;
            const int MAP_HEIGHT = 25;

            Console.SetWindowSize(MAP_WIDTH, MAP_HEIGHT + 2);
            Console.SetBufferSize(MAP_WIDTH, MAP_HEIGHT + 2);

            Walls walls = new Walls(MAP_WIDTH, MAP_HEIGHT);

            walls.Draw();

            DrawScore(MAP_HEIGHT, 0);

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

            snake.Draw();

            FoodCreator foodCreator = new FoodCreator(MAP_WIDTH, MAP_HEIGHT, '$');
            Point       food        = foodCreator.CreateFood();

            food.Draw();

            while (true)
            {
                if (walls.IsHit(snake) || snake.IsHitTail())
                {
                    DrawGameOver();
                    DrawScore(1, snake.Score);
                    break;
                }
                if (snake.Eat(food))
                {
                    food = foodCreator.CreateFood();
                    food.Draw();
                    DrawScore(MAP_HEIGHT, snake.Score);
                }
                else
                {
                    snake.Move();
                }

                Thread.Sleep(100);

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

            Console.ReadKey();
        }
コード例 #19
0
ファイル: Program.cs プロジェクト: Rogotch/Snake
        static void Main(string[] args)
        {
            //Начальное положение змейки
            Point p1 = new Point(1, 3, '*');

            //Создание и отрисовка стен-рамки
            Walls walls = new Walls(Console.WindowWidth, Console.WindowHeight);

            walls.Draw();

            //Создание и отрисовка змейки
            Snake snake = new Snake(p1, 4, Direction.Right);

            snake.Draw();

            //Создание генератора еды
            FoodCreator foodCreator = new FoodCreator(Console.WindowWidth - 1, Console.WindowHeight - 1, '$');
            Point       food        = foodCreator.CreateFood();

            food.Draw();

            //Отключение отображения курсора
            Console.CursorVisible = false;
            //Цикл игры
            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(true);
                    snake.HandleKey(key.Key);
                }
            }

            Console.ReadKey();
        }
コード例 #20
0
        static void Main(string[] args)
        {
            Console.SetWindowSize(1, 1);
            Console.SetBufferSize(80, 25);
            Console.SetWindowSize(80, 25);
            Console.CursorVisible = false;

            Console.WriteLine("Правила игры: Нельзя врезаться в стену. Чтобы змейка росла - нужно есть @!");
            Console.ReadLine();

            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();
                    snake.Draw();
                }
                else
                {
                    snake.Move();
                }

                Thread.Sleep(100);
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.HandleKey(key.Key);
                }
            }
            WriteGameOver();
            Console.ReadLine();
        }
コード例 #21
0
        static void Main(string[] args)
        {
            //размер окна
            Console.SetWindowSize(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.DrawLine();

            //еда
            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);
                }
            }
        }
コード例 #22
0
ファイル: Program.cs プロジェクト: Olejan/Snake
        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())
                {
                    break;
                }
                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(100);
            }
            Console.ForegroundColor = ConsoleColor.Yellow;
            int y = 9;

            WriteLine("============================", 26, y++);
            WriteLine("Game over", 35, y++);
            WriteLine("", 26, y += 2);
            WriteLine("Created by:  Oleg Glytenko", 28, y++);
            WriteLine("My first game!!!", 32, y++);
            WriteLine("============================", 26, y++);
            Console.SetCursorPosition(0, 0);
            Thread.Sleep(1000);
            Console.ReadKey();
        }
コード例 #23
0
        private static void Main(string[] args)
        {
            int x = 80, y = 25;

            Console.SetWindowSize(x, y);

            Walls walls = new Walls(x, y);

            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.SetCursorPosition(x / 2 - 5, y / 2);
                    Console.Write("GAME OVER!");
                    Console.ReadKey();
                    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);
                }
            }
        }
コード例 #24
0
ファイル: Program.cs プロジェクト: kirill8000/Snake
        static void Main(string[] args)
        {
            int x = 120;
            int y = 50;

            Console.SetWindowSize(x, y);
            Console.SetBufferSize(x, y);

            Walls walls = new Walls(x, y);

            walls.Draw();

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

            snake.Draw();

            FoodGenerator foodGenerator = new FoodGenerator(x, y, '$', new Random());
            Point         food          = foodGenerator.SpawnFood();
            int           score         = 0;

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

                if (snake.Eat(food))
                {
                    score++;
                    food = foodGenerator.SpawnFood();
                }
                else
                {
                    snake.Move();
                }

                Thread.Sleep(100);

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

            Console.SetCursorPosition(x / 2, y / 2);
            Console.WriteLine($"Game over. Score: {score}");
            Console.ReadKey();
        }
コード例 #25
0
        static void Main(string[] args)
        {
            Console.SetBufferSize(80, 25);
            Walls walls = new Walls(80, 25);

            walls.Draw();
            Point p = new Point(4, 5, '*');
            //List < Figure > figures= new List<Figure>() { new HorizontalLine(0, 78, 0, '+'),
            //new HorizontalLine(0, 78, 24, '+'),
            //new VerticalLine(0, 24, 0, '+'),
            //new VerticalLine(0, 24, 78, '+')
            //};
            //foreach (Figure f in figures)
            //{
            //    f.Draw();
            //}
            //HorizontalLine hl1 = new HorizontalLine(0, 78, 0, '+');
            //HorizontalLine hl2 = new HorizontalLine(0, 78, 24, '+');
            //VerticalLine vl1 = new VerticalLine(0, 24, 0, '+');
            //VerticalLine vl2 = new VerticalLine(0, 24, 78, '+');
            //hl1.Draw(); vl1.Draw(); hl2.Draw(); vl2.Draw();
            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);
                }
                Thread.Sleep(100); snake.Move();
            }
        }
コード例 #26
0
ファイル: Program.cs プロジェクト: SergeyKrukovskiy/Snake
        static void Main(string[] args)
        {
            //задание границ окна
            Console.SetWindowSize(80, 25);
            Console.SetBufferSize(80, 25);

            // границы карты
            Walls walls = new Walls(80, 25);

            walls.Draw();

            //создание еды
            FoodCreator foodCreator = new FoodCreator(80, 25, '$');
            Point       food        = foodCreator.CreateFood();

            food.Draw();

            //создание змейки
            Point d2    = new Point(6, 9, '*');
            Snake snake = new Snake(d2, 3, Directions.RIGHT);

            snake.Drow();

            //управляемое движение змейки
            while (true)
            {
                if (walls.IsHit(snake) || snake.IsHitTail())
                {
                    Console.Write("Игра закончена!");
                    Console.ReadLine();
                    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);
                }
            }
        }
コード例 #27
0
        static void Main(string[] args)
        {
            int mapWidth  = 80;
            int mapHeight = 50;

            Console.SetWindowSize(mapWidth, mapHeight);
            Console.SetBufferSize(mapWidth, mapHeight);

            Walls walls = new Walls(mapWidth, mapHeight);

            walls.Draw();


            Point p     = new Point(40, 25, '*');
            Snake snake = new Snake(p, 4, Direction.DOWN);

            snake.Draw();

            Food  foodCreator = new Food(mapWidth, mapHeight, '@');
            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();
        }
コード例 #28
0
ファイル: Program.cs プロジェクト: EnemySTVR/Snake
        static void Main()
        {
            System.Console.SetWindowSize(80, 26);
            Console.CursorVisible = false;

            var walls = new Walls(80, 25);

            walls.Draw();

            var startPoint = new Point(5, 5, '*');

            var snake = new Snake(startPoint, 4, Direction.Right);

            snake.Draw();

            ShowCounter(snake.GetCount());

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

            food.Draw();

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

                Thread.Sleep(100);

                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo keyInfo = Console.ReadKey();
                    snake.ChangeDirection(keyInfo.Key);
                }
            }
            ShowGameOverMessage();
            Console.ReadKey();
        }
コード例 #29
0
ファイル: Program.cs プロジェクト: foxthrottle/Snake2
        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();
            int sleep = 150;

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

                Thread.Sleep(sleep);
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.HandleKey(key.Key);
                }
            }
            WriteGameOver();
            Console.ReadLine();
        }
コード例 #30
0
ファイル: Program.cs プロジェクト: Senior-Pomidor/Snake
        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();

            Console.CursorVisible = false;

            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);
                }
            }
            // Console.ReadLine();
        }
コード例 #31
0
        static void Main(string[] args)
        {
            Walls walls = new Walls(80, 25);

            walls.Draw();


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

            snake.Draw();

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

            food.Draw();

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

                if (snake.Eat(food))
                {
                    food = foodCreator.CreatorFood();
                    food.Draw();
                }
                else
                {
                    snake.Move();
                }

                Thread.Sleep(100);

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

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


            Console.ReadLine();
        }
コード例 #32
0
ファイル: Program.cs プロジェクト: makspanshin/Snake
        static void Main(string[] args)
        {
            Console.CursorVisible = false;
            //Console.SetBufferSize(80, 25);
            Thread myThread = new Thread(new ThreadStart(MissionImpossible));
            Walls  walls    = new Walls(80, 25);

            myThread.Start(); // запускаем поток
            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();
        }
コード例 #33
0
ファイル: Program.cs プロジェクト: Olejan/Snake
        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())
                {
                    break;
                }
                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(100);
            }
            Console.ForegroundColor = ConsoleColor.Yellow;
            int y = 9;
            WriteLine("============================", 26, y++);
            WriteLine("Game over", 35, y++);
            WriteLine("", 26, y += 2);
            WriteLine("Created by:  Oleg Glytenko", 28, y++);
            WriteLine("My first game!!!", 32, y++);
            WriteLine("============================", 26, y++);
            Console.SetCursorPosition(0, 0);
            Thread.Sleep(1000);
            Console.ReadKey();
        }
コード例 #34
0
ファイル: Program.cs プロジェクト: UnSi/Snake
        static void Main(string[] args)
        {
            Console.SetBufferSize(Console.WindowWidth, Console.WindowHeight);

            // Рамка
            Walls walls = new Walls(Console.WindowWidth, Console.WindowHeight);
            walls.Draw();

            //Змея
            Point p = new Point(4,5);
            Snake snake = new Snake(p, 4, Direction.RIGHT);
            snake.Draw();

            //Еда
            FoodCreator foodCreator = new FoodCreator(Console.WindowWidth, Console.WindowHeight, '$');
            Point food = foodCreator.CreateFood();
            Console.ForegroundColor = ConsoleColor.Cyan;
            food.Draw();
            Console.ResetColor();

            //Двигаем
            while(true)
            {
                if (walls.IsHit(snake) || snake.IsHitTail())
                    break;
                if (snake.Eat(food))
                {
                    food = foodCreator.CreateFood();
                    Console.ForegroundColor = ConsoleColor.Cyan;
                    food.Draw();
                    Console.ResetColor();
                }
                else snake.Move();
                Thread.Sleep(200);
                if (Console.KeyAvailable)
                {
                    snake.HandleKey(Console.ReadKey().Key);
                }
            }
            Console.SetCursorPosition(Console.WindowWidth / 2, Console.WindowHeight / 2);
            snake.Clear();
            food.Clear();
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("Good Bye!");
            Console.ResetColor();
            Console.ReadLine();
        }
コード例 #35
0
ファイル: Program.cs プロジェクト: m44g11c/snake
        public static void Main(string[] args)
        {
            Walls walls = new Walls( 79, 24 );
            walls.Draw();

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

            FoodCreator foodCreator = new FoodCreator( 77, 22, '$' );
            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();
        }
コード例 #36
0
ファイル: Program.cs プロジェクト: Valentina-K/Snake
        static void Main(string[] args)
        {
            int t;
            Console.WriteLine("      Выберите свой уровень игры:\nвысокий - 1, средний - 2 или низкий - 3");
            ConsoleKeyInfo cinf= Console.ReadKey();
            t = (cinf.KeyChar - 48) * 100;
            Console.Clear();
            Console.SetBufferSize(80, 25);
            Walls wall = new Walls(80, 25);
            wall.Drow();

            Point p1 = new Point(3, 3, '*',ColorSnake.WHITE);
            Snake sn = new Snake(p1, 5, Direction.RIGHT);
            sn.Draw();
            FoodCreator fc = new FoodCreator(80, 25, '$',ColorSnake.YELLOW);
            Point food = fc.CreateFood();
            food.Draw();
            while (true)
            {
                if (wall.IsHit(sn) || sn.IsHitTail())
                    break;
                if (sn.Eat(food))
                {
                    food = fc.CreateFood();
                    food.Draw();
                }
                else
                    sn.Move();
                Thread.Sleep(t);

                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    sn.HandleKey(key.Key);
                }
            }
            Console.Clear();
            Console.WriteLine("   Игра окончена! \nСпасибо за внимание.");
            Console.ReadLine();
        }
コード例 #37
0
ファイル: Program.cs プロジェクト: hermes-jr/gb-lesson-snake
        static void Main(string[] args)
        {
            // Dimensions
            //int winW = Console.WindowWidth - 1;
            //int winH = Console.WindowHeight - 1;
            int winH = 20;
            int winW = 34;

            ushort level = 1;

            // Border
            Walls walls = new Walls(winW, winH);
            walls.Draw();

            // Snake
            Point tl = new Point(10, 10, '*');
            Snake snake = new Snake(tl, 3, Direction.RIGHT);

            // Food
            FoodFactory foodfactory = new FoodFactory(winH, winW, '$');
            Point food = foodfactory.createFood(snake);
            Console.ForegroundColor = ConsoleColor.Yellow;
            food.Draw();
            Console.ResetColor();

            // Infinite loop
            while (true)
            {
                if (walls.IsHit(snake) || snake.IsHitTail())
                {
                    // Snake dies
                    Console.SetCursorPosition(2, 2);
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.Write("Snake collapsed...");
                    break;
                }
                if (snake.Eat(food))
                {
                    food = foodfactory.createFood(snake);
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    food.Draw();
                    Console.ResetColor();
                    // level up every 5 feeds and level cap is 40 (121 - level * 3 must be > 0)
                    if (snake.length % 5 == 0 && level < 40)
                        level++;
                }
                else
                {
                    snake.Move();
                }
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey(true);
                    snake.HandleKey(key.Key);
                    if (key.Key == ConsoleKey.Q)
                        break; // Get the hell out of this infinite loop
                }

                // Thread.Sleep(80); // Control FPS here
                Thread.Sleep(121 - level * 3);

                Console.SetCursorPosition(2, 1);
                Console.Write("Length: " + snake.length + " Level: " + level);
            }

            // Print banner and wait for Enter key
            Console.ForegroundColor = ConsoleColor.Yellow;
            int endplaneX = Math.Abs((winW / 2) - 15);
            Console.SetCursorPosition(endplaneX, 7);
            Console.Write("===============================");
            Console.SetCursorPosition(endplaneX, 8);
            Console.Write("| Thank you for playing. Bye! |");
            Console.SetCursorPosition(endplaneX, 9);
            Console.Write("|   Press Enter key to quit.  |");
            Console.SetCursorPosition(endplaneX, 10);
            Console.Write("===============================");
            while (Console.ReadKey(true).Key != ConsoleKey.Enter) { }
        }
コード例 #38
0
ファイル: Program.cs プロジェクト: EugeneYuriev/Snake
        static void Main(string[] args)
        {
            int TARGET_SNAKE_LENGTH;
            int result;

            TARGET_SNAKE_LENGTH = 10;

            Console.SetBufferSize(80, 25);

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

            ShowMenu();

            while (true)
            {
                ConsoleKeyInfo action = Console.ReadKey();
                if (action.Key == ConsoleKey.S)
                {
                    Console.Clear();
                    walls.Draw();
                    result = 0;

                    Point p = new Point(40, 12, '*');
                    Snake snake = new Snake(p, 5, Direction.LEFT);
                    snake.Draw();

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

                    while (true)
                    {

                        if (walls.IsHit(snake) || snake.IsHitTail())
                        {
                            result = 0;
                            break;
                        }
                        if (snake.GetLength() >= TARGET_SNAKE_LENGTH)
                        {
                            result = 1;
                            break;
                        }
                        if (snake.Eat(food))
                        {
                            food = foodCreator.CreateFood();
                            food.Draw();
                        }
                        else
                        {
                            snake.Move();
                        }

                        Thread.Sleep(300);

                        if (Console.KeyAvailable)
                        {
                            ConsoleKeyInfo key = Console.ReadKey();
                            snake.HandleKey(key.Key);
                        }
                    }
                    Console.Clear();
                    walls.Draw();
                    ShowMenu();
                    if (result==1)
                        ShowMessage("ПОЗДРАВЛЯЕМ! ВЫ ВЫИГРАЛИ.");
                    else
                        ShowMessage("ВЫ ПРОИГРАЛИ. ПОПРОБУЙТЕ ЕЩЁ РАЗ.");
                }
                else if (action.Key == ConsoleKey.E)
                {
                    break;
                }
            }

            /*
            Console.SetCursorPosition(32, 12);
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("===============");
            Console.SetCursorPosition(33, 13);
            Console.WriteLine("ИГРА ОКОНЧЕНА");
            Console.SetCursorPosition(32, 14);
            Console.WriteLine("===============");
            Console.ReadLine();
            */
        }