def read_in_story(file_name): story_num = 0 stories = [] insert = False with open(file_name, 'r') as f: for line in f: line = (line[:-1]).lower() if len(line) < 1: continue if line[0] == '<': if line[1:6] == 'story': story_tmp = story.Story() story_name = line.split('>')[-2].split('<')[0] story_name = story_name.replace(' / ', '__') story_tmp.set_name(story_name) stories.append(story_tmp) insert = True if line[1:6] == 'start': start_time = line.split('>')[-2].split('<')[0] story_tmp.set_start_time(start_time) if line[1:4] == 'end': end_time = line.split('>')[-2].split('<')[0] stories[story_num].set_end_time(end_time) insert = False story_num += 1 else: if len(line) < 2: continue if len(line.split(';')) == 3: continue if insert is True: stories[story_num].add_line(line) print story_num #pdb.set_trace() return stories
def LoadStory(self): print 'Loading Stories...' f = open('auStory.txt', 'r') while True: line = f.readline() if (len(line) <= 0): break if line.find('ID:') == 0: #Start of Story story_ = story.Story(line.lstrip('ID: ').strip()) #Title line = f.readline() story_.SetStoryTitle(line.lstrip('Title: ').strip()) #Time line = f.readline() #Location line = f.readline() #Author line = f.readline() #Story line = f.readline() story_.SetStoryBody(line.lstrip('Story: ').strip()) #Relate line = f.readline() #Good line = f.readline() story_.SetGood(line.lstrip('Good: ').strip().rstrip(';')) #Bad line = f.readline() story_.SetBad(line.lstrip('Bad: ').strip().rstrip(';')) self.storyCollection.append(story_) self.storycounter.countStory(story_) self.wordbag.fillInBags(story_) self.dfCounter.addDocFreq(story_) self.storycounter.CalculateAverage() f.closed
def main(): story_ = story.Story() site1 = booksite.XqishutaSite() story_.register_site(site1) site2 = booksite.SoxsSite() story_.register_site(site2) site3 = booksite.CuohengSite() story_.register_site(site3) site4 = booksite.Shuku87Site() story_.register_site(site4) site5 = booksite.Fox2018Site() story_.register_site(site5) site6 = booksite.DaocaorenshuwuSite() story_.register_site(site6) return story_
def initialize(quickStart=True): global time global player global storyline global galaxy global responseManager, interfaceStack, combatManager time = 0 player = st.Player() storyline = story.Story() galaxy = init.Galaxy().initialize() responseManager = ResponseManager() interfaceStack = InterfaceStack(menus.FactionMenu(galaxy.factionList)) combatManager = CombatManager(player) # Runs story if not quickStart: player.name = input("\nPlease type your name: ") storyline.firstStart()
def main(): story_ = story.Story() site1 = booksite.XqishutaSite() story_.register_site(site1) site2 = booksite.SoxsSite() story_.register_site(site2) site3 = booksite.CuohengSite() story_.register_site(site3) site4 = booksite.Shuku87Site() story_.register_site(site4) site5 = booksite.Fox2018Site() story_.register_site(site5) site6 = booksite.DaocaorenshuwuSite() story_.register_site(site6) root = tkinter.Tk() root.title('下载小说') root.geometry('1440x900') app = Application(root=root, story_=story_) app.mainloop()
def read_in_story(file_name): story_num = 0 stories = [] insert = False with open(file_name, 'r') as f: for line in f: line = (line[:-1]).lower() parts = line.split('|') if parts[0] == 'segstart': if parts[2] != 'commercial': story_tmp = story.Story() story_tmp.set_start_time(parts[1]) story_tmp.set_name(parts[2], parts[3]) stories.append(story_tmp) insert = True elif parts[0] == 'segend': if parts[2] != 'commercial': stories[story_num].set_end_time(parts[1]) story_num += 1 insert = False elif parts[0] == 'cco' and insert is True: stories[story_num].add_line(parts[2]) #print story_num return stories
def test_story(self): import story s = story.Story() self.assertEqual("Tale Demo", s.name)
def test_story(self): import story s = story.Story() self.assertEqual("Zed is me", s.name)
def start(self, game_file_or_path: str) -> None: """Start the driver from a parsed set of arguments""" _check_required_libraries() gamepath = pathlib.Path(game_file_or_path) if gamepath.is_dir(): # cd into the game directory (we can import it then), and load its config and zones os.chdir(str(gamepath)) sys.path.insert(0, os.curdir) elif gamepath.is_file(): # the game argument points to a file, assume it is a zipfile, add it to the import path sys.path.insert(0, str(gamepath)) else: raise FileNotFoundError("Cannot find specified game") assert "story" not in sys.modules, "cannot start new story if it was already loaded before" cmds.clear_registered_commands( ) # needed to allow stories to define their own custom commands after this import story if not hasattr(story, "Story"): raise AttributeError( "Story class not found in the story file. It should be called 'Story'." ) self.story = story.Story() self.story._verify(self) if self.game_mode not in self.story.config.supported_modes: raise ValueError( "driver mode '%s' not supported by this story. Valid modes: %s" % (self.game_mode, list(self.story.config.supported_modes))) self.story.config.mud_host = self.story.config.mud_host or "localhost" self.story.config.mud_port = self.story.config.mud_port or 8180 self.story.config.server_mode = self.game_mode if self.game_mode != GameMode.IF and self.story.config.server_tick_method == TickMethod.COMMAND: raise ValueError( "'command' tick method can only be used in 'if' game mode") # Register the driver and add some more stuff in the global context. self.resources = vfs.VirtualFileSystem( root_package="story") # read-only story resources mud_context.config = self.story.config mud_context.resources = self.resources # check for existence of cmds package in the story root loader = pkgutil.get_loader("cmds") if loader: ld = pathlib.Path(loader.get_filename( "cmds")).parent.parent.resolve() # type: ignore sd = pathlib.Path( inspect.getabsfile(story) ).parent # type: ignore # mypy doesn't recognise getabsfile? if ld == sd: # only load them if the directory is the same as where the story was loaded from cmds.clear_registered_commands( ) # making room for the story's commands # noinspection PyUnresolvedReferences import cmds as story_cmds # import the cmd package from the story for verb, func, privilege in cmds.all_registered_commands(): try: self.commands.add(verb, func, privilege) except ValueError: self.commands.override(verb, func, privilege) cmds.clear_registered_commands() self.commands.adjust_available_commands(self.story.config.server_mode) self.game_clock = util.GameDateTime( self.story.config.epoch or self.server_started, self.story.config.gametime_to_realtime) self.moneyfmt = None if self.story.config.money_type != MoneyType.NOTHING: self.moneyfmt = util.MoneyFormatter.create_for( self.story.config.money_type) user_data_dir = pathlib.Path( appdirs.user_data_dir( "Tale-" + util.storyname_to_filename(self.story.config.name), "Razorvine", roaming=True)) user_data_dir.mkdir(mode=0o700, parents=True, exist_ok=True) self.user_resources = vfs.VirtualFileSystem( root_path=user_data_dir, readonly=False) # r/w to the local 'user data' directory self.story.init(self) if self.story.config.playable_races: # story provides playable races. Check that every race is known. invalid = self.story.config.playable_races - playable_races if invalid: raise errors.StoryConfigError("invalid playable_races") else: # no particular races in story config, take the defaults self.story.config.playable_races = playable_races self.zones = self._load_zones(self.story.config.zones) if not self.story.config.startlocation_player: raise errors.StoryConfigError( "player startlocation not configured in story") if not self.story.config.startlocation_wizard: self.story.config.startlocation_wizard = self.story.config.startlocation_player self.lookup_location(self.story.config.startlocation_player) self.lookup_location(self.story.config.startlocation_wizard) if self.story.config.server_tick_method == TickMethod.COMMAND: # If the server tick is synchronized with player commands, this factor needs to be 1, # because at every command entered the game time simply advances 1 x server_tick_time. self.story.config.gametime_to_realtime = 1 assert self.story.config.server_tick_time > 0 assert self.story.config.max_wait_hours >= 0 self.game_clock = util.GameDateTime( self.story.config.epoch or self.server_started, self.story.config.gametime_to_realtime) # convert textual exit strings to actual exit object bindings for x in self.unbound_exits: x._bind_target(self.zones) self.unbound_exits = [] sys.excepthook = util.excepthook # install custom verbose crash reporter self.start_main_loop() # doesn't exit! (unless game is killed) self._stop_driver()
Created on Wed Dec 2 04:25:15 2020 @author: 戴可昕 """ import tool import var import mainmenu import story import startgame import Gameover import music import startinterface stateDict = { "mainmenu": mainmenu.Mainmenu(), 'story': story.Story(), 'startgame': startgame.Start(), 'gameover': Gameover.GameOver() } def main(): game = tool.Game(stateDict, "mainmenu") #state=mainmenu.Mainmenu() startinterface.StartInterface(game.screen) music.music() game.run() main()
def extend(self, entries): newlist = [] for entry in entries: # This checks existence in newlist as well to avoid # duplicate items on feeds with duplicates in them. # (i.e. broken) if entry in self and entry not in newlist: centry = self[self.index(entry)] if (not centry.updated) and\ (centry["canto_state"] != entry["canto_state"]): centry["canto_state"] = entry["canto_state"] newlist.append(centry) continue # nentry is the new, stripped down version of the item nentry = {} nentry["id"] = entry["id"] nentry["feed"] = self.URL nentry["canto_state"] = entry["canto_state"] if "title" not in entry: nentry["title"] = "" else: nentry["title"] = entry["title"] if "title_detail" in entry: nentry["title_detail"] = entry["title_detail"] for pc in self.cfg.precache: if pc in entry: nentry[pc] = entry[pc] else: nentry[pc] = None if "link" in entry: nentry["link"] = entry["link"] elif "href" in entry: nentry["link"] = entry["href"] # If tags were added in the configuration, c-f won't # notice (doesn't care about tags), so we check and # append as needed. updated = STORY_SAVED if self.tags[0] != nentry["canto_state"][0]: nentry["canto_state"][0] = self.tags[0] updated = STORY_UPDATED for tag in self.tags[1:]: if tag not in nentry["canto_state"]: nentry["canto_state"].append(tag) updated = STORY_UPDATED if nentry not in newlist: newlist.append(story.Story(nentry, self.path, updated)) del self[:] for item in newlist: if not self.filter or self.filter(self, item): list.append(self, item)
def checkForStory(self): p1x, p1y = pygame.mouse.get_pos() if p1x > 436 and p1x < 636 and p1y > 390 and p1y < 450: game = story.Story() game.runStory()
sentence = '庙里有个老和尚,' @classmethod def reading(cls): print('在讲故事,') class Story: sentence = '一个长长的故事。' def reading(self): print('讲的什么故事呢?') #main文件存放执行语句 import story for i in range(10): print(story.sentence) story.mountain() print(story.Temple.sentence) story.Temple.reading() A = story.Story() print(A.sentence) A.reading() print() #仅打印类Temple的属性 from story import Temple print(Temple.sentence) #关于random模块 import random # 调用random模块 a = random.random() # 随机从0-1之间抽取一个小数 print(a) a = random.randint(0,100) # 随机从0-100之间抽取一个数字
def run(self): clock = pygame.time.Clock() self.initstuff() if '-nomusic' not in sys.argv: try: pygame.mixer.music.load(data.filepath('tripper.ogg')) except pygame.error: pass else: pygame.mixer.music.play() glClearColor(0, 0, 0, 1) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE) while not self.alldone: for e in pygame.event.get(): if e.type == QUIT: sys.exit() if e.type != KEYDOWN: continue elif e.key == K_ESCAPE: self.fadeouttime = True self.cursorplace = 2 self.spinspeed = 0 elif e.key == K_UP or e.key == K_LEFT: self.menumove.play() self.cursorplace -= 1 if self.cursorplace < 0: self.cursorplace = 2 #wrap over elif e.key == K_DOWN or e.key == K_RIGHT: self.menumove.play() self.cursorplace += 1 if self.cursorplace > 2: self.cursorplace = 0 #wrap over elif e.key == K_SPACE or e.key == K_RETURN: self.spinspeed = 0 self.menuselect.play() self.fadeouttime = True glClear(GL_COLOR_BUFFER_BIT) dt = clock.tick(60) self.figurestuff(dt) glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glPushMatrix() #x, y = (0, 0) glTranslatef(0, 256 + self.bgoffset, 0) self.bg.render() glPopMatrix() glPushMatrix() #x, y = (0, 0) glTranslatef(0, -256, 0) self.menubg.render() glPopMatrix() glDisable(GL_BLEND) glPushMatrix() x, y = (646, 347 + (90 * self.cursorplace)) glTranslatef(x, 768 - y - 64, 0) self.starguy.render(self.starframe) glPopMatrix() if self.fadeouttime == True and self.running >= 1: self.alldone = True if self.cursorplace != 2: #pygame.display.flip() glClear(GL_COLOR_BUFFER_BIT) glPushMatrix() x, y = (0, 349) glTranslatef(x, 768 - y, 0) self.loadingscreen.render() glPopMatrix() if self.cursorplace == 1: timemachinesound = pygame.mixer.Sound( data.filepath('timemachine2.ogg', 'sfx')) timemachinesound.play() else: return True if self.fadein == True: glColor(0, 0, 0, 1 - self.running) glEnable(GL_BLEND) glBegin(GL_QUADS) glVertex2f(0, 0) glVertex2f(1024, 0) glVertex2f(1024, 768) glVertex2f(0, 768) glEnd() glDisable(GL_BLEND) glColor(1, 1, 1, 1) self.running += .02 if self.running >= 1: self.running = 0 self.fadein = False if self.fadeouttime == True and self.running < 1: glColor(0, 0, 0, self.running) glEnable(GL_BLEND) glBegin(GL_QUADS) glVertex2f(0, 0) glVertex2f(1024, 0) glVertex2f(1024, 768) glVertex2f(0, 768) glEnd() glDisable(GL_BLEND) glColor(1, 1, 1, 1) self.running += .04 pygame.display.flip() if self.alldone == True and self.cursorplace == 0: pygame.mixer.music.fadeout(1000) #play cutscene stuff thestory = story.Story() thestory.run() del thestory pygame.mixer.stop() self.initstuff() #don't exit yet! tee hee try: pygame.mixer.music.load(data.filepath('tripper.ogg')) pygame.mixer.music.play() except: pass #pygame.time.wait(100) return False
# Create oak, and add his different images to a list __builtin__.g_oak_grass = npc.NPC([1152, -64], pygame.image.load("resc\images\g_oak.png"), True, 0) __builtin__.g_oak_lab = npc.NPC([448, 256], pygame.image.load("resc\images\g_oak.png"), False, 0) __builtin__.g_oak_list = [g_oak_grass, g_oak_lab] #Create rest of the npc/trainers __builtin__.g_trainer_one = npc.NPC( [1792, -656], pygame.image.load("resc\images\g_trainer.png"), False, 0) # Create the menu class. g_menu = menu.Menu(DISPLAY_SURFACE) g_story = story.Story(DISPLAY_SURFACE) # This function handles any input. Called before update. def handle_input(): global g_game_stopped for event in pygame.event.get(): if event.type == pygame.QUIT: g_game_stopped = True elif g_player.handle_input(event): pass elif event.type == pygame.KEYDOWN: if event.key == pygame.K_RETURN: g_menu.enable_menu()
def test_story(self): import story s = story.Story() self.assertEqual("Circle", s.config.name)