From 47869ed9ab0a2ac7f29bebd6ba678f93494af415 Mon Sep 17 00:00:00 2001 From: Nick Walton Date: Tue, 19 Nov 2019 14:58:21 -0700 Subject: [PATCH 1/2] update --- play.py | 32 +++++++++++++++++++++----------- story/story_manager.py | 11 ++++++++++- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/play.py b/play.py index 20dd1a1..b5039f1 100644 --- a/play.py +++ b/play.py @@ -29,6 +29,15 @@ def instructions(): text += '\n* Finally if you want to end your game and start a new one just enter "restart" for any action. ' return text +def upload_story_to_cloud(story): + rating = input("Please rate the story quality from 1-10: ") + try: + rating_float = float(rating) + story.rating = rating_float + story.save_to_storage() + except: + pass + def play_aidungeon_2(): @@ -52,8 +61,9 @@ def play_aidungeon_2(): print("\n\n") context, prompt = select_game() console_print(instructions()) + print("\nGenerating story...") - story_manager.start_new_story(prompt, context=context) + story_manager.start_new_story(prompt, context=context, upload_story=upload_story) print("\n") console_print(context + str(story_manager.story)) @@ -62,14 +72,12 @@ def play_aidungeon_2(): action = input("> ") if action == "restart": if upload_story: - rating = input("Please rate the story quality from 1-10: ") - try: - rating_float = float(rating) - story_manager.story.rating = rating_float - story_manager.story.save_to_storage() - except: - pass + upload_story_to_cloud(story_manager.story) break + elif action == "quit": + if upload_story: + upload_story_to_cloud(story_manager.story) + exit() if action != "" and action.lower() != "continue": action = action.strip() @@ -88,14 +96,16 @@ def play_aidungeon_2(): result = "\n" + story_manager.act(action) - if upload_story: - story_manager.story.save_to_storage() - if player_died(result): console_print(result + "\nGAME OVER") + if upload_story: + upload_story_to_cloud(story_manager.story) break elif player_won(result): console_print(result + "\n CONGRATS YOU WIN") + if upload_story: + upload_story_to_cloud(story_manager.story) + break else: console_print(result) diff --git a/story/story_manager.py b/story/story_manager.py index 1ab306e..3f5c41e 100644 --- a/story/story_manager.py +++ b/story/story_manager.py @@ -7,10 +7,11 @@ import os class Story(): - def __init__(self, story_start, context ="", seed=None, game_state=None): + def __init__(self, story_start, context ="", seed=None, game_state=None, upload_story=False): self.story_start = story_start self.context = context self.rating = -1 + self.upload_story = upload_story # list of actions. First action is the prompt length should always equal that of story blocks self.actions = [] @@ -29,6 +30,14 @@ class Story(): self.game_state = game_state self.memory = 10 + def __del__(self): + rating = input("Please rate the story quality from 1-10: ") + try: + rating_float = float(rating) + self.rating = rating_float + self.save_to_storage() + except: + pass def initialize_from_json(self, json_string): story_dict = json.loads(json_string) From d7eea8c21083e4dcea0092a827085ced5acdb1f3 Mon Sep 17 00:00:00 2001 From: Nick Walton Date: Tue, 19 Nov 2019 15:00:02 -0700 Subject: [PATCH 2/2] update --- story/story_manager.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/story/story_manager.py b/story/story_manager.py index 3f5c41e..6fc6528 100644 --- a/story/story_manager.py +++ b/story/story_manager.py @@ -116,10 +116,10 @@ class StoryManager(): def __init__(self, generator): self.generator = generator - def start_new_story(self, story_prompt, context="", game_state=None): + def start_new_story(self, story_prompt, context="", game_state=None, upload_story=False): block = self.generator.generate(context + story_prompt) block = cut_trailing_sentence(block) - self.story = Story(story_prompt + block, context=context, game_state=game_state) + self.story = Story(story_prompt + block, context=context, game_state=game_state, upload_story=upload_story) return self.story def load_story(self, story, from_json=False):