def PollAndUpdate(self): self.error_text = None try: response = requests.get("http://localhost:6119/game") game_info = json.loads(response.text) self.game_time = game_info['displayTime'] for player in game_info['players']: name = player['name'] if self.villain is not None and name == self.villain.name: break elif name != self.cfg.hero: self.villain = Villain(name, self.cfg.data_dir) self.build = Build(player['race'], self.cfg.data_dir) self.view.SetNotesText(self.villain.GetNotes()) break else: self.error_text = 'No villain found.' except Exception as e: self.error_text = "Can't connect to API." print(e) self.UpdateView(self.view_format)
def __init__(self): self.challenge_rating = random.randint(2, 10) self.name = (templates.Template("{{output}}") .render(output="{{old1}}|{{old1}} {{old2}}|The {{adj}} {{noun}}", old1=old_language_generator.random_word(), old2=old_language_generator.random_word(), adj=vocab.get_adj(), noun=vocab.get_noun()).title()) self.location_description = templates.Template('{{sentence}}').render(sentence="{{name}} is {{locationphrase}} {{placement}}.", name=self.name.title(), locationphrase="located in|located on|constructed on|located under", placement="a_or_an {{adj}} tree|a_or_an {{adj}} plain|a_or_an {{adj}} city|a_or_an {{adj}} rift|a_or_an {{adj}} mountain", adj="alien|obsidion|crystal|spikey|giant|flooded|ruined|volcanic|cursed|poisoned|haunted|broken") self.parts_description = (templates.Template('{{sentence}}') .render(sentence="{{segment}} of {{name}} are {{state}}.", segment="Parts|Some areas|Regions|Some rooms", name=self.name.title()+"|it", state="cursed|corrupted|flooded|{{adj}} hot|{{adj}} cold|frozen|foggy|inaccessible|flooded", adj="incredibly|somewhat|unbearably")) self.circumstances_description = (templates.Template('{{sentence}}') .render(sentence="A_or_an {{outside_thing}} is happening outside.|The ruin is {{ruin_becoming}}.", outside_thing="massive storm|battle between raiders|solar eclipse|massive flood|windstorm|blizzard|lunar eclipse", ruin_becoming="flooding|coming to life|sinking into the earth|collapsing slowly|burning|larger on the inside than the outside")) self.artifact = Artifact() self.race = monsters.get_race(self.challenge_rating) self.race_description = (templates.Template('{{sentence}}') .render(sentence="It is occupied by {{plural_race}}.", plural_race=self.race)) self.villain = Villain(self) self.villain_sentence = (templates.Template('{{sentence}}') .render(sentence="{{villain}}, a_or_an {{villain_type}} is here.", villain=md_writer.phrase_with_anchor(self.villain.__str__()), villain_type=self.villain.monster.name)) self.race_villain_relation_sentence = (templates.Template("{{sentence}}") .render(sentence="The {{race_name}} {{relation}} {{villain}}.", race_name=self.race, relation="are the slaves of|have been charmed by|are ruled by|worship|are the minions of|are the soldiers of|are battling", villain=self.villain.__str__())) self.entrance = Room(self) self.entrance.set_connection('south', 'entrance') self.rooms = [self.entrance] rooms_to_build = random.randint(5, 15) while len(self.rooms) < rooms_to_build: random_room = choice(self.rooms) new_room = random_room.add_connected_room() if new_room is not None: self.rooms.append(new_room) random_room.artifact = self.artifact random_room = choice(self.rooms) random_room.villain = self.villain
class Ruin(object): def __init__(self): self.challenge_rating = random.randint(2, 10) self.name = (templates.Template("{{output}}") .render(output="{{old1}}|{{old1}} {{old2}}|The {{adj}} {{noun}}", old1=old_language_generator.random_word(), old2=old_language_generator.random_word(), adj=vocab.get_adj(), noun=vocab.get_noun()).title()) self.location_description = templates.Template('{{sentence}}').render(sentence="{{name}} is {{locationphrase}} {{placement}}.", name=self.name.title(), locationphrase="located in|located on|constructed on|located under", placement="a_or_an {{adj}} tree|a_or_an {{adj}} plain|a_or_an {{adj}} city|a_or_an {{adj}} rift|a_or_an {{adj}} mountain", adj="alien|obsidion|crystal|spikey|giant|flooded|ruined|volcanic|cursed|poisoned|haunted|broken") self.parts_description = (templates.Template('{{sentence}}') .render(sentence="{{segment}} of {{name}} are {{state}}.", segment="Parts|Some areas|Regions|Some rooms", name=self.name.title()+"|it", state="cursed|corrupted|flooded|{{adj}} hot|{{adj}} cold|frozen|foggy|inaccessible|flooded", adj="incredibly|somewhat|unbearably")) self.circumstances_description = (templates.Template('{{sentence}}') .render(sentence="A_or_an {{outside_thing}} is happening outside.|The ruin is {{ruin_becoming}}.", outside_thing="massive storm|battle between raiders|solar eclipse|massive flood|windstorm|blizzard|lunar eclipse", ruin_becoming="flooding|coming to life|sinking into the earth|collapsing slowly|burning|larger on the inside than the outside")) self.artifact = Artifact() self.race = monsters.get_race(self.challenge_rating) self.race_description = (templates.Template('{{sentence}}') .render(sentence="It is occupied by {{plural_race}}.", plural_race=self.race)) self.villain = Villain(self) self.villain_sentence = (templates.Template('{{sentence}}') .render(sentence="{{villain}}, a_or_an {{villain_type}} is here.", villain=md_writer.phrase_with_anchor(self.villain.__str__()), villain_type=self.villain.monster.name)) self.race_villain_relation_sentence = (templates.Template("{{sentence}}") .render(sentence="The {{race_name}} {{relation}} {{villain}}.", race_name=self.race, relation="are the slaves of|have been charmed by|are ruled by|worship|are the minions of|are the soldiers of|are battling", villain=self.villain.__str__())) self.entrance = Room(self) self.entrance.set_connection('south', 'entrance') self.rooms = [self.entrance] rooms_to_build = random.randint(5, 15) while len(self.rooms) < rooms_to_build: random_room = choice(self.rooms) new_room = random_room.add_connected_room() if new_room is not None: self.rooms.append(new_room) random_room.artifact = self.artifact random_room = choice(self.rooms) random_room.villain = self.villain def room_in_position(self, pos): for room in self.rooms: if pos[0] == 0 and pos[1] == -1: return True if pos[0] == room.pos[0] and pos[1] == room.pos[1]: return True return False def render(self): ruin_save_name = self.name.replace(" ", "-") ruin_map_file_name = ruin_save_name + ".png" grapher.save_graph(self, ruin_map_file_name) md_writer.print_title("Ruin Dogs") md_writer.print_sub_title(self.name) md_writer.print_chapter_heading("Overview") md_writer.print_chapter_sentence(self.location_description) md_writer.print_chapter_sentence(self.parts_description) md_writer.print_chapter_sentence(self.circumstances_description) md_writer.print_chapter_sentence(self.race_description) md_writer.print_chapter_sentence(self.villain_sentence) md_writer.print_chapter_sentence(self.race_villain_relation_sentence) md_writer.print_chapter_sentence(self.villain.motivation_description) md_writer.end_paragraph() md_writer.end_chapter() md_writer.print_chapter_heading("Artifact") self.artifact.render() md_writer.end_paragraph() md_writer.end_chapter() md_writer.print_chapter_heading("Locations") md_writer.end_chapter() md_writer.insert_image('../'+md_writer.output_folder+'/images/' + ruin_map_file_name, 'layout') for room in self.rooms: room.render() md_writer.end_paragraph() md_writer.end_novel(css='http://mattfister.github.io/ruindogs/base.css')
class Board: '''board class''' bricks = [] bricks2 = [] level1 = [] enemies = [] bullets = [] ebul = [] coins = [] flyer = Flyer(355, 35, 1, 0) player = Mario(620, 28, 5, 0, 0, 1) for j in range(40): row = [] for k in range(1000): row.append(" ") level1.append(row) enemy = Enemy(140, 20, 1, 0) enemies.append(enemy) enemy = Enemy(170, 32, 1, 0) enemies.append(enemy) enemy = Enemy(150, 32, -1, 0) enemies.append(enemy) enemy = Enemy(215, 20, 1, 0) enemies.append(enemy) enemy = Enemy(265, 32, 1, 0) enemies.append(enemy) enemy = Enemy(580, 32, 1, 0) enemies.append(enemy) enemy = Enemy(590, 32, 1, 0) enemies.append(enemy) vil = Villain(730, 22, 0, 10) brick(bricks) for i in range(70, 130, 5): brick = MakeBrick(i, 30, -2) bricks2.append(brick) coin = Coin(i + 1, 28) coins.append(coin) for i in range(50, 80, 5): brick = MakeBrick(i, 20, -2) bricks2.append(brick) coin = Coin(i + 1, 18) coins.append(coin) for i in range(10, 60, 5): brick = MakeBrick(i, 30, -2) bricks2.append(brick) coin = Coin(i + 1, 28) coins.append(coin) for i in range(100, 140, 5): brick = MakeBrick(i, 20, -2) bricks2.append(brick) coin = Coin(i + 1, 18) coins.append(coin) time = 0 alivev = 1 # print_background(level1) # draw_brick(level1,bricks) def print_board(self, k): '''print board function''' if self.player.level == 1: print_background(self) print_player(self) draw_brick(self, self.bricks) print_enemy(self) print_bullet(self, self.bullets) print_bullet(self, self.ebul) if self.alivev == 1: print_villain(self, self.vil.posx, self.vil.posy) if self.alivev == 0: win(self) # time.sleep(3) temp = "" string = '\033[93m' + "Life=" + str( self.player.life) + " Score=" + str( self.player.score) + " Coins=" + str( self.player.coins) + "\n" + '\033[0m' if k >= 550 and self.alivev == 1: string += '\033[93m' + "Boss Life=" + \ str(self.vil.life) + "\n" + '\033[0m' temp += string for i in range(40): for j in range(k, k + 150, 1): temp += self.level1[i][j] print(temp) else: print_background(self) print_player(self) draw_brick(self, self.bricks2) draw_coin(self, self.coins) if time.time() - self.time >= 0.3: write(self) self.time = time.time() temp = "" string = '\033[93m' + "Life=" + str( self.player.life) + " Score=" + str( self.player.score) + " Coins=" + str( self.player.coins) + "\n" + '\033[0m' temp += string for i in range(40): for j in range(k, k + 150, 1): temp += self.level1[i][j] print(temp) def dum(self): '''dummy method''' return self
def start_game(screen): height, width = os.popen( 'stty size', 'r' ).read().split() #this obtains board size and width as dependent on the terminal size config.height = int( height ) - 8 config.width = int( width ) * 5 config.frame_width = int( width ) Coin = coins.Coins() Obs = obstacles.Obstacles() Bullets = bullets.Bullet() Mag=Magnet() ice=bullets.Bullet() screen.create_board( height, width, Coin, Obs, Mag ) player = hero.Hero( 4, 40 ) # creating hero with co ordinates config.time_left = 500 config.start_time = time() screen.refresh_screen( player,Bullets ) dragon_flag=0 Dragon=Villain(config.width-49,player.get_y()) itr=1 quitter=False while ((not game_state.is_game_over()) and (config.time_left > 0) and (not quitter)): player.gravity() player.magnet_effect(Mag.get_y(),Mag.get_start(),Mag.get_end()) #to put the effect of the magnet on the hero quitter=player.movehero( screen.get_screen(), Bullets) game_state.coin_check( screen.get_screen() ) game_state.place_bullets( screen.get_screen(), Bullets, Obs ,dragon_flag) config.time_left = 500-(time()-config.start_time) screen.refresh_screen( player ,Bullets) if config.start_col < 4 * int( width ): # for moving the board frame config.start_col += 1 + config.boost_speed else: #this takes place when in the last frame dragon_flag=1 Dragon.update(player.get_y(),ice,screen.get_screen()) game_state.place_ice(screen.get_screen(),ice,player) if config.boost_end_time <= time(): #to handle power ups if config.state == 'u': if config.boost_speed!=0: config.boost_speed = 0 elif config.shield!=0: config.shield=0 config.state = 'c' config.boost_end_time=time()+10 elif config.state=='c': config.boost_end_time=time()+10 config.state='r' itr+=1 if player.get_y()<config.height-3: config.hangtime+=1 if config.result == 1: print( "\nYOU WON !!!!!!!!! :)" ) else: print( "YOU LOST :( :( :(" ) print( "SCORE:- %d" % (config.score) )
def quest_enemy(self): """Returns an enemy for revenge/killing based quests""" villain = Villain() self.enemy = villain.main()
print("\nCreando Arco") heroBow = Bow("Armatus", 4, 7, 70) print("Equipando arco ...") hero.equip(heroBow) print("\nCreando Escudo") heroShield = Shield("Aegis", 10, 10) print("Equipando escudo ...") hero.equip(heroShield) print("--------------------") #ENEMIGO print("Creando Enemigo") villain = Villain("Rixton", 45, 100) villain.details() #villain.equipment() print("--------------------") print("\nCreando Espada") villainSword = Sword("Dark Sword", 5, 11, 100) print("Equipando espada ...") villain.equip(villainSword) print("\nCreando Arco") villainBow = Bow("Dark Bow", 2, 9, 70) print("Equipando arco ...") villain.equip(villainBow)
class Controller: def __init__(self): self.cfg = config.Config() self.view = View(self.LblLeftClickHandler, self.LblRightClickHandler, self.NotesUpdatedHandler, self.ViewToggleHandler) self.view_format = ViewFormat.LABEL_ONLY self.view.SetViewFormat(self.view_format) self.villain = None self.build = None self.error_text = None self.game_time = 0.0 self.view.AddTask(self.PollAndUpdate, 1000) # client api: # https://us.battle.net/forums/en/sc2/topic/20748195420 def PollAndUpdate(self): self.error_text = None try: response = requests.get("http://localhost:6119/game") game_info = json.loads(response.text) self.game_time = game_info['displayTime'] for player in game_info['players']: name = player['name'] if self.villain is not None and name == self.villain.name: break elif name != self.cfg.hero: self.villain = Villain(name, self.cfg.data_dir) self.build = Build(player['race'], self.cfg.data_dir) self.view.SetNotesText(self.villain.GetNotes()) break else: self.error_text = 'No villain found.' except Exception as e: self.error_text = "Can't connect to API." print(e) self.UpdateView(self.view_format) def UpdateView(self, view_format): # Try to change view format. if self.error_text is not None: if view_format == ViewFormat.TAB: self.view_format = view_format else: self.view_format = ViewFormat.LABEL_ONLY elif view_format == ViewFormat.TAB or view_format == ViewFormat.LABEL_ONLY: self.view_format = view_format elif view_format == ViewFormat.NOTES_VIEW: if self.villain is not None: self.view_format = view_format elif view_format == ViewFormat.BUILD_VIEW: if self.build is not None: self.view_format = view_format # Set label text if self.view_format == ViewFormat.TAB: self.view.SetLabelText('') elif self.error_text is not None: self.view.SetLabelText(self.error_text) elif self.view_format == ViewFormat.BUILD_VIEW: self.view.SetLabelText('{}: {}'.format(self.build.race, self.build.name)) else: self.view.SetLabelText(self.villain.name) # Other stuff if self.view_format == ViewFormat.BUILD_VIEW: self.view.SetBuildText( past=self.build.GetBuildText(before=self.game_time), future=self.build.GetBuildText(earliest=self.game_time)) self.view.SetViewFormat(self.view_format) def Run(self): self.view.Run() # Make us smaller. def LblLeftClickHandler(self, e): if self.view_format == ViewFormat.TAB: pass elif self.view_format == ViewFormat.LABEL_ONLY: self.UpdateView(ViewFormat.TAB) else: self.UpdateView(ViewFormat.LABEL_ONLY) # Make us bigger. def LblRightClickHandler(self, e): if self.view_format == ViewFormat.TAB: self.UpdateView(ViewFormat.LABEL_ONLY) elif self.view_format == ViewFormat.LABEL_ONLY: self.UpdateView(ViewFormat.NOTES_VIEW) def NotesUpdatedHandler(self, e): self.villain.SaveNotes(self.view.GetVillainNotes()) def ViewToggleHandler(self): if self.view_format == ViewFormat.NOTES_VIEW: self.UpdateView(ViewFormat.BUILD_VIEW) elif self.view_format == ViewFormat.BUILD_VIEW: self.UpdateView(ViewFormat.NOTES_VIEW)