コード例 #1
0
        static void Main(string[] args)
        {
            //Console.SetBufferSize(81, 26);

            Walls walls = new Walls(80, 25);

            walls.Drow();

            //Drowing points
            Point p     = new Point(2, 5, '*');
            Snake snake = new Snake(p, initialSnakesLength, 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);
                }
            }

            WriteGameOver(snake);
            Console.ReadLine();
        }
コード例 #2
0
        static void Main(string[] args)
        {
            Console.SetWindowSize(80, 25);
            Console.SetBufferSize(80, 25);

            Walls walls = new Walls(80, 25);

            walls.Drow();


            Point p1    = new Point(5, 5, '*');
            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);
                }
            }
        }
コード例 #3
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();
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: MND682/SNAKE
        static void Main(string[] args)
        {
            string a;
            int    b = 0;

            do
            {
                Console.WriteLine("Введите уровень сложности (легко, нормально, сложно)");
                a = Console.ReadLine();
                if ("ЛЕГКО" == a.ToUpper() || "нормально" == a.ToLower() || "сложно" == a.ToLower())
                {
                    b = 1;
                }
            } while (b != 1);
            Console.Clear();
            switch (a.ToLower())
            {
            case "легко":
                //задаю размер
                Console.SetBufferSize(200, 50);
                // граници поля ( стены )
                Walls walls = new Walls(20, 10);
                walls.Drow();
                //  сама змейка первые ее координаты
                Point p     = new Point(4, 5, '*');
                Snake snake = new Snake(p, 2, Direction.RIGHT);
                snake.Drow();

                FoodCreator foodCreator = new FoodCreator(20, 10, 'O');
                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();
                    }
                    System.Threading.Thread.Sleep(200);

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

            case "нормально":

                //задаю размер
                Console.SetBufferSize(200, 50);
                // граници поля ( стены )
                Walls walls1 = new Walls(30, 15);
                walls1.Drow();
                //  сама змейка первые ее координаты
                Point p1     = new Point(4, 5, '*');
                Snake snake1 = new Snake(p1, 2, Direction.RIGHT);
                snake1.Drow();

                FoodCreator foodCreator1 = new FoodCreator(30, 15, 'O');
                Point       food1        = foodCreator1.CreateFood();
                food1.Draw();

                while (true)
                {
                    if (walls1.IsHit(snake1) || snake1.IsHitTail())
                    {
                        break;
                    }

                    if (snake1.Eat(food1))
                    {
                        food = foodCreator1.CreateFood();
                        food.Draw();
                    }
                    else
                    {
                        snake1.Move();
                    }
                    System.Threading.Thread.Sleep(160);

                    if (Console.KeyAvailable)
                    {
                        ConsoleKeyInfo key = Console.ReadKey();
                        snake1.dvig(key.Key);
                    }
                }

                break;

            case "сложно":

                //задаю размер
                Console.SetBufferSize(200, 50);
                // граници поля ( стены )
                Walls walls2 = new Walls(30, 15);
                walls2.Drow();
                //  сама змейка первые ее координаты
                Point p2     = new Point(4, 5, '*');
                Snake snake2 = new Snake(p2, 2, Direction.RIGHT);
                snake2.Drow();

                FoodCreator foodCreator2 = new FoodCreator(40, 20, 'O');
                Point       food2        = foodCreator2.CreateFood();
                food2.Draw();

                while (true)
                {
                    if (walls2.IsHit(snake2) || snake2.IsHitTail())
                    {
                        break;
                    }

                    if (snake2.Eat(food2))
                    {
                        food = foodCreator2.CreateFood();
                        food.Draw();
                    }
                    else
                    {
                        snake2.Move();
                    }
                    System.Threading.Thread.Sleep(100);

                    if (Console.KeyAvailable)
                    {
                        ConsoleKeyInfo key = Console.ReadKey();
                        snake2.dvig(key.Key);
                    }
                }

                break;

            default:
                break;
            }



            Console.WriteLine(" ");
            Console.WriteLine("       /> _  >");
            Console.WriteLine("      |  _  _|");
            Console.WriteLine("     /`Z _x Z  ");
            Console.WriteLine("     /       |");
            Console.WriteLine("   /  \\     )                ");
            Console.WriteLine(" / |    | | |   _      _     ");
            Console.WriteLine(" | ( \\__\\_)_)    \\____/    ");
            Console.WriteLine(" \_)");
            Console.WriteLine(" ");
            Console.WriteLine("                                 Game Over");

            System.Threading.Thread.Sleep(1000);
            Console.Clear();
        }
コード例 #5
0
        static void Main(string[] args)
        {
            //Console.SetBufferSize(80, 25);


            FoodCreator foodCreator = new FoodCreator(70, 15, '^');
            Point       food        = foodCreator.CreateFood();

            food.Drow();

            Point p     = new Point(10, 10, '*');
            Snake snake = new Snake(p, 2, Direction.RIGHT);
            Walls walls = new Walls(80, 25);

            walls.Drow();
            snake.Drow();

            while (true)
            {
                if (walls.IsHit(snake) || snake.IsHitTail())
                {
                    break;
                }
                if (snake.Eat(food))
                {
                    food = foodCreator.CreateFood();
                    food.Drow();
                }
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.Mandlekey(key.Key);
                }
                Thread.Sleep(100);
                snake.Move();
            }


            //Point p2 = new Point(4,5,'%');

            //Point cp1 = new Point(11, 5, '#');
            //Point cp2 = new Point(-3, 15, '#');
            //Point cp3 = new Point(6, 0, '#');
            //Point cp4 = new Point(2, 10, '#');

            //p2.Drow();
            //List<Point> pList = new List<Point>();
            //pList.Add(p1);
            //pList.Add(p2);

            //List<Point> Cheef = new List<Point>();
            //Cheef.Add(cp1);
            //Cheef.Add(cp2);
            //Cheef.Add(cp3);

            //List<char> sym = new List<char>();
            //sym.Add('*');
            //sym.Add('$');
            //sym.Add('@');
            //char sym1 = sym[0];
            //char sym2 = sym[1];
            //char sym3 = sym[2];

            //List<int> numList = new List<int>();
            //numList.Add(0);
            //numList.Add(1);
            //numList.Add(2);
            //int x = numList[0];
            //int y = numList[1];
            //int z = numList[2];

            //Console.ReadLine();
        }