Пример #1
0
        public GameScreen(XmlDocument saveFile) : base()
        {
            _quit = false;

            if (saveFile.HasChildNodes)
            {
                GameFile.LoadFile(saveFile);
            }
            else
            {
                GameFile.CreateFile();
            }

            Move(GameFile._roomID);
        }
Пример #2
0
        public static void CreateFile()
        {
            _roomID      = Data._startInfo.roomID;
            _spawnRoomID = Data._startInfo.spawnRoomID;
            _money       = Data._startInfo.money;

            for (int i = 0; i < Data._startInfo.unitIDs.Count(); i++)
            {
                _units.Add(UnitMaster.MakeUnit(Data._startInfo.unitIDs [i], Data._startInfo.unitLevels [i]));
            }

            for (int i = 0; i < Data._startInfo.itemIDs.Count(); i++)
            {
                for (int j = 0; j < Data._startInfo.itemAmounts [i]; j++)
                {
                    GameFile.AddItem(Data._startInfo.itemIDs [i]);
                }
            }
        }
Пример #3
0
        public MenuScreen() : base()
        {
            _topLine = 5;
            int selection = 0;

            AddSelections(new List <string> {
                Data._battleInfo.units, Data._battleInfo.bag, "Save", "About " + Data._generalInfo.title, "Quit"
            }, 0, true);

            while (selection != -1)
            {
                Clear(ClearType.Both);
                DrawScreenTitle("Menu");
                Write("  " + new string (' ', Data._generalInfo.width - Data._itemInfo.money.Length - 2 - GameFile._money.ToString().Length) + Data._itemInfo.money + ": " + GameFile._money.ToString(), 3, ConsoleColor.DarkYellow);

                selection = GetSelection(true, selection);

                if (selection == 0)
                {
                    if (GameFile._units.Count() > 0)
                    {
                        int selection2 = 0;

                        while (selection2 != -1)
                        {
                            MenuUnitsScreen mps = new MenuUnitsScreen(0);
                            selection2 = mps.GetSelection(true, selection2, new List <string> {
                                "Select", "Stats", "Swap", "Cancel"
                            });

                            if (selection2 != -1)
                            {
                                new MenuUnitScreen(GameFile._units [selection2]);
                            }
                        }
                    }
                    else
                    {
                        TypeWrite(Data._unitInfo.noUnitsText, ConsoleColor.DarkYellow, true, false, true);
                    }
                }
                else if (selection == 1)
                {
                    if (GameFile._items.Count() > 0)
                    {
                        MenuBagScreen mbs = new MenuBagScreen();
                        mbs.UseItemEvent -= onUseItem;
                        mbs.UseItemEvent += onUseItem;
                        mbs.Start();
                    }
                    else
                    {
                        TypeWrite(Data._itemInfo.noItemsText, ConsoleColor.DarkYellow, true, false, true);
                    }
                }
                else if (selection == 2)
                {
                    if (GameFile._fileName.Length == 0)
                    {
                        Clear(ClearType.Both);
                        Write(Helper.RCenterWrapped("  " + "Enter a name for your save file."), 3, ConsoleColor.DarkYellow);
                        int spaces = Data._generalInfo.width - 20;
                        Write("  " + new string (' ', spaces / 2) + new string ('-', 20), 7, ConsoleColor.DarkYellow);
                        Console.SetCursorPosition(spaces / 2 + 2, 6);
                        string     name = "";
                        ConsoleKey key  = ConsoleKey.Applications;

                        while (key != ConsoleKey.Enter)
                        {
                            key = Console.ReadKey(true).Key;

                            if ((name.Length == 0 || name.Replace(" ", "").Length == 0) && key == ConsoleKey.Enter)
                            {
                                key = ConsoleKey.EraseEndOfFile;
                            }

                            if (key != ConsoleKey.Backspace && Console.CursorLeft < spaces / 2 + 20 + 2)
                            {
                                if ("ABCDEFGHIJKLMNOPQRSTUVWXYZ".Contains(key.ToString()))
                                {
                                    Console.Write(key.ToString().ToLower());
                                    name += key.ToString().ToLower();
                                }
                                else if ("1234567890".Contains(key.ToString().Substring(1)))
                                {
                                    Console.Write(key.ToString().Substring(1));
                                    name += key.ToString().Substring(1);
                                }
                                else if (key == ConsoleKey.Spacebar)
                                {
                                    Console.Write(" ");
                                    name += " ";
                                }
                            }
                            else if (key == ConsoleKey.Backspace && Console.CursorLeft > spaces / 2 + 2)
                            {
                                Console.CursorLeft = Console.CursorLeft - 1;
                                Console.Write(" ");
                                Console.CursorLeft = Console.CursorLeft - 1;
                                name = name.Substring(0, name.Length - 1);
                            }
                        }

                        GameFile._fileName = name;
                    }

                    GameFile.SaveFile();
                }
                else if (selection == 3)
                {
                    new CreditsScreen();
                }
                else if (selection == 4)
                {
                    GameFile.ClearAll();
                    GameScreen._quit = true;
                    break;
                }
            }
        }
