def test_input(self): player = Player("julie", "f") with WrappedConsoleIO(None) as io: pc = PlayerConnection(player, io) player.tell("first this text") player.store_input_line(" input text \n") x = pc.input_direct("inputprompt") self.assertEqual("input text", x) self.assertEqual(" first this text\ninputprompt ", sys.stdout.getvalue()) # should have outputted the buffered text
def welcome(self, player: Player) -> str: """ Welcome text when player enters a new game If you return a string, it is used as an input prompt before continuing (a pause). """ player.tell("<bright>Hello, %s!</> Welcome to the land of `%s'. May your visit here be... interesting." % (player.title, self.config.name), end=True) player.tell("--", end=True) return ""
def test_peek_output(self): player = Player("fritz", "m") player.io = ConsoleIo(None) player.set_screen_sizes(0, 100) player.tell("line1") player.tell("line2", 42) self.assertEqual(["line1\nline2\n42\n"], player.peek_output_paragraphs_raw()) self.assertEqual("line1 line2 42\n", player.get_output()) self.assertEqual([], player.peek_output_paragraphs_raw())
def test_tell_sep(self): player = Player("fritz", "m") pc = PlayerConnection(player, ConsoleIo(None)) player.set_screen_sizes(0, 10) player.tell("apple", "bee", "zinc", "rose") self.assertEqual(["apple bee zinc rose\n"], player.test_get_output_paragraphs()) pc.get_output() player.tell("apple", "bee", "zinc", "rose", format=False) self.assertEqual("apple\nbee\nzinc\nrose\n", pc.get_output())
def test_peek_output(self): player = Player("fritz", "m") pc = PlayerConnection(player, ConsoleIo(None)) player.set_screen_sizes(0, 100) player.tell("line1") player.tell("line2", 42) self.assertEqual(["line1\nline2 42\n"], player.test_peek_output_paragraphs()) self.assertEqual("line1 line2 42\n", pc.get_output()) self.assertEqual([], player.test_peek_output_paragraphs())
def test_write_output(self): player = Player("julie", "f") with WrappedConsoleIO(None) as io: pc = PlayerConnection(player, io) player.tell("hello 1", end=True) player.tell("hello 2", end=True) pc.write_output() self.assertEqual(" hello 2", pc.last_output_line) self.assertEqual(" hello 1\n hello 2\n", sys.stdout.getvalue())
def welcome(self, player: Player) -> str: """ Welcome text when player enters a new game If you return a string, it is used as an input prompt before continuing (a pause). """ player.tell( "<bright>Hello, %s!</> Welcome to the land of `%s'. May your visit here be... interesting." % (player.title, self.config.name), end=True) player.tell("--", end=True) return ""
def test_write_output(self): player = Player("julie", "f") player.io = ConsoleIo(None) old_stdout = sys.stdout sys.stdout = StringIO() try: player.tell("hello 1", end=True) player.tell("hello 2", end=True) player.write_output() self.assertEqual(" hello 1\n hello 2\n", sys.stdout.getvalue()) finally: sys.stdout = old_stdout
def test_input(self): player = Player("julie", "f") player.prompt_toolkit_enabled = False with WrappedConsoleIO(None) as io: pc = PlayerConnection(player, io) player.tell("first this text") player.store_input_line(" input text \n") x = pc.input_direct("inputprompt") self.assertEqual("input text", x) self.assertEqual(" first this text\ninputprompt ", sys.stdout.getvalue() ) # should have outputted the buffered text
def test_input(self): player = Player("julie", "f") player.io = ConsoleIo(None) old_stdout = sys.stdout sys.stdout = StringIO() try: player.tell("first this text") player.store_input_line("input text\n") x = player.input("inputprompt") self.assertEqual("input text", x) self.assertEqual(" first this text\ninputprompt", sys.stdout.getvalue()) # should have outputted the buffered text finally: sys.stdout = old_stdout
def welcome(self, player: Player) -> Optional[str]: """welcome text when player enters a new game""" player.tell("<bright>Hello, %s! Welcome to %s.</>" % (player.title, self.config.name), end=True) player.tell("\n") player.tell(self.driver.resources["messages/welcome.txt"].text) player.tell("\n") return None
def welcome_savegame(self, player: Player) -> Optional[str]: """welcome text when player enters the game after loading a saved game""" player.tell("<bright>Hello %s, welcome back to %s.</>" % (player.title, self.config.name), end=True) player.tell("\n") player.tell(self.driver.resources["messages/welcome.txt"].text) player.tell("\n") return None
def welcome(self, player: Player) -> str: player.tell("<bright>Welcome to `%s'.</>" % self.config.name, end=True) player.tell("This is a tiny embedded story to check out a running Tale environment.") player.tell("Try to communicate with your pet, and exit the house to win the game.") player.tell("\n") player.tell("\n") return ""
def welcome(self, player: Player) -> str: player.tell("<bright>Welcome to `%s'.</>" % self.config.name, end=True) player.tell( "This is a tiny embedded story to check out a running Tale environment." ) player.tell( "Try to communicate with your pet, and exit the house to win the game." ) player.tell("\n") player.tell("\n") return ""
def test_tell_emptystring(self): player = Player("fritz", "m") player.tell("", end=False) self.assertEqual([], player.test_get_output_paragraphs()) player.tell("", end=True) self.assertEqual(["\n"], player.test_get_output_paragraphs()) player.tell("", end=True) player.tell("", end=True) self.assertEqual(["\n", "\n"], player.test_get_output_paragraphs())
def test_tell_emptystring(self): player = Player("fritz", "m") player.tell("", end=False) self.assertEqual([], player.test_get_output_paragraphs()) player.tell("", end=True) self.assertEqual(["\n"], player.test_get_output_paragraphs()) player.tell("", end=True) player.tell("", end=True) self.assertEqual(["\n", "\n"], player.test_get_output_paragraphs())
def welcome(self, player: Player) -> str: """ Welcome text when player enters a new game If you return a string, it is used as an input prompt before continuing (a pause). """ player.tell("<bright>Welcome to `%s'.</>" % self.config.name, end=True) player.tell("\n") player.tell_text_file(self.driver.resources["messages/welcome.txt"]) player.tell("\n") return "<bright>Press enter to continue.</>"
def welcome_savegame(self, player: Player) -> str: """ Welcome text when player enters the game after loading a saved game If you return a string, it is used as an input prompt before continuing (a pause). """ player.tell("<bright>Welcome back to `%s'.</>" % self.config.name, end=True) player.tell("\n") player.tell_text_file(self.driver.resources["messages/welcome.txt"]) player.tell("\n") return "<bright>Press enter to continue where you were before.</>"
def spawn_cvnum(player: Player, parsed: ParseResult, ctx: util.Context) -> None: """Spawn an item or monster with the given circle-vnum (or both if the circle-vnum is the same).""" if len(parsed.args) != 1: raise ParseError("You have to give the item or monster's circle-vnum.") vnum = int(parsed.args[0]) try: item = make_item(vnum) except KeyError: player.tell("There's no item with that circle-vnum.") else: player.tell("Spawned " + repr(item) + " (into your inventory)") item.move(player, actor=player) try: mob = make_mob(vnum) except KeyError: player.tell("There's no monster with that circle-vnum.") else: player.tell("Spawned " + repr(mob) + " (into your current location)") mob.move(player.location, actor=player)
def welcome_savegame(self, player: Player) -> str: """ Welcome text when player enters the game after loading a saved game If you return a string, it is used as an input prompt before continuing (a pause). """ player.tell("<bright>Welcome back to `%s'.</>" % self.config.name, end=True) player.tell("\n") # player.tell_text_file(self.driver.resources["messages/welcome.txt"]) # player.tell_text_file(self.driver.resources["messages/motd.txt"]) player.tell("\n") return "<bright>Press enter to continue where you were before.</>"
def show_cvnum(player: Player, parsed: ParseResult, ctx: util.Context) -> None: """Show the circle-vnum of a location (.) or an object/living, or when you provide a circle-vnum as arg, show the object(s) with that circle-vnum.""" if not parsed.args: raise ParseError("From what should I show the circle-vnum?") name = parsed.args[0] obj = None # type: Union[Location, Living, Item, Exit] if name == ".": obj = player.location elif parsed.who_info: obj = parsed.who_1 else: try: vnum = int(parsed.args[0]) except ValueError as x: raise ActionRefused(str(x)) objects = [] # type: List[Union[Location, Living, Item, Exit]] try: objects.append(make_item(vnum)) except KeyError: pass try: objects.append(make_location(vnum)) except KeyError: pass try: objects.append(make_mob(vnum)) except KeyError: pass player.tell("Objects with circle-vnum %d:" % vnum + " " + (lang.join(str(o) for o in objects) or "none")) return try: vnum = obj.circle_vnum player.tell("Circle-Vnum of %s = %d." % (obj, vnum)) except AttributeError: player.tell(str(obj) + " has no circle-vnum.")
def test_tell_formats(self): player = Player("fritz", "m") pc = PlayerConnection(player, ConsoleIo(None)) player.set_screen_sizes(0, 100) player.tell("a b c", format=True) player.tell("d e f", format=True) self.assertEqual(["a b c\nd e f\n"], player.test_get_output_paragraphs()) player.tell("a b c", format=True) player.tell("d e f", format=True) self.assertEqual("a b c d e f\n", pc.get_output()) player.tell("a b c", format=False) player.tell("d e f", format=False) self.assertEqual(["a b c\nd e f\n"], player.test_get_output_paragraphs()) player.tell("a b c", format=False) player.tell("d e f", format=False) self.assertEqual("a b c\nd e f\n", pc.get_output()) player.tell("a b c", format=True) player.tell("d e f", format=False) self.assertEqual(["a b c\n", "d e f\n"], player.test_get_output_paragraphs()) player.tell("a b c", format=True) player.tell("d e f", format=False) self.assertEqual("a b c\nd e f\n", pc.get_output())
def do_score(player: Player, parsed: ParseResult, ctx: Context) -> None: """Show your current score in the game.""" player.tell("You have taken %d turns so far." % player.turns)
def goodbye(self, player: Player) -> None: """goodbye text when player quits the game""" player.tell("Goodbye, %s. Please come back again soon." % player.title) player.tell("\n")
def do_demo2(player: Player, parsed: ParseResult, ctx: Context) -> None: """demo command""" player.tell("DEMO COMMAND")
def do_coin(player: Player, parsed: ParseResult, ctx: Context) -> None: """coin command that overwrites the default version""" player.tell("COIN OVERRIDE")
def do_demo2(player: Player, parsed: ParseResult, ctx: Context) -> None: """demo command""" player.tell("DEMO COMMAND")
def do_demo(player: Player, parsed: ParseResult, ctx: Context) -> None: """demo wizard command""" player.tell("DEMO WIZARD COMMAND")
def notify_player_arrived(self, player: Player, previous_location: Location) -> None: if previous_location is self: player.tell("...Weird... The door you just entered seems to go back to the same place you came from...")
def test_tell_chain(self): player = Player("fritz", "m") player.tell("hi").tell("there") self.assertEqual(["hi\nthere\n"], player.test_get_output_paragraphs())
def test_tell_chain(self): player = Player("fritz", "m") player.tell("hi").tell("there") self.assertEqual(["hi\nthere\n"], player.test_get_output_paragraphs())
def test_tell(self) -> None: player = Player("fritz", "m") player.tell("5") self.assertEqual(["5\n"], player.test_get_output_paragraphs()) player.tell("") self.assertEqual([], player.test_get_output_paragraphs()) player.tell("") player.tell("") self.assertEqual([], player.test_get_output_paragraphs()) player.tell("") player.tell("line1") player.tell("line2") player.tell("") self.assertEqual(["line1\nline2\n"], player.test_get_output_paragraphs()) player.tell("", format=False) player.tell("line1", format=False) player.tell("", format=False) player.tell("line2", format=False) player.tell("", format=False) self.assertEqual(["\nline1\n\nline2\n\n"], player.test_get_output_paragraphs()) player.tell("\n") self.assertEqual(["\n"], player.test_get_output_paragraphs()) player.tell("line1") player.tell("line2") player.tell("hello\nnewline") player.tell("\n") player.tell("ints") player.tell("42") player.tell("999") self.assertEqual(["line1\nline2\nhello\nnewline\n", "ints\n42\n999\n"], player.test_get_output_paragraphs()) self.assertEqual([], player.test_get_output_paragraphs()) player.tell("para1", end=False) player.tell("para2", end=True) player.tell("para3") player.tell("\n") player.tell("para4") player.tell("\n") player.tell("para5") self.assertEqual(["para1\npara2\n", "para3\n", "para4\n", "para5\n"], player.test_get_output_paragraphs()) player.tell(" xyz \n 123", format=False) self.assertEqual([" xyz \n 123\n"], player.test_get_output_paragraphs()) player.tell("line1", end=True) player.tell("\n") player.tell("line2", end=True) player.tell("\n") player.tell("\n") self.assertEqual(["line1\n", "\n", "line2\n", "\n", "\n"], player.test_get_output_paragraphs()) player.tell("one two three", format=False) self.assertEqual(["one two three\n"], player.test_get_output_paragraphs())
def test_tell(self): player = Player("fritz", "m") player.tell(5) self.assertEqual(["5\n"], player.test_get_output_paragraphs()) player.tell("") self.assertEqual([], player.test_get_output_paragraphs()) player.tell("") player.tell("") self.assertEqual([], player.test_get_output_paragraphs()) player.tell("") player.tell("line1") player.tell("line2") player.tell("") self.assertEqual(["line1\nline2\n"], player.test_get_output_paragraphs()) player.tell("", format=False) player.tell("line1", format=False) player.tell("", format=False) player.tell("line2", format=False) player.tell("", format=False) self.assertEqual(["\nline1\n\nline2\n\n"], player.test_get_output_paragraphs()) player.tell("\n") self.assertEqual(["\n"], player.test_get_output_paragraphs()) player.tell("line1") player.tell("line2") player.tell("hello\nnewline") player.tell("\n") player.tell("ints", 42, 999) self.assertEqual(["line1\nline2\nhello\nnewline\n", "ints 42 999\n"], player.test_get_output_paragraphs()) self.assertEqual([], player.test_get_output_paragraphs()) player.tell("para1", end=False) player.tell("para2", end=True) player.tell("para3") player.tell("\n") player.tell("para4", "\n", "para5") self.assertEqual(["para1\npara2\n", "para3\n", "para4 \n para5\n"], player.test_get_output_paragraphs()) player.tell(" xyz \n 123", format=False) self.assertEqual([" xyz \n 123\n"], player.test_get_output_paragraphs()) player.tell("line1", end=True) player.tell("\n") player.tell("line2", end=True) player.tell("\n") player.tell("\n") self.assertEqual(["line1\n", "\n", "line2\n", "\n", "\n"], player.test_get_output_paragraphs())
def test_tell_formatted(self): player = Player("fritz", "m") pc = PlayerConnection(player, ConsoleIo(None)) player.set_screen_sizes(0, 100) player.tell("line1") player.tell("line2", "\n") player.tell("hello\nnewline") player.tell("\n") # paragraph separator player.tell("ints", 42, 999) self.assertEqual("line1 line2 hello newline\nints 42 999\n", pc.get_output()) player.tell("para1", end=False) player.tell("para2", end=True) player.tell("para3") player.tell("\n") player.tell("para4", "\n", "para5") self.assertEqual("para1 para2\npara3\npara4 para5\n", pc.get_output()) player.tell("word " * 30) self.assertNotEqual(("word " * 30).strip(), pc.get_output()) player.tell("word " * 30, format=False) self.assertEqual( ("word " * 30) + "\n", pc.get_output()) # when format=False output should be unformatted player.tell(" xyz \n 123", format=False) self.assertEqual(" xyz \n 123\n", pc.get_output()) player.tell("line1", end=True) player.tell("\n") player.tell("line2", end=True) player.tell("\n") player.tell("\n") self.assertEqual(["line1\n", "\n", "line2\n", "\n", "\n"], player.test_get_output_paragraphs()) player.tell("line1", end=True) player.tell("\n") player.tell("line2", end=True) player.tell("\n") player.tell("\n") self.assertEqual("line1\n\nline2\n\n\n", pc.get_output())
def test_tell_formats(self): player = Player("fritz", "m") pc = PlayerConnection(player, ConsoleIo(None)) player.set_screen_sizes(0, 100) player.tell("a b c", format=True) player.tell("d e f", format=True) self.assertEqual(["a b c\nd e f\n"], player.test_get_output_paragraphs()) player.tell("a b c", format=True) player.tell("d e f", format=True) self.assertEqual("a b c d e f\n", pc.get_output()) player.tell("a b c", format=False) player.tell("d e f", format=False) self.assertEqual(["a b c\nd e f\n"], player.test_get_output_paragraphs()) player.tell("a b c", format=False) player.tell("d e f", format=False) self.assertEqual("a b c\nd e f\n", pc.get_output()) player.tell("a b c", format=True) player.tell("d e f", format=False) self.assertEqual(["a b c\n", "d e f\n"], player.test_get_output_paragraphs()) player.tell("a b c", format=True) player.tell("d e f", format=False) self.assertEqual("a b c\nd e f\n", pc.get_output())
def test_tell_formatted(self): player = Player("fritz", "m") pc = PlayerConnection(player, ConsoleIo(None)) player.set_screen_sizes(0, 100) player.tell("line1") player.tell("line2", "\n") player.tell("hello\nnewline") player.tell("\n") # paragraph separator player.tell("ints", 42, 999) self.assertEqual("line1 line2 hello newline\nints 42 999\n", pc.get_output()) player.tell("para1", end=False) player.tell("para2", end=True) player.tell("para3") player.tell("\n") player.tell("para4", "\n", "para5") self.assertEqual("para1 para2\npara3\npara4 para5\n", pc.get_output()) player.tell("word " * 30) self.assertNotEqual(("word " * 30).strip(), pc.get_output()) player.tell("word " * 30, format=False) self.assertEqual(("word " * 30) + "\n", pc.get_output()) # when format=False output should be unformatted player.tell(" xyz \n 123", format=False) self.assertEqual(" xyz \n 123\n", pc.get_output()) player.tell("line1", end=True) player.tell("\n") player.tell("line2", end=True) player.tell("\n") player.tell("\n") self.assertEqual(["line1\n", "\n", "line2\n", "\n", "\n"], player.test_get_output_paragraphs()) player.tell("line1", end=True) player.tell("\n") player.tell("line2", end=True) player.tell("\n") player.tell("\n") self.assertEqual("line1\n\nline2\n\n\n", pc.get_output())
def do_score(player: Player, parsed: ParseResult, ctx: Context) -> None: """Show your current score in the game.""" player.tell("You have taken %d turns so far." % player.turns)
def goodbye(self, player: Player) -> None: player.tell("Thanks for trying out Tale!")
def do_demo(player: Player, parsed: ParseResult, ctx: Context) -> None: """demo wizard command""" player.tell("DEMO WIZARD COMMAND")
def notify_player_arrived(self, player: Player, previous_location: Location) -> None: if previous_location is self: player.tell( "...Weird... The door you just entered seems to go back to the same place you came from..." )
def goodbye(self, player: Player) -> None: player.tell("Thanks for trying out Tale!")
def test_tell(self): player = Player("fritz", "m") player.tell(5) self.assertEqual(["5\n"], player.test_get_output_paragraphs()) player.tell("") self.assertEqual([], player.test_get_output_paragraphs()) player.tell("") player.tell("") self.assertEqual([], player.test_get_output_paragraphs()) player.tell("") player.tell("line1") player.tell("line2") player.tell("") self.assertEqual(["line1\nline2\n"], player.test_get_output_paragraphs()) player.tell("", format=False) player.tell("line1", format=False) player.tell("", format=False) player.tell("line2", format=False) player.tell("", format=False) self.assertEqual(["\nline1\n\nline2\n\n"], player.test_get_output_paragraphs()) player.tell("\n") self.assertEqual(["\n"], player.test_get_output_paragraphs()) player.tell("line1") player.tell("line2") player.tell("hello\nnewline") player.tell("\n") player.tell("ints", 42, 999) self.assertEqual(["line1\nline2\nhello\nnewline\n", "ints 42 999\n"], player.test_get_output_paragraphs()) self.assertEqual([], player.test_get_output_paragraphs()) player.tell("para1", end=False) player.tell("para2", end=True) player.tell("para3") player.tell("\n") player.tell("para4", "\n", "para5") self.assertEqual(["para1\npara2\n", "para3\n", "para4 \n para5\n"], player.test_get_output_paragraphs()) player.tell(" xyz \n 123", format=False) self.assertEqual([" xyz \n 123\n"], player.test_get_output_paragraphs()) player.tell("line1", end=True) player.tell("\n") player.tell("line2", end=True) player.tell("\n") player.tell("\n") self.assertEqual(["line1\n", "\n", "line2\n", "\n", "\n"], player.test_get_output_paragraphs())
def notify_player_arrived(self, player: Player, previous_location: Location) -> None: # player has entered, and thus the story ends player.tell("\n") player.tell("\n") player.tell("<bright>Congratulations on escaping the house!</> Someone else has to look after the parakeet now though...") raise StoryCompleted
def notify_player_arrived(self, player: Player, previous_location: Location) -> None: # player has entered, and thus the story ends player.tell("\n") player.tell("\n") player.tell("<bright>Congratulations on escaping the house!</> Someone else has to look after Garfield now though...") raise StoryCompleted
def do_coin(player: Player, parsed: ParseResult, ctx: Context) -> None: """coin command that overwrites the default version""" player.tell("COIN OVERRIDE")