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> /// Print the enter-message /// </summary> public virtual Boolean OnEnter() { /// This function gets called when the Room is Entered /// The magic stuff happens here: sub classes implement their story in this Func CIO.Print("you entered " + name); return true; }
/// <summary> /// reprints the current top-Context below /// </summary> public static void ReEnterCurrentContext() { CIO.Clear(); if (lastContexts.Count > 0) { lastContexts[lastContexts.Count - 1].Enter(); } }
public virtual void onNotAvailable() { if (notavailableMessageAction == null) { CIO.PrintError("not avaulable"); } else { CIO.PrintError(notavailableMessageAction()); } }
public static void Help() { if (CIO.GetCurrentContext().name == "Inventory.Category") { CIO.PrintHelp("help for Inventory"); } else { CIO.PrintHelp("type i for inventory"); CIO.PrintHelp("type s for Spellbook"); CIO.PrintHelp("type Attack to attack an NPC"); } }
public virtual void onFailure() { if (OnFailure == null) { CIO.PrintError("Failed (generic)"); } else { foreach (Action a in OnFailure) { a(); } } }
public static void Attack() { CIO.Print("Which NPC?"); string input = CIO.ReadLine(); if (wannaExit(input)) { return; } Character enemy = Program.currentRoom.getNPCByName(input); Fight f = new Fight(enemy); f.startFight(); }
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(); } } }
public static void executeCheat(string s) { if (!commands.ContainsKey(s)) { return; } Console.ForegroundColor = ConsoleColor.White; foreach (Action a in commands[s]) { a(); } CIO.ReEnterCurrentContext(); Console.ForegroundColor = ConsoleColor.Blue; }
public static void GiveXP() { int amount = -1; while (amount == -1) { CIO.Print("How much?"); string input = CIO.ReadLine(); if (wannaExit(input)) { return; } Int32.TryParse(input, out amount); } Player.getInstance().GiveXP(amount); }
public static void GiveGold() { CIO.StartNewContext(new Handlers.IO.Context("How much?")); int amount = -1; while (amount == -1) { CIO.Print("How much?"); string input = CIO.ReadLine(); if (wannaExit(input)) { return; } Int32.TryParse(input, out amount); } Player.getInstance().AddGold(amount); CIO.EndContextWithoutReEnter(); }
public override void onFailure() { CIO.Print("the guard doesnt accept your bribe"); }
public override void onNotAvailable() { CIO.Print("Not Enough money"); }
/// <summary> /// Print the leave-message /// </summary> public virtual void OnExit() { // This function gets called when the Room is Exited CIO.Print("you left " + name); }