Пример #4
0
        private bool HandleOptionItem(OptionItem ifAction, List <OptionItem> ifActionList)
        {
            if (ifAction.GetType() == typeof(Loop))
            {
                Loop loop = (Loop)ifAction;

                for (int i = 0; i < loop.repeat; i++)
                {
                    ifActionList.InsertRange(ifActionList.IndexOf(ifAction) + 1, loop.items);
                }

                return(false);
            }
            else if (ifAction.GetType() == typeof(OptionCondition))
            {
                OptionCondition condition = (OptionCondition)ifAction;
                bool            isTrue    = false;

                switch (condition.comparison)
                {
                case OptionCondition.Comparison.MoneyGreaterThan:
                    if (GameFile._money > Convert.ToInt32(condition.expression))
                    {
                        isTrue = true;
                    }

                    break;

                case OptionCondition.Comparison.MoneyLessThan:
                    if (GameFile._money < Convert.ToInt32(condition.expression))
                    {
                        isTrue = true;
                    }

                    break;

                case OptionCondition.Comparison.AllUnitsDead:
                    if (UnitMaster.AllDead())
                    {
                        isTrue = true;
                    }

                    break;

                case OptionCondition.Comparison.LastBattleWon:
                    if (GameFile._lastBattleWon)
                    {
                        isTrue = true;
                    }

                    break;

                case OptionCondition.Comparison.HasItem:
                    if (GameFile._items.Exists(item => item.itemId == Convert.ToInt32(condition.expression.Substring(0, condition.expression.IndexOf("-")))))
                    {
                        List <ItemStack> stacks = GameFile._items.FindAll(item => item.itemId == Convert.ToInt32(condition.expression.Substring(0, condition.expression.IndexOf("-"))));
                        int count = 0;

                        foreach (ItemStack stack in stacks)
                        {
                            count += stack.amount;

                            if (count >= Convert.ToInt32(condition.expression.Substring(condition.expression.IndexOf("-") + 1)))
                            {
                                isTrue = true;
                                break;
                            }
                        }
                    }

                    break;

                case OptionCondition.Comparison.HasUnit:
                    if (GameFile._units.Exists(unit => unit.id == Convert.ToInt32(condition.expression)))
                    {
                        isTrue = true;
                    }

                    break;

                case OptionCondition.Comparison.HasLevelRange:
                    if (GameFile._units.Exists(unit => unit.level >= Convert.ToInt32(condition.expression.Substring(0, condition.expression.IndexOf("-"))) && unit.level <= Convert.ToInt32(condition.expression.Substring(condition.expression.IndexOf("-") + 1))))
                    {
                        isTrue = true;
                    }

                    break;
                }

                if (isTrue)
                {
                    ifActionList.InsertRange(ifActionList.IndexOf(ifAction) + 1, condition.trueItems);
                }
                else
                {
                    ifActionList.InsertRange(ifActionList.IndexOf(ifAction) + 1, condition.falseItems);
                }

                return(false);
            }
            else if (ifAction.GetType() == typeof(Action))
            {
                Action action = (Action)ifAction;

                switch (action.type)
                {
                case Action.Type.GetUnit:
                    Unit unit = UnitMaster.MakeUnit(Convert.ToInt32(action.vars ["unitID"]), Convert.ToInt32(action.vars ["unitLevel"]));
                    new GetUnitScreen(unit, action.vars ["text"], Boolean.Parse(action.vars ["canRename"]));
                    return(false);

                case Action.Type.GetItem:
                    for (int i = 0; i < Convert.ToInt32(action.vars ["amount"]); i++)
                    {
                        GameFile.AddItem(Convert.ToInt32(action.vars ["itemID"]));
                    }

                    return(false);

                case Action.Type.GetMoney:
                    GameFile._money += Convert.ToInt32(action.vars ["amount"]);
                    return(false);

                case Action.Type.LoseItem:
                    for (int i = 0; i < Convert.ToInt32(action.vars ["amount"]); i++)
                    {
                        GameFile.RemoveItem(Convert.ToInt32(action.vars ["itemID"]));
                    }

                    return(false);

                case Action.Type.LoseMoney:
                    if (GameFile._money <= Convert.ToInt32(action.vars ["amount"]))
                    {
                        GameFile._money = 0;
                    }
                    else
                    {
                        GameFile._money -= Convert.ToInt32(action.vars ["amount"]);
                    }

                    return(false);

                case Action.Type.UnitGainEXP:
                    if (GameFile._units.Count() > 0)
                    {
                        if (GameFile._units [0].level == Data._unitInfo.maxLevel && GameFile._units [0].exp == GameFile._units [0].expNext - 1)
                        {
                            TypeWrite(BuildText(Data._unitInfo.cannotLevelUpText, GameFile._units [0]), ConsoleColor.DarkYellow, true, false, true);
                            break;
                        }
                        else
                        {
                            decimal expBefore = GameFile._units [0].exp;
                            UnitMaster.IncreaseEXPEvent -= onIncreaseEXP;
                            UnitMaster.IncreaseEXPEvent += onIncreaseEXP;
                            UnitMaster.LevelUpEvent     -= onLevelUp;
                            UnitMaster.LevelUpEvent     += onLevelUp;

                            if (GameFile._units [0].hpLeft > 0)
                            {
                                UnitMaster.IncreaseEXP(GameFile._units [0], Convert.ToInt32(action.vars ["amount"]), true);

                                if (GameFile._units [0].exp - expBefore < Convert.ToDecimal(action.vars ["amount"]))
                                {
                                    TypeWrite(BuildText(Data._unitInfo.cannotLevelUpText, GameFile._units [0]), ConsoleColor.DarkYellow, true, false, true);
                                }
                            }
                        }

                        return(false);
                    }
                    else
                    {
                        TypeWrite(Data._battleInfo.noUnitsText, ConsoleColor.DarkYellow, true, false, true);
                        return(true);
                    }

                case Action.Type.AllUnitsGainEXP:
                    if (GameFile._units.Count() > 0)
                    {
                        UnitMaster.IncreaseEXPEvent -= onIncreaseEXP;
                        UnitMaster.IncreaseEXPEvent += onIncreaseEXP;
                        UnitMaster.LevelUpEvent     -= onLevelUp;
                        UnitMaster.LevelUpEvent     += onLevelUp;

                        foreach (Unit u in GameFile._units)
                        {
                            if (u.level == Data._unitInfo.maxLevel && u.exp == u.expNext - 1)
                            {
                                TypeWrite(BuildText(Data._unitInfo.cannotLevelUpText, u), ConsoleColor.DarkYellow, true, false, true);
                                break;
                            }
                            else
                            {
                                if (u.hpLeft > 0)
                                {
                                    decimal expBefore = u.exp;
                                    UnitMaster.IncreaseEXP(u, Convert.ToInt32(action.vars ["amount"]), true);

                                    if (u.exp - expBefore < Convert.ToDecimal(action.vars ["amount"]))
                                    {
                                        TypeWrite(BuildText(Data._unitInfo.cannotLevelUpText, u), ConsoleColor.DarkYellow, true, false, true);
                                    }
                                }
                            }
                        }

                        return(false);
                    }
                    else
                    {
                        TypeWrite(Data._battleInfo.noUnitsText, ConsoleColor.DarkYellow, true, false, true);
                        return(true);
                    }

                case Action.Type.UnitLevelUp:
                    if (GameFile._units.Count() > 0)
                    {
                        UnitMaster.LevelUpEvent -= onLevelUp;
                        UnitMaster.LevelUpEvent += onLevelUp;

                        for (int i = 0; i < Convert.ToInt32(action.vars ["amount"]); i++)
                        {
                            if (GameFile._units [0].level == Data._unitInfo.maxLevel)
                            {
                                TypeWrite(BuildText(Data._unitInfo.cannotLevelUpText, GameFile._units [0]), ConsoleColor.DarkYellow, true, false, true);
                                GameFile._units [0].exp = GameFile._units [0].expNext - 1;
                                break;
                            }
                            else
                            {
                                if (GameFile._units [0].hpLeft > 0)
                                {
                                    UnitMaster.LevelUpUnit(GameFile._units [0]);
                                }
                            }
                        }

                        return(false);
                    }
                    else
                    {
                        TypeWrite(Data._battleInfo.noUnitsText, ConsoleColor.DarkYellow, true, false, true);
                        return(true);
                    }

                case Action.Type.AllUnitsLevelUp:
                    if (GameFile._units.Count() > 0)
                    {
                        UnitMaster.LevelUpEvent -= onLevelUp;
                        UnitMaster.LevelUpEvent += onLevelUp;

                        foreach (Unit u in GameFile._units)
                        {
                            for (int i = 0; i < Convert.ToInt32(action.vars ["amount"]); i++)
                            {
                                if (u.level == Data._unitInfo.maxLevel)
                                {
                                    TypeWrite(BuildText(Data._unitInfo.cannotLevelUpText, u), ConsoleColor.DarkYellow, true, false, true);
                                    u.exp = u.expNext - 1;
                                    break;
                                }
                                else
                                {
                                    if (u.hpLeft > 0)
                                    {
                                        UnitMaster.LevelUpUnit(u);
                                    }
                                }
                            }
                        }

                        return(false);
                    }
                    else
                    {
                        TypeWrite(Data._battleInfo.noUnitsText, ConsoleColor.DarkYellow, true, false, true);
                        return(true);
                    }

                case Action.Type.FightWild:
                    if (Convert.ToDouble(action.vars ["chance"]) >= PreGameScreen._rand.NextDouble())
                    {
                        if (GameFile._units.Exists(theUnit => theUnit.hpLeft > 0))
                        {
                            int [] unitIDs  = Array.ConvertAll <string, int> (action.vars ["unitIDs"].Split(new char [] { ',' }), delegate(string s) { return(Convert.ToInt32(s)); });
                            int    minLevel = Convert.ToInt32(action.vars ["minLevel"]);
                            int    maxLevel = Convert.ToInt32(action.vars ["maxLevel"]);
                            Unit   bad      = UnitMaster.MakeUnit(unitIDs [PreGameScreen._rand.Next(0, unitIDs.Count())], PreGameScreen._rand.Next(minLevel, maxLevel + 1));
                            new BattleScreen(bad, Boolean.Parse(action.vars ["canEscape"]), Boolean.Parse(action.vars ["canCatch"]));
                            DrawScreenTitle(_roomName);
                            return(false);
                        }
                        else
                        {
                            TypeWrite(Data._battleInfo.noUnitsText, ConsoleColor.DarkYellow, true, false, true);
                            _nextRoomId = _roomId;
                            return(true);
                        }
                    }

                    return(false);

                case Action.Type.FightTrainer:
                    if (Convert.ToDouble(action.vars ["chance"]) >= PreGameScreen._rand.NextDouble())
                    {
                        if (GameFile._units.Exists(theUnit => theUnit.hpLeft > 0))
                        {
                            new BattleScreen(Data._trainers.Find(t => t.id == Convert.ToInt32(action.vars ["trainerID"])).Clone(), Boolean.Parse(action.vars ["canEscape"]), Boolean.Parse(action.vars ["canCatch"]));
                            DrawScreenTitle(_roomName);
                            return(false);
                        }
                        else
                        {
                            TypeWrite(Data._battleInfo.noUnitsText, ConsoleColor.DarkYellow, true, false, true);
                            _nextRoomId = _roomId;
                            return(true);
                        }
                    }

                    return(false);

                case Action.Type.SetUnitHP:
                    if (GameFile._units.Count() > 0)
                    {
                        GameFile._units [0].hpLeft = (decimal)(Convert.ToDouble(action.vars ["percent"]) * GameFile._units [0].stats ["HP"]);
                        return(false);
                    }
                    else
                    {
                        TypeWrite(Data._battleInfo.noUnitsText, ConsoleColor.DarkYellow, true, false, true);
                        return(true);
                    }

                case Action.Type.SetAllUnitsHP:
                    if (GameFile._units.Count() > 0)
                    {
                        foreach (Unit p in GameFile._units)
                        {
                            p.hpLeft = (decimal)(Convert.ToDouble(action.vars ["percent"]) * p.stats ["HP"]);
                        }

                        return(false);
                    }
                    else
                    {
                        TypeWrite(Data._battleInfo.noUnitsText, ConsoleColor.DarkYellow, true, false, true);
                        return(true);
                    }

                case Action.Type.ChargeUnitMoves:
                    if (GameFile._units.Count() > 0)
                    {
                        for (int i = 0; i < GameFile._units [0].moves.Count(); i++)
                        {
                            Move move = GameFile._units [0].moves [i];
                            move.usesLeft = move.uses;
                            GameFile._units [0].moves [i] = move;
                        }

                        return(false);
                    }
                    else
                    {
                        TypeWrite(Data._battleInfo.noUnitsText, ConsoleColor.DarkYellow, true, false, true);
                        return(true);
                    }

                case Action.Type.ChargeAllUnitsMoves:
                    if (GameFile._units.Count() > 0)
                    {
                        for (int j = 0; j < GameFile._units.Count(); j++)
                        {
                            for (int i = 0; i < GameFile._units [j].moves.Count(); i++)
                            {
                                Move move = GameFile._units [j].moves [i];
                                move.usesLeft = move.uses;
                                GameFile._units [j].moves [i] = move;
                            }
                        }

                        return(false);
                    }
                    else
                    {
                        TypeWrite(Data._battleInfo.noUnitsText, ConsoleColor.DarkYellow, true, false, true);
                        return(true);
                    }

                case Action.Type.TeachUnitMove:
                    if (GameFile._units.Count() > 0)
                    {
                        UnitMaster.LearnMove(this, GameFile._units [0], Data._moveInfo.moves.Find(m => m.id == Convert.ToInt32(action.vars ["moveID"])));
                        return(false);
                    }
                    else
                    {
                        TypeWrite(Data._battleInfo.noUnitsText, ConsoleColor.DarkYellow, true, false, true);
                        return(true);
                    }

                case Action.Type.TeachAllUnitMove:
                    if (GameFile._units.Count() > 0)
                    {
                        foreach (Unit p in GameFile._units)
                        {
                            UnitMaster.LearnMove(this, p, Data._moveInfo.moves.Find(m => m.id == Convert.ToInt32(action.vars ["moveID"])));
                        }

                        return(false);
                    }
                    else
                    {
                        TypeWrite(Data._battleInfo.noUnitsText, ConsoleColor.DarkYellow, true, false, true);
                        return(true);
                    }

                case Action.Type.Text:
                    TypeWrite(action.vars ["text"], ConsoleColor.DarkYellow, true);
                    return(false);

                case Action.Type.Move:
                    _nextRoomId = Convert.ToInt32(action.vars ["roomID"]);
                    DrawScreenTitle(Data._rooms.Find(r => r.id == _nextRoomId).name);
                    return(false);

                case Action.Type.ItemShop:
                    new ItemShopScreen(Convert.ToInt32(action.vars ["shopID"]));
                    Clear(ClearType.Both);
                    DrawScreenTitle(_roomName);
                    return(false);

                case Action.Type.SetAsSpawn:
                    GameFile._spawnRoomID = GameFile._roomID;
                    return(false);

                case Action.Type.Options:
                    HandleOptionList(action.options, action.vars ["dialog"]);
                    return(false);

                case Action.Type.Break:
                    _breaksLeft = Convert.ToInt32(action.vars ["amount"]);
                    return(true);

                case Action.Type.SwapRoomIDs:
                    Room r1      = Data._rooms.Find(r => r.id == Convert.ToInt32(action.vars ["room1ID"]));
                    Room r2      = Data._rooms.Find(r => r.id == Convert.ToInt32(action.vars ["room2ID"]));
                    int  r1Index = Data._rooms.IndexOf(r1);
                    int  r2Index = Data._rooms.IndexOf(r2);
                    int  tempID  = r1.id;
                    r1.id = r2.id;
                    r2.id = tempID;
                    Data._rooms [r1Index] = r1;
                    Data._rooms [r2Index] = r2;
                    return(false);
                }
            }


            return(true);
        }