예제 #1
0
 public HighScores Sort(HighScores highScores)
 {
     for (int i = 0; i < highScores.name.Count - 1; i++)
     {
         for (int j = i + 1; j < highScores.name.Count; j++)
         {
             if (highScores.score[i] < highScores.score[j])
             {
                 string a = highScores.name[i];
                 int    b = highScores.score[i];
                 highScores.name[i]  = highScores.name[j];
                 highScores.score[i] = highScores.score[j];
                 highScores.name[j]  = a;
                 highScores.score[j] = b;
             }
         }
     }
     return(highScores);
 }
예제 #2
0
        public void OpenMenu()
        {
            DirectoryInfo directoryInfo = new DirectoryInfo(@"C:\Users\Адиль\Desktop\PP2_LABS\Snake\Levels");

            maxLevel = directoryInfo.GetFileSystemInfos().Length;
            int           cursor = 0;
            List <string> menu   = new List <string>();

            menu.Add("Start game");
            menu.Add("Leader board");
            menu.Add("Choose difficulty level");
            menu.Add("Exit");
            while (true)
            {
                for (int i = 0; i < 4; i++)
                {
                    if (i == cursor)
                    {
                        Console.ForegroundColor = ConsoleColor.DarkCyan;
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                    }
                    Console.WriteLine(menu[i]);
                }
                ConsoleKeyInfo key = Console.ReadKey();
                if (key.Key == ConsoleKey.UpArrow)
                {
                    cursor--;
                }
                if (key.Key == ConsoleKey.DownArrow)
                {
                    cursor++;
                }
                if (cursor == -1)
                {
                    cursor = 3;
                }
                if (cursor == 4)
                {
                    cursor = 0;
                }
                Console.Clear();
                for (int i = 0; i < 4; i++)
                {
                    if (i == cursor)
                    {
                        Console.ForegroundColor = ConsoleColor.DarkCyan;
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                    }
                    Console.WriteLine(menu[i]);
                }
                Console.Clear();
                if (key.Key == ConsoleKey.Enter)
                {
                    if (cursor == 1)
                    {
                        highScores = Sort(highScores);
                        for (int i = 0; i < highScores.name.Count; i++)
                        {
                            Console.Write(highScores.name[i]);
                            Console.Write(" - ");
                            Console.WriteLine(highScores.score[i]);
                        }
                        while (true)
                        {
                            ConsoleKeyInfo k = Console.ReadKey();
                            if (k.Key == ConsoleKey.Escape)
                            {
                                Console.Clear();
                                break;
                            }
                        }
                    }
                    if (cursor == 2)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("Press button to choose difficulty level");
                        Console.Write("Easy   : ");
                        Console.ForegroundColor = ConsoleColor.Gray;
                        Console.Write("OO");
                        Console.ForegroundColor = ConsoleColor.Yellow;
                        Console.Write("O");
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("  --->  Q");
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.Write("Normal : ");
                        Console.ForegroundColor = ConsoleColor.Cyan;
                        Console.Write("OO");
                        Console.ForegroundColor = ConsoleColor.Magenta;
                        Console.Write("O");
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("  --->  W");
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.Write("Hard   : ");
                        Console.ForegroundColor = ConsoleColor.DarkCyan;
                        Console.Write("OO");
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.Write("O");
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("  --->  E");
                        ConsoleKeyInfo k = Console.ReadKey();
                        if (k.Key == ConsoleKey.Q)
                        {
                            snakeBodyColor = ConsoleColor.Gray;
                            snakeHeadColor = ConsoleColor.Yellow;
                            speed          = 200;
                        }
                        if (k.Key == ConsoleKey.W)
                        {
                            snakeBodyColor = ConsoleColor.Cyan;
                            snakeHeadColor = ConsoleColor.Magenta;
                            speed          = 180;
                        }
                        if (k.Key == ConsoleKey.E)
                        {
                            snakeBodyColor = ConsoleColor.DarkCyan;
                            snakeHeadColor = ConsoleColor.Green;
                            speed          = 160;
                        }
                        Console.Clear();
                    }
                    if (cursor == 3)
                    {
                        break;
                    }
                    if (cursor == 0)
                    {
                        x        = 1; y = 0; sc = 0; levelCount = 1; score = 0;
                        wall     = new Wall();
                        snake    = new Snake();
                        playGame = true; moovable = false;
                        food     = new Food();
                        Thread t = new Thread(MoveSnakeThread);
                        t.Start();
                        while (true)
                        {
                            ConsoleKeyInfo k = new ConsoleKeyInfo();
                            k = Console.ReadKey();
                            if (k.Key == ConsoleKey.Escape)
                            {
                                break;
                            }
                            if ((k.Key == ConsoleKey.UpArrow || k.Key == ConsoleKey.W) && y != 1)
                            {
                                y = -1;
                                x = 0;
                            }
                            if ((k.Key == ConsoleKey.DownArrow || k.Key == ConsoleKey.S) && y != -1)
                            {
                                y = 1;
                                x = 0;
                            }
                            if ((k.Key == ConsoleKey.LeftArrow || k.Key == ConsoleKey.A) && x != 1)
                            {
                                x = -1;
                                y = 0;
                            }
                            if ((k.Key == ConsoleKey.RightArrow || k.Key == ConsoleKey.D) && x != -1)
                            {
                                x = 1;
                                y = 0;
                            }
                        }
                        Console.Clear();
                        playGame = false;
                    }
                }
            }
        }