public static void LoadAll() { void AddCheat(string s, Action a) { s = s.ToLower(); if (commands.ContainsKey(s)) { commands[s].Add(a); } else { commands.Add(s, new List <Action>()); commands[s].Add(a); } } AddCheat("give gold", () => GlobalCommands.GiveGold()); AddCheat("i", () => Player.getInstance().OpenInventory()); AddCheat("s", () => Player.getInstance().OpenSpellbook()); AddCheat("Attack", () => Attack()); AddCheat("h", () => Help()); AddCheat("help", () => Help()); AddCheat("give sword", () => GiveSword()); AddCheat("give xp", () => GiveXP()); AddCheat("debug", () => CIO.ToggleDebugging()); }
/// <summary> /// Reads user input and returns the first string which is NOT a global Command /// </summary> public static string ReadLine() { /// <summary> /// Checks if the String is a Global COmmand and Executes it, if true /// </summary> Boolean TestGC(string input) { if (GlobalCommands.existsCheat(input)) { GlobalCommands.executeCheat(input); return(true); } return(false); } while (true) { printsSinceLastRead.Clear(); Console.ForegroundColor = userinputColor; string input = Console.ReadLine().ToLower(); if (!TestGC(input)) { Console.ForegroundColor = defaultcolor; return(input); } } }
/// <summary> /// Initializes the class CIO to make it ready for use /// </summary> public static void Initialize() { Console.ForegroundColor = defaultcolor; GlobalCommands.LoadAll(); foreach (KeyValuePair <string, ConsoleColor> kvPair in ColorVars) { if (kvPair.Key == "{Default}") { continue; } ColorVarsReversed.Add(kvPair.Value, kvPair.Key);//twist key as value and value as key } }
static void Main(string[] args) { player = Player.getInstance(); createStartRoom(); CIO.Initialize(); currentRoom = Room.AllRooms[typeof(GameContent.Rooms.Forest_start)]; GlobalCommands.GiveSword(); player.LearnSpell(Spell.Flames); while (true) { Console.WriteLine("#########################"); Room r = currentRoom; if (r.OnEnter()) { Room nextroom = null; while (nextroom == null) { Optionhandler h; if (r.ActivitiesInRoom != null)//print activities if there are any { h = new Optionhandler(r.name + ". Activities:"); h.AddOptions(r.ActivitiesInRoom); h.AddHeading("Next Rooms:"); } else { h = new Optionhandler(r.name + ". next room?"); } h.AddOptions(Optionhandler.RoomsToOption(r.nextRooms)); Option selectedOpt = h.selectOption(); if (selectedOpt.GetType().IsSubclassOf(typeof(Room))) { nextroom = (Room)selectedOpt; } } CIO.Clear(); currentRoom.OnExit(); currentRoom = nextroom; } else { CIO.Clear(); r.OnExit(); } } }