def play(self, tempo): with play.Player() as player: for n, command in enumerate(self.command_list): command.run() if n < len(self.command_list) - 1: next_offset = self.command_list[n + 1].offset - command.offset time.sleep((tempo / 60) * float(next_offset))
def test_gen_stat(self, mocked_ondie): mocked_luck = 1 mocked_stamina = 1 mocked_skill = 1 mocked_ondie.side_effect = [mocked_luck, mocked_stamina, mocked_skill] myplayer = play.Player() myplayer.gen_stat() self.assertEqual(myplayer.skill, play.Player.BASE_SKILL + mocked_skill) self.assertEqual(myplayer.stamina, play.Player.BASE_STAMINA + mocked_stamina) self.assertEqual(myplayer.luck, play.Player.BASE_LUCK + mocked_luck)
def test_init(self): initialPotion = "blah" initialSkill = 10 initialStamina = 10 initialLuck = 10 initialEquipment = ["fire ring", "shield"] myplayer = play.Player(potion=initialPotion, skill=initialSkill, stamina=initialStamina, equipment=initialEquipment, luck=initialLuck) self.assertEqual(myplayer.potion, initialPotion) self.assertEqual(myplayer.skill, initialSkill) self.assertEqual(myplayer.stamina, initialStamina) self.assertEqual(myplayer.luck, initialLuck) self.assertEqual(myplayer.equipment, initialEquipment)
def test_luck(self, mocked_twodie): initialPotion = "blah" initialSkill = 10 initialStamina = 10 initialLuck = 10 initialEquipment = ["fire ring", "shield"] myplayer = play.Player(potion=initialPotion, skill=initialSkill, stamina=initialStamina, equipment=initialEquipment, luck=initialLuck) mocked_twodie.side_effect = [6, 12] lucky = myplayer.test_luck() self.assertTrue(lucky) self.assertEqual(myplayer.luck, initialLuck -1) lucky = myplayer.test_luck() self.assertFalse(lucky) self.assertEqual(myplayer.luck, initialLuck -2)
def test_player_print(self, mocked_print): initialPotion = "blah" initialSkill = 10 initialGold = 100 initialStamina = 10 initialLuck = 10 initialEquipment = ["fire ring", "shield"] myplayer = play.Player(gold=initialGold, potion=initialPotion, skill=initialSkill, stamina=initialStamina, equipment=initialEquipment, luck=initialLuck) myplayer.print_player() assert mocked_print.mock_calls == [call("Gold: ", initialGold) , call("Potion: ", initialPotion) , call("Skill: ", initialSkill) , call("Stamina: ", initialStamina) , call("Luck: ", initialLuck) ,call("Equipment: ", initialEquipment) ]
def test_luck(self, mocked_twodie): initialPotion = "blah" initialSkill = 10 initialStamina = 10 initialLuck = 10 initialEquipment = ["fire ring", "shield"] myplayer = play.Player(potion=initialPotion, skill=initialSkill, stamina=initialStamina, equipment=initialEquipment, luck=initialLuck) mocked_twodie.side_effect = [6, 12] # Passes luck test myplayer.flee(try_luck=True) self.assertEqual(myplayer.stamina, initialStamina -1) # Fails luck test myplayer.flee(try_luck=True) self.assertEqual(myplayer.stamina, initialStamina -3 ) # Dont use luck myplayer.flee() self.assertEqual(myplayer.stamina, initialStamina -5 )
def play(track_id, station_id=None): import re import play import xbmc track = rhapsody.tracks.detail(track_id) stream = helpers.get_stream(track_id) if stream is None: plugin.notify(_(30107).encode('utf-8')) return item = helpers.get_track_item(track) item['path'] = stream.url notify = play.Notify(rhapsody, track, stream) player = play.Player(plugin=plugin, notify=notify) plugin.set_resolved_url(item) # add upcoming station tracks to playlist if station_id is not None: playlist = xbmc.PlayList(xbmc.PLAYLIST_MUSIC) current_pos = playlist.getposition() + 1 playlist_target_size = current_pos + 5 if playlist.size() < playlist_target_size: next_tracks = rhapsody.stations.tracks(station_id, offset=current_pos, count=playlist_target_size - playlist.size()).tracks for next_track in next_tracks: plugin.log.info( 'Preload: Adding next station track {0:d} of {1:d}: {2:s}'. format(playlist.size() + 1, playlist_target_size, next_track.id)) next_item = helpers.get_track_item(next_track) next_item['path'] = plugin.url_for( 'stations_play', station_id=station_id, current_track_id=next_track.id) plugin.add_to_playlist([next_item], playlist='music') # query the next playlist item so it'll be added to the cache for seamless playback prefetch_enabled = plugin.get_setting('api_prefetch', converter=bool) if prefetch_enabled and rhapsody.ENABLE_CACHE: playlist = xbmc.PlayList(xbmc.PLAYLIST_MUSIC) next_pos = playlist.getposition() + 1 if next_pos >= playlist.size(): next_pos = 0 next_url = playlist[next_pos].getPath() next_track_id = None url_patterns = [ re.escape(plugin.url_for('play', track_id='-track_id-')).replace( re.escape('-track_id-'), '(?P<track_id>[^/]+)'), re.escape( plugin.url_for('stations_play', station_id='-station_id-', current_track_id='-track_id-')).replace( re.escape('-station_id-'), '(?P<station_id>[^/]+)').replace( re.escape('-track_id-'), '(?P<track_id>.+)') ] for url_pattern in url_patterns: match = re.match(url_pattern, next_url) if match is not None: next_track_id = match.group(1) if next_track_id is not None and next_track_id != track_id: plugin.log.info( 'Preload: Caching next playlist position {0:d} ({1:s})'.format( next_pos, next_track_id)) try: rhapsody.tracks.detail(next_track_id) helpers.get_stream(next_track_id) except exceptions.ResourceNotFoundError: pass # wait for the current item to finish before exiting monitor = xbmc.Monitor() while not monitor.abortRequested() and not player.has_stopped: if monitor.waitForAbort(1): break plugin.log.info('Player: Exited')
import play import combatant myplayer = play.Player() myplayer.gen_stat() potions = ["Stamina", "Skill", "Strength"] print("Choose one adventurer potion") for i, f in enumerate(potions, start=1): option = f"For {f} press {i}" print(option) myplayer.potion = potions[int(input("Enter (1-3)"))] myplayer.print_player() c1 = combatant.Combatant(3, 3, "Goblin") c2 = combatant.Combatant(4, 4, "Troll") combatants = [c1, c2] while (1): for c in combatants: if c.dead(): continue if c.combat_roll() > myplayer.combat_roll(): print("Player damage") myplayer.takedamage(2) else: print("c damage") c.takedamage(2) print("c stamina", c.stamina)
def play(track_id, station_id=None): import re import play import xbmc track = rhapsody.tracks.detail(track_id) stream = rhapsody.streams.detail(track_id) item = helpers.get_track_item(track) if stream.url.startswith('rtmp://'): parts = [ '/'.join(stream.url.split('/')[:5]), 'app=' + '/'.join(stream.url.split('/')[3:5]), 'playpath=' + 'mp3:' + '/'.join(stream.url.split('/')[5:]) ] item['path'] = ' '.join(parts) else: item['path'] = stream.url notify = play.Notify(rhapsody, track, stream) player = play.Player(plugin=plugin, notify=notify) plugin.set_resolved_url(item) # add upcoming station tracks to playlist if station_id is not None: playlist = xbmc.PlayList(xbmc.PLAYLIST_MUSIC) current_pos = playlist.getposition() playlist_target_size = current_pos + 5 while playlist.size() <= playlist_target_size: next_tracks = rhapsody.stations.tracks(station_id).tracks[:5] if len(next_tracks) == 0: break for next_track in next_tracks: plugin.log.info( 'Preload: Adding next station track {0:d} of {1:d}'.format( playlist.size(), current_pos + 5)) next_item = helpers.get_track_item(next_track) next_item['path'] = plugin.url_for( 'stations_play', station_id=station_id, current_track_id=next_track.id) plugin.add_to_playlist([next_item], playlist='music') # query the next playlist item so it'll be added to the cache for seamless playback prefetch_enabled = plugin.get_setting('api_prefetch', converter=bool) if prefetch_enabled and rhapsody.ENABLE_CACHE: playlist = xbmc.PlayList(xbmc.PLAYLIST_MUSIC) next_pos = playlist.getposition() + 1 if next_pos >= playlist.size(): next_pos = 0 next_url = playlist[next_pos].getfilename() next_track_id = None url_patterns = [ re.escape(plugin.url_for('play', track_id='-track_id-')).replace( re.escape('-track_id-'), '(?P<track_id>[^\/]+)'), re.escape( plugin.url_for('stations_play', station_id='-station_id-', current_track_id='-track_id-')).replace( re.escape('-station_id-'), '(?P<station_id>[^\/]+)').replace( re.escape('-track_id-'), '(?P<track_id>.+)') ] for url_pattern in url_patterns: match = re.match(url_pattern, next_url) if match is not None: next_track_id = match.group('track_id') if next_track_id is not None: plugin.log.info( 'Preload: Caching next playlist position {0:d} ({1:s})'.format( next_pos, next_track_id)) rhapsody.tracks.detail(next_track_id) rhapsody.streams.detail(next_track_id) # wait for the current item to finish before exiting while not xbmc.abortRequested and not player.has_stopped: xbmc.sleep(10) plugin.log.info('Player: Exited') return plugin.finish()