예제 #1
0
        static void Main(string[] args)
        {
            string[,] map = new string[width, height];
            string e     = "Легко";
            string m     = "Средний";
            string h     = "Сложный";
            int    menu  = 0;
            bool   start = false;

            Console.WriteLine("Выберете сложность (стрелки вверх и вниз) и нажмите Enter");
            while (start == false)
            {
                if (menu == 0)
                {
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.SetCursorPosition(0, 1);
                    Console.WriteLine(e);
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.SetCursorPosition(0, 2);
                    Console.WriteLine(m);
                    Console.SetCursorPosition(0, 3);
                    Console.WriteLine(h);
                }
                else if (menu == 1)
                {
                    Console.SetCursorPosition(0, 1);
                    Console.WriteLine(e);
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.SetCursorPosition(0, 2);
                    Console.WriteLine(m);
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.SetCursorPosition(0, 3);
                    Console.WriteLine(h);
                }
                else if (menu == 2)
                {
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.SetCursorPosition(0, 1);
                    Console.WriteLine(e);
                    Console.SetCursorPosition(0, 2);
                    Console.WriteLine(m);
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.SetCursorPosition(0, 3);
                    Console.WriteLine(h);
                    Console.ForegroundColor = ConsoleColor.White;
                }
                if (Console.KeyAvailable == true)
                {
                    f = Console.ReadKey();
                    if (f.Key == ConsoleKey.UpArrow)
                    {
                        if (menu != 0)
                        {
                            --menu;
                        }
                    }
                    if (f.Key == ConsoleKey.DownArrow)
                    {
                        if (menu != 2)
                        {
                            ++menu;
                        }
                    }
                    if (f.Key == ConsoleKey.Enter)
                    {
                        start = true;
                    }
                }
            }
            Console.Clear();


            if (menu == 0)
            {
                width  = 10;
                height = 10;
                map    = new string[width, height];
                speed  = 400;
            }
            else if (menu == 1)
            {
                width  = 15;
                height = 15;
                map    = new string[width, height];
                speed  = 250;
            }
            else if (menu == 2)
            {
                width  = 20;
                height = 20;
                map    = new string[width, height];
                speed  = 100;
            }
            Random rnd = new Random();

            headX = width / 2; headY = height / 2;
            while (true)
            {
                fruitX = rnd.Next(1, width - 2); fruitY = rnd.Next(1, height - 2);
                if (fruitX == headX && fruitY == headY || fruitX != headX && fruitY == headY || fruitX != headX && fruitY != headY)
                {
                    break;
                }
            }
            while (game == true)
            {
                Game.Draw(width, height, ref headX, ref headY, ref fruitX, ref fruitY, ref map);
                Game.Move(width, height, ref headX, ref headY, move, ref map);
                Game.EatGenerate(ref score, width, height, ref map, headX, headY, ref fruitX, ref fruitY, ref eat, masX, masY);
                Game.Tail(ref masX, ref masY, ref map, ref eat, ref size, headX, headY);
                Game.Lose(width, height, masX, masY, headX, headY, ref game, size);
                Game.Win(width, height, map, ref game);
                for (int i = 0; i < width; i++)
                {
                    for (int j = 0; j < height; j++)
                    {
                        Console.SetCursorPosition(j, i);
                        Console.Write(map[i, j]);
                    }
                    Console.WriteLine();
                }
                Console.SetCursorPosition(0, height);
                Console.WriteLine("Длина змейки: " + size);

                if (Console.KeyAvailable == true)
                {
                    f = Console.ReadKey();
                    if (f.Key == ConsoleKey.UpArrow)
                    {
                        if (move != "Down")
                        {
                            move = "Up";
                        }
                    }
                    if (f.Key == ConsoleKey.DownArrow)
                    {
                        if (move != "Up")
                        {
                            move = "Down";
                        }
                    }
                    if (f.Key == ConsoleKey.RightArrow)
                    {
                        if (move != "Left")
                        {
                            move = "Right";
                        }
                    }
                    if (f.Key == ConsoleKey.LeftArrow)
                    {
                        if (move != "Right")
                        {
                            move = "Left";
                        }
                    }
                }
                Thread.Sleep(speed);
            }
        }