def main(): """Début du programme """ pygame.init() pygame.font.init() config = Config() display = Display(config) level = config.loading_stage("level.txt") hero = Hero(level) guardian = Guardian(level) needle = Items("needle", level) ether = Items("ether", level) tube = Items("tube", level) keys = Event() display.draw_window(config) while config.run: display.draw_labyrinth(level, config) keys.actions(level, hero) hero.pick(needle) hero.pick(ether) hero.pick(tube) hero.craft() display.draw_items(hero, display.hero, config) display.draw_items(guardian, display.guardian, config) display.draw_items(ether, display.ether, config) display.draw_items(needle, display.needle, config) display.draw_items(tube, display.tube, config) display.draw_inventory(hero, config) guardian.is_there_anyone_here(hero, config) pygame.display.update() display.draw_final(config)
def setUpPlayer(self): newGear = Gear(500) hunter = Guardian(1, newGear) newGear2 = Gear(500) warlock = Guardian(2, newGear2) newGear3 = Gear(500) titan = Guardian(3, newGear3) return Player(hunter, warlock, titan)
def crawling(request): article_dict = {} if request.POST: subject = request.POST["subject"] date_range = request.POST['date_range'] source = request.POST['source'] articles = [] address = "" if source == 'Bloomberg': temp = datetime.utcnow().strftime("%Y-%m-%d") + 'T' + datetime.utcnow().strftime("%H:%M:%S.%f") end_date = temp[0:len(temp) - 3] + 'Z' blm = Bloomberg(subject, date_range, end_date) articles, address = blm.getNews() elif source == 'Reuters': if date_range == "-1d": rts = Reuters(subject, 'pastDay') articles, address = rts.get_news() elif date_range == "-1w": rts = Reuters(subject, 'pastWeek') articles, address = rts.get_news() elif date_range == "-1m": rts = Reuters(subject, 'pastMonth') articles, address = rts.get_news() elif source == 'Guardian': end = date.today() if date_range == "-1d": time_delta = 1 start = end - timedelta(time_delta) gdn = Guardian(subject, start, end, 1) articles, address = gdn.get_news() elif date_range == "-1w": time_delta = 7 start = end - timedelta(time_delta) gdn = Guardian(subject, start, end, 1) articles, address = gdn.get_news() elif date_range == "-1m": time_delta = 30 start = end - timedelta(time_delta) gdn = Guardian(subject, start, end, 1) articles, address = gdn.get_news() for article in articles: title = BeautifulSoup(article['title']).text article_dict[title] = article['content'] request.session['address'] = address request.session['subject'] = subject request.session.set_expiry(300) return render(request, "crawling.html", {'news': article_dict})
def set_grid(self): """set_grid defined the maze.""" with open('maze.txt') as maze: datas = maze.read() # je parcours toutes mes lettres # le retour a la ligne est le caractère "\n" count_x = 0 count_y = 0 for letter in datas: print(count_x, count_y) if letter == "M": self.grid[(count_x, count_y)] = "wall" self.wall.append((count_x, count_y)) count_x = count_x + 1 if letter == "A": self.grid[(count_x, count_y)] = "macgyver" self.macgyver = Macgyver(count_x, count_y) count_x = count_x + 1 if letter == "B": self.grid[(count_x, count_y)] = "guardian" self.guardian = Guardian(count_x, count_y) count_x = count_x + 1 if letter == "C": self.grid[(count_x, count_y)] = "floor" self.floor.append((count_x, count_y)) count_x = count_x + 1 if letter == "S": self.grid[(count_x, count_y)] = "exit" count_x = count_x + 1 if letter == "\n": print("line break") count_x = 0 count_y = count_y + 1
def __init__(self): """Class constructor.""" self.caption = pg.display.set_caption("MacGyver Escape") self.display = pg.display.set_mode((600, 600)) self.needle = item_placement() self.tube = item_placement() self.ether = item_placement() self.syringe = letter_to_sprite('I')[1] self.guard = Guardian() self.hero = Hero() self.end_game = False
def load_maze(self, file_name): """load a list of lists of character, and replace by the tile image, defined in its class""" data = [] with open(file_name) as f: # f= line list -> first loop to add each line in "data" list for line in f: # second loop to add each tile in "line_data" list, # with its symbol defined in its class line_data = [] for tile in line: if tile == "G": line_data.append(Guardian()) elif tile == "#": line_data.append(Wall()) elif tile == " ": line_data.append(Lane()) elif tile == "M": line_data.append(McGyver()) # add each line_data in data data.append(line_data) return data
def main(): screen = pygame.display.set_mode((15 * sp_size, 15 * sp_size)) Lab = Labyrinth("mappy.txt", sp_size) Lab.convert_file_txt() Lab.get_pos() objects = Objects(Lab) objects.random() macgyver = MacGyver("mappy.txt", sp_size, objects, Lab) guardian = Guardian(sp_size) pygame.display.flip() current_game = True while current_game: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() elif event.type == pygame.KEYDOWN: if event.key == pygame.K_RIGHT: macgyver.move_right() elif event.key == pygame.K_LEFT: macgyver.move_left() elif event.key == pygame.K_UP: macgyver.move_up() elif event.key == pygame.K_DOWN: macgyver.move_down() macgyver.get_objects() Lab.get_pos() arbitror(macgyver, guardian) objects.display_objects() screen.blit(guardian.image, (guardian.rect.x, guardian.rect.y)) screen.blit(macgyver.image, (macgyver.rect.x, macgyver.rect.y)) macgyver.score_count() pygame.display.flip()
def execute(self): nytimes = NY_TIMES() cnn = CNN() guardian = Guardian() reddit = Reddit() wsj = WSJ() if self.application == 'all': print('...searching The New York Times') nytimes.search() nytimes.keywords() nytimes.mains() nytimes.top_stories() self.write_into_text(nytimes.all_mentions) print('...searching CNN') cnn.everything() self.write_into_text(cnn.all_mentions) print('...searching The Guardian') guardian.searches() self.write_into_text(guardian.num_articles) print('...searching Reddit') reddit.aggregate_submissions() reddit.aggregate_comments() self.write_into_text(reddit.all_mentions) print('...searching The Wall Street Journal') wsj.everything() self.write_into_text(wsj.all_mentions) self.total_mentions = (nytimes.total_mentions) + len( cnn.all_mentions) + (guardian.num_articles) + len( reddit.all_mentions) + len(wsj.all_mentions) print('There are a total of ' + str((self.total_mentions)) + ' mentions') print('The New York Times had ' + str((nytimes.total_mentions)) + ' mentions') print('CNN had ' + str(len(cnn.all_mentions)) + ' mentions') print('The Guardian had ' + str(guardian.num_articles) + ' mentions') print('Reddit had ' + str(len(reddit.all_mentions)) + ' mentions') print('The Wall Street Jornal had ' + str(len(wsj.all_mentions)) + ' mentions') print('...Generating your model') # Send the data to create the matplot graph self.data = [(nytimes.total_mentions), len(cnn.all_mentions), (guardian.num_articles), len(reddit.all_mentions), len(wsj.all_mentions)] self.data_labels = [ 'The New York Times', 'CNN', 'The Guardian', 'Reddit', 'The Wall Street Journal' ] plt.pie(self.data, labels=self.data_labels, autopct='%1.1f%%') plt.title('COVID-19 Mentions') plt.axis('equal') plt.show() elif self.application == 'nytimes': nytimes.search() nytimes.keywords() nytimes.mains() nytimes.top_stories() self.write_into_text(nytimes.all_mentions) self.total_mentions = nytimes.total_mentions print('The New York Times had ' + str(nytimes.total_mentions) + ' mentions') elif self.application == 'guardian': guardian.searches() self.write_into_text(guardian.all_mentions) self.total_mentions = guardian.num_articles print('The Guardian had ' + str(len(guardian.num_articles)) + ' mentions') elif self.application == 'cnn': cnn.everything() self.write_into_text(cnn.all_mentions) self.total_mentions = len(cnn.all_mentions) print('CNN had ' + str(cnn.all_mentions) + ' mentions') elif self.application == 'reddit': reddit.aggregate_submissions() reddit.aggregate_comments() self.write_into_text(reddit.all_mentions) self.total_mentions = len(reddit.all_mentions) print('Reddit had ' + str(len(reddit.all_mentions)) + ' mentions') elif self.application == 'wsj': wsj.everything() self.write_into_text(wsj.all_mentions) self.total_mentions = len(wsj.all_mentions) print('The Wall Street Journal had ' + str(len(wsj.all_mentions)) + ' mentions') else: print('Not a valid option')
def __init__(self, guardian1: Guardian, guardian2: Guardian, guardian3: Guardian): self.guardians = { guardian1.getGuardianNumber(): guardian1, guardian2.getGuardianNumber(): guardian2, guardian3.getGuardianNumber(): guardian3 }
def main(): #initialization os.environ['SDL_VIDEO_WINDOW_POS'] = "%d,%d" % (250, 30) pygame.init() pygame.mixer.init() clock = pygame.time.Clock() pygame.key.set_repeat(30) #Window configuration resolution = width, height = 800, 700 window = pygame.display.set_mode(resolution) pygame.display.set_caption("Guardian Hell") pygame.display.set_icon(pygame.image.load('./src/images/ico.png')) #Instantiation of player player = Guardian(guardianImagesPaths, soundPaths, [400, 200], 3, 0) ### Scenes statement scene0 = StartScreen(width, height, scenesPaths["startScreen"], "Press any key to start", soundPaths['start']) level1 = Level1(width, height, player, scenesPaths["level1"]) level2 = Level2(width, height, player, scenesPaths["level2"]) level3 = Level3(width, height, player, scenesPaths["level3"]) level4 = Level4(width, height, player, scenesPaths["level4"]) level5 = Level5(width, height, player, scenesPaths["level5"]) level6 = Level6(width, height, player, scenesPaths["level6"]) gameover = GameOver(player) #The scenes are added to an array that will be traversed as the level progresses scenes = [] scenes.append(scene0) scenes.append(level1) scenes.append(level2) scenes.append(level3) scenes.append(level4) scenes.append(level5) scenes.append(level6) scenes.append(gameover) #sceneNumber will be the index of the scene array sceneNumber = -1 runNextScene = True quit = False pygame.mixer.Sound(soundPaths['music']).play(-1) while (not quit): clock.tick(60) if (runNextScene): sceneNumber += 1 runNextScene = False #check if the player has lost all their lives and go to the "game over" scene if (player.lives <= 0): sceneNumber = len(scenes) - 1 #check if there are still scenes to go if (sceneNumber < len(scenes)): scenes[sceneNumber].initialize(window, player.points) #check if the current scene is the last and then restart the player lives and points if (sceneNumber == len(scenes) - 1): player.restart() else: #restart the scenes. Start from the start screen game sceneNumber = 0 scenes[sceneNumber].initialize(window) events = pygame.event.get() keysPressed = pygame.key.get_pressed() #run the scene behavior according to the events and return true if it must go to the next scene runNextScene = scenes[sceneNumber].runEvents(events, keysPressed, window, width, height) for event in events: quit = event.type == pygame.QUIT pygame.display.flip() pygame.quit()