Exemplo n.º 1
0
 /// <summary>
 /// Adds a level to the list.
 /// </summary>
 /// <param name="level">The level to add to the list.</param>
 /// <exception cref="NullReferenceException">Thrown if a null level, or a level with a GUID equivalent to Guid.Empty, is passed in.</exception>
 public static void InsertLevel(AenigmaLevel level)
 {
     if (level?.ID != Guid.Empty)
     {
         levels.Add(level);
     }
     else
     {
         throw new NullReferenceException("Tried to add an empty or NULL level to the list.");
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Loads levels from a given directory.
 /// </summary>
 /// <param name="path">The path to load levels from.</param>
 /// <exception cref="LevelLoadException">Thrown if an error occurs while loading levels.</exception>
 public static void LoadLevelsFromDirectory(String path)
 {
     if (Directory.Exists(path))
     {
         foreach (string file in Directory.EnumerateFiles(path).Where(n => n.EndsWith(".stage")))
         {
             using (StreamReader sr = new StreamReader(file))
             {
                 try
                 {
                     levels.Add(AenigmaLevel.Deserialize(sr.ReadToEnd()));
                 }
                 catch (JsonReaderException jre)
                 {
                     throw new InvalidLevelDataException("", jre, file);
                 }
             }
         }
     }
     else
     {
         throw new LevelLoadException("The specified path does not exist.");
     }
 }
Exemplo n.º 3
0
        public static void JumpToLevel(AenigmaLevel level)
        {
            // Do some sanity checking on the level.
            if (level == null)
            {
                throw new InvalidLevelException("Cannot load a null level.");
            }

            if (level.ID == Guid.Empty)
            {
                throw new InvalidLevelException("Cannot load a level with an empty GUID.");
            }

            if (string.IsNullOrEmpty(level.Data) || string.IsNullOrWhiteSpace(level.Data))
            {
                throw new InvalidLevelException("Cannot load a level with no level data.");
            }

            CurrentLevel = level;

            // Reset the lives counter to 3.
            NumberOfLives = 3;

            // If this is the starting level, then increment the attempts counter and set the "last played" time.
            if (CurrentLevel.Password != null && CurrentLevel.Password.ToLower() == "start")
            {
                NumberOfAttempts++;
                AenigmaMenuUtils.LastPlayed = DateTime.UtcNow;
            }

            // Draw the level data.
            Console.Clear();
            AenigmaUtils.SlowPrint(level.Data, 0);

            HandleLevel(CurrentLevel);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Run through the main menu.
        /// </summary>
        public static void HandleMainMenu()
        {
            ClearBox();

            WriteLineToBox($"[Connected to Aenigma BBS via {PhoneNumber}]");
            WriteLineToBox("[INFO // https://aenigma.mynameistavis.com]");
            WriteLineToBox("[INFO // Retrieving data from BBS...]");

            int amountLoaded = 0;

            while (amountLoaded < 126)
            {
                if (amountLoaded >= 114)
                {
                    amountLoaded += (126 - amountLoaded);
                }

                WriteStatusMessage($"Downloaded {amountLoaded} / 126 KB.");

                amountLoaded += new Random().Next(5, 12);
                Thread.Sleep(300);
            }

            CurrentUsers = new Random().Next(30, 90);


            using (StreamReader sr = new StreamReader("boot/main_menu.txt"))
            {
                string line;
                while ((line = sr.ReadLine()) != null)
                {
                    if (line.Contains("{0}"))
                    {
                        line = string.Format(line, LifetimeAttempts,
                                             (LastPlayed != DateTime.MinValue) ? LastPlayed.ToString("HH:mm dd/MM/yy") : "00:00 00/00/00",
                                             CurrentUsers);
                    }

                    line = line.Replace("{color_begin}", "\x1B[0;32m");
                    line = line.Replace("{color_end}", "\x1B[0m");

                    WriteLineToBox(line, 0);
                }
            }

            ClearStatusMessage();

            Console.SetCursorPosition(14, 46);

            AenigmaLevel nextLevel            = null;
            int          LastNumberOfTimeouts = NumberOfTimeouts;

            while (nextLevel == null && LastNumberOfTimeouts == NumberOfTimeouts)
            {
                string password = AenigmaUtils.ReadLine();

                if (password == "sudoritual2216")
                {
                    Environment.Exit(255);
                }

                if (password == "sudoritual2217")
                {
                    BeginBootSequence();
                }

                try
                {
                    nextLevel = AenigmaLevelManager.GetLevelByPassword(password);
                }
                catch (LevelNotFoundException)
                {
                    FailedLoginAttempts++;
                    if (FailedLoginAttempts >= 3)
                    {
                        AenigmaMenuUtils.WriteStatusMessage(
                            "Whatever it is you're doing, please stop it and just type \"start\".");
                    }
                    else
                    {
                        AenigmaMenuUtils.WriteStatusMessage("Invalid password!");
                    }

                    Console.SetCursorPosition(14, 46);
                    for (int i = 0; i < password?.Length; i++)
                    {
                        Console.Write(" ");
                    }
                    Console.SetCursorPosition(14, 46);
                }
            }

            FailedLoginAttempts = 0;
            LifetimeAttempts   += 1;

            if (LastNumberOfTimeouts != NumberOfTimeouts)
            {
                return;
            }

            AenigmaLevelHandler.JumpToLevel(nextLevel);
        }
Exemplo n.º 5
0
        public static AenigmaLevel Deserialize(string json)
        {
            AenigmaLevel tmp = JsonConvert.DeserializeObject<AenigmaLevel>(json);

            return tmp;
        }
Exemplo n.º 6
0
        public static void HandleLevel(AenigmaLevel level)
        {
            AenigmaLevel nextLevel = AenigmaLevelManager.GetLevelById(level.NextStage);

            if (level.LevelType == AenigmaLevelType.Level)
            {
                Console.SetCursorPosition(107, 43);
                Console.Write("   ");
                Console.SetCursorPosition(107, 43);
                for (int i = 0; i < NumberOfLives; i++)
                {
                    Console.Write("X");
                }

                int LastNumberOfTimeouts = AenigmaMenuUtils.NumberOfTimeouts;
                while (NumberOfLives > 0 && LastNumberOfTimeouts == AenigmaMenuUtils.NumberOfTimeouts)
                {
                    string response = HandleLevelUserInput();

                    if (response.ToLower().Equals(level.CorrectAnswer.ToLower()))
                    {
                        break;
                    }

                    else
                    {
                        NumberOfLives -= 1;

                        Console.SetCursorPosition(107, 43);
                        Console.Write("   ");
                        Console.SetCursorPosition(107, 43);
                        for (int i = 0; i < NumberOfLives; i++)
                        {
                            Console.Write("X");
                        }

                        Thread.Sleep(1000);
                    }
                }
            }
            else if (level.LevelType == AenigmaLevelType.Cutscene)
            {
                if (level.ID != Guid.Parse("994495c4-7bef-4e39-a449-55a3d39743fa") && level.ID != Guid.Parse("38f677db-e167-4f9e-be18-a5def9b7a683"))
                {
                    AenigmaMenuUtils.WriteStatusMessage("Press ENTER to continue.");
                }

                Console.ReadKey(true);
                AenigmaMenuUtils.TimeSinceInputAttempts = 0;
            }

            if (NumberOfLives == 0)
            {
                AenigmaMenuUtils.WriteStatusMessage("You have been banned. Reason: Brute forcing.");
                Thread.Sleep(1000);

                AenigmaMenuUtils.HandleMainMenu();
            }
            else
            {
                NumberOfLives = 3;
                if (!nextLevel.IsFinalStage)
                {
                    JumpToLevel(nextLevel);
                }
                else
                {
                    AenigmaMenuUtils.HandleMainMenu();
                }
            }
        }