Exemplo n.º 1
0
        /// <summary>
        /// Creates a new MenuChoice object
        /// </summary>
        /// <param name="synopsis">Choice synopsis</param>
        /// <param name="options">Possible options to choose from</param>
        /// <param name="baseChoice">Base choice in a choice tree</param>
        public MenuChoice(List <string> synopsis, List <ChoiceOption> options, MenuChoice baseChoice)
        {
            this.synopsis = synopsis;
            this.options  = options;

            this.baseChoice = baseChoice;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a new MenuChoice object
        /// </summary>
        /// <param name="synopsis">Choice synopsis</param>
        /// <param name="options">Possible options to choose from</param>
        public MenuChoice(List <string> synopsis, List <ChoiceOption> options)
        {
            this.synopsis = synopsis;
            this.options  = options;

            baseChoice = this;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates a ChoiceOption object from text
        /// </summary>
        /// <param name="screen">Screen that holds this option</param>
        /// <param name="lines">Lines of text that represent an option</param>
        /// <returns></returns>
        public static ChoiceOption OptionFromText(MenuChoiceScreen screen, List <string> lines, ScreenManager manager)
        {
            int    lineNum   = 0;
            bool   endOfLine = false;
            string synopsis;
            Action action = null;
            Dictionary <GameItem, int> itemRequirements  = new Dictionary <GameItem, int>();
            Dictionary <Currency, int> moneyRequirements = new Dictionary <Currency, int>();
            Dictionary <string, int>   varRequirements   = new Dictionary <string, int>();
            bool invisible = false;

            synopsis = lines[lineNum];
            lineNum++;

            if (lineNum >= lines.Count)
            {
                endOfLine = true;
            }

            //Loop through action lines
            while (!endOfLine)
            {
                string[] lineParts = lines[lineNum].Split(new string[] { " " }, StringSplitOptions.None);

                switch (lineParts[0].ToLower())
                {
                case "invisible":
                    invisible = true;
                    break;

                case "require":
                {
                    lineParts[1] = lineParts[1].ToLower();

                    if (lineParts[1] == "var")
                    {
                        int value;
                        if (!int.TryParse(lineParts[3], out value))
                        {
                            break;
                        }

                        varRequirements.Add(lineParts[2], value);
                        break;
                    }

                    int count;
                    if (!int.TryParse(lineParts[2], out count))
                    {
                        break;
                    }

                    switch (lineParts[1])
                    {
                    case "credits":
                        moneyRequirements.Add(Currency.credits, count);
                        break;

                    case "jex":
                        moneyRequirements.Add(Currency.jex, count);
                        break;

                    default:
                        itemRequirements.Add(GameItem.Parse(lineParts[1]), count);
                        break;
                    }
                }
                break;

                case "var":
                {
                    int count;
                    if (!int.TryParse(lineParts[3], out count))
                    {
                        break;
                    }

                    switch (lineParts[1].ToLower())
                    {
                    case "set":
                        action += () => PlayerData.SetVariable(lineParts[2], count);
                        break;

                    case "add":
                        action += () => PlayerData.SetVariable(lineParts[2], PlayerData.GetVariable(lineParts[2]) + count);
                        break;
                    }
                }
                break;

                case "credits":
                {
                    int amount;
                    if (!int.TryParse(lineParts[1], out amount))
                    {
                        break;
                    }

                    action += () => PlayerData.AddMoney(Currency.credits, amount);
                }
                break;

                case "jex":
                {
                    int amount;
                    if (!int.TryParse(lineParts[1], out amount))
                    {
                        break;
                    }

                    action += () => PlayerData.AddMoney(Currency.jex, amount);
                }
                break;

                case "get":
                {
                    int count;
                    if (!int.TryParse(lineParts[2], out count))
                    {
                        break;
                    }

                    action += () =>
                    {
                        for (int i = 0; i < count; i++)
                        {
                            PlayerData.inventory.Add(GameItem.Parse(lineParts[1]));
                        }
                    };
                }
                break;

                case "remove":
                {
                    int count;
                    if (!int.TryParse(lineParts[2], out count))
                    {
                        break;
                    }

                    action += () =>
                    {
                        for (int i = 0; i < count; i++)
                        {
                            PlayerData.inventory.Remove(GameItem.Parse(lineParts[1]));
                        }
                    };
                }
                break;

                case "enemy":
                    int   level;
                    float pos = Math.Abs(PlayerData.ship.position.X) + Math.Abs(PlayerData.ship.position.Y);

                    if (pos < 10000)
                    {
                        level = 1;
                    }
                    else if (pos < 30000)
                    {
                        level = 2;
                    }
                    else
                    {
                        level = 3;
                    }

                    action += () => manager.Push(new BattleScreen(PlayerData.ship, level));
                    break;

                case "return":
                    action += () => screen.currentChoice = screen.currentChoice.baseChoice;
                    break;

                case "choice":
                    lineNum += 2;

                    if (lineNum >= lines.Count)
                    {
                        endOfLine = true;
                    }

                    List <string> choiceLines = new List <string>();

                    while (!endOfLine)
                    {
                        choiceLines.Add(lines[lineNum]);
                        lineNum++;

                        if (lineNum >= lines.Count)
                        {
                            endOfLine = true;
                        }
                    }
                    lineNum++;

                    action += () => screen.currentChoice = MenuChoice.ChoiceFromText(screen, choiceLines, manager, screen.currentChoice.baseChoice);

                    break;

                case "exit":
                    action += () => manager.Pop();
                    break;

                case "gameover":
                    action += () =>
                    {
                        MainGame.eventLogger.Log(typeof(ChoiceOption), "Game Over!");

                        manager.Pop();
                        manager.Pop();

                        if (File.Exists("saveData.sav"))
                        {
                            File.Delete("saveData.sav");
                        }

                        MainGame.eventLogger.Log(typeof(ChoiceOption), "Deleted save data at: saveData.sav");
                    };
                    break;
                }

                lineNum++;
                if (lineNum >= lines.Count)
                {
                    endOfLine = true;
                }
            }

            return(new ChoiceOption(synopsis, action, itemRequirements, moneyRequirements, varRequirements, invisible, manager));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates a MenuChoice object from text.
        /// </summary>
        /// <param name="screen">Screen that holds this choice</param>
        /// <param name="lines">Lines of text that represent a choice</param>
        /// <param name="baseChoice">The original choice in a choice tree</param>
        /// <returns></returns>
        public static MenuChoice ChoiceFromText(MenuChoiceScreen screen, List <string> lines, ScreenManager manager, MenuChoice baseChoice = null)
        {
            int                 lineNum   = 0;
            bool                endOfLine = false;
            List <string>       synopsis  = new List <string>();
            List <ChoiceOption> options   = new List <ChoiceOption>();

            //Loop through lines that make up the Choice synopsis
            while (!endOfLine && !lines[lineNum].ToLower().StartsWith(">"))
            {
                synopsis.Add(lines[lineNum]);
                lineNum++;

                if (lineNum >= lines.Count)
                {
                    endOfLine = true;
                }
            }

            //Loop through the options for this choice
            while (!endOfLine)
            {
                List <string> optionLines = new List <string>();
                optionLines.Add(lines[lineNum]);
                lineNum++;

                int choiceLevels = 1;

                while (!endOfLine && (!lines[lineNum].StartsWith(">") || choiceLevels > 1))
                {
                    if (lines[lineNum].StartsWith("choice"))
                    {
                        choiceLevels++;
                    }
                    else if (lines[lineNum].StartsWith("}"))
                    {
                        choiceLevels--;
                    }

                    optionLines.Add(lines[lineNum]);
                    lineNum++;

                    if (lineNum >= lines.Count)
                    {
                        endOfLine = true;
                    }
                }

                options.Add(ChoiceOption.OptionFromText(screen, optionLines, manager));

                if (lineNum >= lines.Count)
                {
                    endOfLine = true;
                }
            }

            if (baseChoice != null)
            {
                return(new MenuChoice(synopsis, options, baseChoice));
            }
            else
            {
                return(new MenuChoice(synopsis, options));
            }
        }