def __generate_monster(self, n_properties): # берем случайного персонажа из списка персонажей person = self.base_character_list[random.randint( 0, len(self.base_character_list) - 1)] # количество n проперти prop_list = (np.random.choice(self.property_list, n_properties, replace=False).tolist()) a = len(prop_list) names_prop = [] hp_bonus = 0 att_bonus = 0 for i in range(a): names_prop.append(prop_list[i].name) hp_bonus += prop_list[i].health_bonus att_bonus += prop_list[i].attack_bonus sort_names_prop = sorted(names_prop) result_name = ' '.join(sort_names_prop) # возвращает персонажа с проп if (person.max_health + hp_bonus) < 1: reroll = self.__generate_monster(n_properties) return reroll else: if hp_bonus != 0 and att_bonus != 0: new_character = Character( (result_name + ' ' + person.name).capitalize(), hp_bonus + person.max_health, att_bonus + person.get_attack_damage()) else: new_character = Character((f'{person.name}').capitalize(), person.max_health, person.get_attack_damage()) return new_character
def __init__(self) -> None: self.player = Character() self.dealer = Dealer() self.menu = ActionMenu(self.dealer) self.minimum = 10 self.maximum = int(self.minimum * 1.5) self.bet = 0
def __init__(self): os.system("clear") self.inRoom = True self.player = Character("player") self.R = -1 self.condit = reader.readRoom("txtStory/intro.txt", self.R) self.printCondit()
def addCharacter(self, name = None, gender = None): if gender == None: gender = Gender.getRandomGender() if name == None: name = self.namegen.generateFirstName(gender) c = Character(len(self.characters), name, gender) self.characters.append(c)
def checkregistry(data): with open('database.txt', mode='r') as database: if data["warriorname"] and data["password"] in database: print('already exists') return redirect("/signin.html") else: write_to_file(data) write_to_csv(data) global userid userid += len(database.readlines()) username = data["warriorname"] password = data["password"] charactername = data["username"] userage = data['age'] useralive = True userhp = 30 userac = 6 userxp = 1 userlvl = 1 userammo = 6 userstr = (random.randint(3, 18)) userdex = (random.randint(3, 18)) usercon = (random.randint(3, 18)) userofd = data['objectOfDesire'] print('wrote to file') global hero hero = Character(userid,charactername, userage, useralive, userhp, userac, userxp, userlvl, userammo, userstr, userdex, usercon, userofd) print(hero.name)
def shuffle_players(self): self.players_qty = len(self.players_info) self.player_distribution = np.array([ list(range(1, 11)), [1, 1, 2, 3, 3, 4, 4, 5, 6, 6], [0, 1, 1, 1, 2, 2, 3, 3, 3, 4] ]) print(self.players_qty) player_col = np.where( self.player_distribution[0] == self.players_qty)[0][0] print(self.player_distribution) print(player_col) print(self.players_qty) self.good_qty = int(self.player_distribution[1][player_col]) self.bad_qty = self.good_qty = int( self.player_distribution[2][player_col]) players = [] alignment_array = np.ones(self.players_qty) alignment_array[:self.bad_qty] = 0 np.random.shuffle(alignment_array) for i in range(self.players_qty): players.append( Character( bool(alignment_array[i]), { 'number': i + 1, 'discord_id': self.players_info[i]["discord_id"], 'name': self.players_info[i]["name"] })) roles = random.sample(range(self.players_qty), 2) self.merlin_player = roles[0] self.assassin_player = roles[1] players[roles[0]].assassin = True players[roles[1]].merlin = True self.char = players print("O Merlin é o jogador: ", self.char[roles[1]].player_number) print("O Assassino é o jogador: ", self.char[roles[0]].player_number)
def make_character_user_set_attribute_levels(name): return Character( name, get_positive_whole_number_from_user( "Please enter the strength for %s." % name), get_positive_whole_number_from_user( "Please set the skill level for %s." % name))
def signinfunc(data): with open('database.txt', mode='r') as database: for line in database.readlines(): hgrab = json.loads(line) if data["warriorname"] == hgrab["warriorname"] and data["password"] == hgrab["password"]: print('character found') global hero hero = Character(hgrab["userid"],hgrab["username"],hgrab["age"],hgrab["useralive"],hgrab["userhp"],hgrab["userac"],hgrab["userxp"],hgrab["userlvl"],hgrab["userammo"],hgrab["userstr"],hgrab["userdex"],hgrab["usercon"],hgrab["userofd"]) else: print('character not found')
def test_inits(self): char = C.Character('Grognak') # YOU MADE A CHARACTER self.assertIsInstance(char,C.Character) # You made a hero hero = H.Hero('Grognak', [20, 20]) self.assertIsInstance(hero, H.Hero) # You made a monster monster = M.Monster('Goblin', 5, 5, 1) self.assertIsInstance(monster,M.Monster)
def __init__(self): self.player = Character() self.monsters = [Goblin(), Troll(), Dragon()] self.monster = self.get_next_monster() # game loop while self.player.hit_points and (self.monster or self.monsters): print('\n' + '=' * 20) print(self.player) self.monster_turn() print('-' * 20) self.player_turn() self.cleanup() print('\n' + '=' * 20) if self.player.hit_points: print("You win!") elif self.monster or self.monsters: print("You lose!") sys.exit()
def do_attack(self, fight_time): self.next_attack += dt.timedelta(seconds=fight_time) targets = Character.find_by_location(*(Map.boss_location()), connection=self.connection) if len(targets) == 0: self.state = self.State.PASSIVE self.hp = self._max_hp self.lvl += 1 return target = random.choice(targets) if self.attack_target(target) or self.attack_target(target): self.hp += self.hp_regen return target
def make_first_city(self, models): self.active = True r = lambda: random.randint(0, 255) self.color = '#%02X%02X%02X' % (r(), r(), r()) new_culture = False self.food_limit = 750 if self.culture == None: self.culture = Culture(self.color) new_culture = True self.name = self.culture.generate_name(models, "t") while len(self.name) < 6 or len( self.name ) > 10 or ' ' in self.name or '-' in self.name or ')' in self.name: self.name = self.culture.generate_name(models, "t") if new_culture: self.culture.name = self.name + "ian" self.leader = Character(models, self.culture, self, 40) ### CREATE TITLE self.title = Title(self.name, None, [], [self], 1) self.title.setGovFormGameStart(self.leader.focus) self.leader.titles.append(self.title) self.leader.refresh_fullname() self.chars.append(self.leader) for f in self.field.field_neighbor(10): if f.city is not None: if f.city.culture == None: f.city.culture = self.culture for f in self.field.field_neighbor(1): if f.owner is not None: if not f.owner.active: f.owner = self self.territory.append(f) else: f.owner = self self.territory.append(f) self.calculate_values() self.detect_resources() self.pop = self.wealth * 10 + random.randint(-100, 100) self.wpc = self.wealth / self.pop
def __init__(self): MapBase.__init__(self,20,20) self.set_regen_rate(1) self.set_location( (0,0), 'stone', False ) self.set_location( (1,1), 'stone', False ) self.set_location( (2,2), 'stone', False ) self.set_location( (3,2), 'stone', False ) self.set_location( (4,2), 'stone', False ) self.set_location( (5,2), 'stone', False ) self.set_location( (6,1), 'stone', False ) self.set_location( (7,0), 'stone', False ) # Put a wise dude here, to talk to. sprite = Character('dude_map') self.place_entity( sprite, (8,1) ) sprite.face(SOUTH) sprite.always_animate = True sprite.animation_speed = 10 self.add_entry_listener(8,2, self.walk_in_front_of_dude) self.add_entry_listener(8,3, self.random_fight) # Place the armor merchant armor_dude = ArmorMerchant('dude_map') self.place_entity( armor_dude, (12,4) ) armor_dude.face(WEST) armor_dude.always_animate = True armor_dude.animation_speed = 4 # Place the weapon merchant weapon_dude = WeaponMerchant('dude_map') self.place_entity( weapon_dude, (12,6) ) weapon_dude.face(WEST) weapon_dude.always_animate = True weapon_dude.animation_speed = 5 tp = NPC.Townsperson('dude_map') self.place_entity(tp, (7,7) ) tp.animation_speed = 5 tp.set_dialog(( "Hi", "Yeah, what?", "You still here?", \ "Why are you talking to me?", "I don't know anything that would help you", "ok, you must be bored", "please leave me alone"))
def make_city(self, models, interface): self.active = True r = lambda: random.randint(0, 255) self.color = '#%02X%02X%02X' % (r(), r(), r()) new_culture = False if self.culture == None: self.culture = Culture(self.color) new_culture = True self.name = self.culture.generate_name(models, "t") while len(self.name) < 4 or len( self.name ) > 10 or ' ' in self.name or '-' in self.name or ')' in self.name: self.name = self.culture.generate_name(models, "t") if new_culture: self.culture.name = self.name + "ian" self.leader = Character(models, self.culture, self, 40) self.chars.append(self.leader) for f in self.field.field_neighbor(10): if f.city is not None: if f.city.culture == None: f.city.culture = self.culture #~ f.city.change_color(interface) if interface.mapmode != "t": self.change_color(interface) if interface.mapmode != "t": self.claim_field(self.field, interface) for f in self.field.field_neighbor(1): if f.owner is not None: if not f.owner.active: f.owner = self self.territory.append(f) if interface.mapmode != "t": self.claim_field(f, interface) else: f.owner = self self.territory.append(f) if interface.mapmode != "t": self.claim_field(f, interface) interface.inner_map.update_idletasks()
def create_player(data, arm_types, wpn_types, arm_mods, wpn_mods, create=True): # Inputs # Input number of armor type character = Character(data["character"]) character.suite_armor(Armor(data['armor_name'], arm_types[data['armor_type']])) character.take_weapon(Weapon(data['weapon_name'], wpn_types[data['weapon_type']], data['hand_coeff'])) character.armor.add_modification(arm_mods[data['armor_mod']]) character.weapon.add_modification(wpn_mods[data['weapon_mod']]) if not create: with open(f'{SAVE_FOLDER}{data["character"]}.json', 'w') as outfile: json.dump(data, outfile) return character
# Name: Subanaya Thirunavukkarasu # Description: Final project for CS 30 # imports from characters import Character, Inventory import maps print("It's 2080. Welcome to The City, a place so polluted") print("that fog covers everything, and oxygen tanks are required\n\n") print("Objective: Escape The City\n") print("Explore the map and defeat the enemy of any location") print("to escape The City.\n") print("To begin, choose a character\n") # character descriptions character_one = Character('Evelyn', 'ambitious', 'strength', 100) print(character_one.__str__()) character_two = Character('Avery', 'funny', 'speed', 100) print(character_two.__str__()) # this list will be used later in the Function # user_action_3. The character chosen will affect the # outcome of the user's choices when fighting enemies chosen_character = [] # this list will be user later in the function # user_action_3. The items in the inventory will affect # the user's choices when fighting enemies character_inventory = []
# rpg, broń postaci from weapons import Wand, Sword from characters import Character from time import perf_counter as getTime player = Character("Rektor", 1000) victim = Character("student", 100) # nasze "strategie", bronie sword = Sword(5) wand = Wand(10, 1000) # atak bez broni print("# pięści") player.attack(victim) print() # wyposażenie w broń player.setWeapon(sword) print("# miecz") player.attack(victim) player.attack(victim) print() # wyposażenie w inną broń player.setWeapon(wand) print("# różdżka") player.attack(victim) player.attack(victim) # <- to nie wyjdzie, bo cooldown 1s curr_time = getTime()
"all'ultimo piano del monastero", "al terzo piano del monastero" ], "exits": { "Monastero-inner-2": [ ExitDescription("verso i", "da", "l piano di sotto"), ExitDescription("verso i", "da", "l piano inferiore"), ] }, "variants": {} } }, world_size=50 ) veggero = Character( description=Description('ragazzo carino', 'ragazzi carini', 'ragazzo', 'ragazzi') ) nicole = Character( description=Description('ragazza carina', 'ragazze carine', 'ragazza', 'ragazze', '','una', 'la', 'le', 'delle') ) world.spawn(veggero, world.places[0]) world.spawn(nicole, world.places[0]) Telegram('508857997:AAGYf6PS09WSZ_mjlOlooj-YtIU4fPlYijs', world, {302001216: veggero}) #302001216: veggero #186405135: nicole #1229891893: veggero2
from characters import Character, Hero from monster_creator import Property, Monster_creater from inventory import Health_potion from images import kitten, pooch, c**k, viper, tigress, assasin, warrior, prophet import numpy as np properties = [ Property('survivalist', 140, 0), Property('strong', 0, 25), Property('berserk', -100, 50), Property('elite', 200, 30), Property('weak', -30, -10) ] characters = [ Character('cat', 50, 15, kitten), Character('dog', 70, 10, pooch), Character('chicken', 60, 20, c**k), Character('dragon', 150, 40, viper), Character('tiger', 100, 30, tigress) ] ''' heroes = [ Hero('Alexa', 400, 35, 'agility', 3, 5, 2, assasin), Hero('Max', 650, 30, 'strength', 6, 3, 1, warrior), Hero('Furion', 350, 25, 'intelligence', 2, 4, 7, prophet) ] ''' thief = Hero('Alexa', 400, 35, 'agility', 3, 5, 2, assasin) defender = Hero('Maximus', 650, 30, 'strength', 6, 3, 1, warrior) prophet = Hero('Furion', 350, 25, 'intelligence', 2, 4, 7, prophet)
player.born_again() # print(self) random.shuffle(self.players) def round(self, first_inp, second_inp): return self.results_dict[(first_inp, second_inp)] def __repr__(self): self.players.sort(reverse=True, key=lambda x: x.score) league_table = pd.DataFrame([p.to_dict() for p in self.players]) return str(league_table) if __name__ == '__main__': type_A = Character('cheat', action=0) # type_B = Character('cooperate', action=1) type_C = Character('copycat') # type_D = Character('grudger') # type_E = Character('detective') type_F = Character('copykitten') type_G = Character('simpleton') type_H = Character('random') new_sim = Game(10, 5, 0.05) new_sim.populate(type_A, 13) # new_sim.populate(type_B, 13) new_sim.populate(type_C, 3) # new_sim.populate(type_D, 1) # new_sim.populate(type_E, 1) new_sim.populate(type_F, 3)
from flask import Flask, redirect, url_for, render_template, request from characters import Character, skeleton, wraith import random import csv import json app = Flask(__name__) enemy = skeleton hero = Character(0,"Empty", 1, True, 1, 1, 1, 1, 1, 1, 1, 1, "Empty") userid = 0 userid += 1 lvldict = {"lvl0": 0, "lvl1":1, 'lvl2': 300, 'lvl3': 1000, 'lvl4':2000, 'lvl5':5000,'lvl6':8000,'lvl7':12000} def write_to_file(data): with open('database.txt', mode='r+') as database: global userid userid += len(database.readlines()) data['userid'] = userid username = data["warriorname"] password = data["password"] charactername = data["username"] userage = data['age'] data['useralive'] = True data['userhp'] = 30 data['userac'] = 6 data['userxp'] = 1
def spawn(self, character: Character, place: Optional[Place]=None): place = place or choice([*self.places]) place.contained.add(character) character.place = place character.world = self
def load_save(save_name=""): save_file = shelve.open("saves/save") save_load = save_file[save_name] player_chars = [] player_name = save_load[0][0] for char_li in save_load[:-1]: temp_char = Character([0, 0]) temp_char.name = char_li[0] temp_char.health = char_li[1] temp_char.max_health = char_li[2] temp_char.attack = char_li[3] temp_char.ammo = char_li[4] temp_char.max_ammo = char_li[5] temp_char.mana = char_li[6] temp_char.max_mana = char_li[7] temp_char.attacks = char_li[8] temp_char.equipped_items = char_li[9] player_chars.append(temp_char) rounds = save_load[-1] player_party = Party(player_chars) save_file.close() return [player_name, player_party, rounds]
Item( "chestplate", "The armour glitters with thick scales, but it has been used often. Its fabric is dirty and torn.", False, False, None, None)) def temp(target): target.health -= 1 data["Clearing"].add_item( Item("sword", "A simple longsword, rusted with disrepair.", False, True, temp, None)) #ADD CHARACTERS HERE goblin = Character( "goblin", 2, False, "A small goblin. He seems extremely oblivious, but will attack if provoked." ) goblin.add_attack(Attack(1, "The goblin swipes at you!")) data["Clearing"].add_character(goblin) data["Crossroads"].add_character( Character( "Guide of Astralon", 10, False, "A man materializes in thin air on the road-bend. He's wearing a golden cloak and his long beard floats over his thin locket. There's a soft halo around the ground on which he stands. You can ask him for advice if you wish." )) data["Pond of Healing"].add_character( Character( "Tikki", 5, True, "A small bouncy fairy, with bright eyes and dark locks. She wears a simple dark blue dress that drapes around her shoulders." )) data["Quezlat's Hill"].add_character(
def intro(): gameExit = False spritesheet = SpriteSheet('tiles/sheet.png') ground1 = spritesheet.image_at((0, 0, ts, ts)) ground2 = spritesheet.image_at((ts, 0, ts, ts)) ground3 = spritesheet.image_at((ts * 2, 0, ts, ts)) fence = spritesheet.image_at((0, ts * 22, ts, ts), -1) path1 = spritesheet.image_at((ts * 5, 0, ts, ts)) tree2 = spritesheet.image_at((ts * 2, ts, ts * 2, ts * 2), -1) log = spritesheet.image_at((ts * 6, ts * 5, ts * 2, ts), -1) skull = spritesheet.image_at((ts * 6, ts * 131, ts, ts), -1) morgan = Character('morgan', 20, 20) # scale things.. ground1 = pygame.transform.scale(ground1, (scalesize, scalesize)) ground2 = pygame.transform.scale(ground2, (scalesize, scalesize)) ground3 = pygame.transform.scale(ground3, (scalesize, scalesize)) path1 = pygame.transform.scale(path1, (scalesize, scalesize)) tree2 = pygame.transform.scale(tree2, (scalesize * 2, scalesize * 2)) fence = pygame.transform.scale(fence, (scalesize, scalesize)) log = pygame.transform.scale(log, (scalesize * 2, scalesize)) skull = pygame.transform.scale(skull, (scalesize, scalesize)) background = ( ("G2", "G2", "G2", "G2", "G2", "P1", "P1", "P1", "G2", "G2", "G2", "G2", "G2"), ("G2", "G2", "G2", "G2", "G2", "P1", "P1", "P1", "G2", "G2", "G2", "G2", "G2"), ("G2", "G2", "G2", "G2", "G2", "P1", "P1", "P1", "G2", "G2", "G2", "G2", "G2"), ("G2", "G2", "G2", "G2", "G2", "P1", "P1", "P1", "G2", "G2", "G2", "G2", "G2"), ("G2", "G2", "G2", "G2", "G2", "P1", "P1", "P1", "G2", "G2", "G2", "G2", "G2"), ("G2", "G2", "G2", "G2", "G2", "P1", "P1", "P1", "G2", "G2", "G2", "G2", "G2"), ("G2", "G2", "G2", "G2", "G2", "P1", "P1", "P1", "G2", "G2", "G2", "G2", "G2"), ("G2", "G2", "G2", "G2", "G2", "P1", "P1", "P1", "G2", "G2", "G2", "G2", "G2"), ("G2", "G2", "G2", "G2", "G2", "P1", "P1", "P1", "G2", "G2", "G2", "G2", "G2"), ("G2", "G2", "G2", "G2", "G2", "P1", "P1", "P1", "G2", "G2", "G2", "G2", "G2"), ) foreground = ( (" ", " ", " ", " ", "F1", " ", " ", " ", " ", " ", " ", " ", " "), (" ", "T2", " ", " ", "F1", " ", " ", " ", " ", " ", " ", " ", " "), (" ", " ", "T2", " ", "F1", " ", " ", " ", " ", " ", " ", " ", " "), (" ", " ", " ", " ", "F1", " ", " ", " ", " ", " ", " ", " ", " "), (" ", " ", "T2", " ", "F1", " ", " ", " ", " ", " ", " ", " ", " "), (" ", " ", " ", " ", "F1", " ", " ", " ", " ", " ", " ", " ", " "), (" ", " ", " ", " ", "F1", " ", " ", " ", " ", "L1", " ", " ", " "), (" ", " ", "T2", " ", "F1", " ", " ", " ", " ", " ", " ", " ", " "), ("T2", " ", " ", " ", "F1", " ", " ", " ", " ", " ", " ", " ", " "), (" ", " ", " ", " ", "F1", " ", " ", " ", " ", " ", " ", " ", " "), ) drawn = 0 is_shaking = 0 while not gameExit: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() #debug #print(event) if not drawn: loc_x = 0 loc_y = 0 for map_y in background: for map_x in map_y: if map_x == 'G1': gameDisplay.blit(ground1, (loc_x, loc_y)) if map_x == 'G2': gameDisplay.blit(ground2, (loc_x, loc_y)) if map_x == 'G3': gameDisplay.blit(ground3, (loc_x, loc_y)) if map_x == 'P1': gameDisplay.blit(path1, (loc_x, loc_y)) loc_x = loc_x + scalesize loc_y = loc_y + scalesize loc_x = 0 loc_x = 0 loc_y = 0 for map_y in foreground: for map_x in map_y: if map_x == 'T2': gameDisplay.blit(tree2, (loc_x, loc_y)) if map_x == 'F1': gameDisplay.blit(fence, (loc_x, loc_y)) if map_x == 'L1': gameDisplay.blit(log, (loc_x, loc_y)) loc_x = loc_x + scalesize loc_y = loc_y + scalesize loc_x = 0 drawn = 0 #force redraw, or not key_input = pygame.key.get_pressed() if not is_shaking: if key_input[pygame.K_LEFT]: morgan.move_left() if key_input[pygame.K_UP]: morgan.move_up() if key_input[pygame.K_RIGHT]: morgan.move_right() if key_input[pygame.K_DOWN]: morgan.move_down() gameDisplay.blit(morgan.get_image(), morgan.get_location()) pygame.display.update() clock.tick(60)
true_scroll = [0, 0] been_here = False current_level = 0 levels = [ 'output:\nhello world', 'passed level 1', 'passed level 2', 'coding\nin python\nis cool', 'passed level 4', 'passed level 5', 'unlocked' ] levels_text = [] load_levels_text(levels_text) player = Player([100, 100]) pirate = Character('characters/pirate') # background_animated = Character('characters/background_animated') # not in use yet, maybe for menu? sky = pygame.image.load('game_map/background/sky.png').convert() collectable = {} while True: player.update_animation() true_scroll[0] += (player.rect.x - true_scroll[0] - display.get_width() // 2 - player.image.get_width() // 2) / 20 true_scroll[1] += (player.rect.y - true_scroll[1] - display.get_height() // 2 - player.image.get_height() // 2) / 20 scroll = true_scroll.copy() scroll[0] = int(scroll[0]) scroll[1] = int(scroll[1])
def find_index_from_xy(x, y): row = y // gc.IMAGE_SIZE col = x // gc.IMAGE_SIZE index = row * gc.NUM_TILES_SIDE + col return row, col, index pygame.init() display.set_caption( 'Big Bang Theory -A Simple Memory Game Designed By Aashita') screen = display.set_mode((gc.SCREEN_SIZE, gc.SCREEN_SIZE)) matched = image.load('other_assets/matched.png') running = True tiles = [Character(i) for i in range(0, gc.NUM_TILES_TOTAL)] current_images_displayed = [] while running: current_events = event.get() for e in current_events: if e.type == pygame.QUIT: running = False if e.type == pygame.KEYDOWN: if e.key == pygame.K_ESCAPE: running = False if e.type == pygame.MOUSEBUTTONDOWN: mouse_x, mouse_y = pygame.mouse.get_pos()
def intro(): gameExit = False frame_counter = 0 phase = 0 summoning = 0 summoned = False chest = 'closed' show_key = False show_bear = False show_cake = False done_hoot = False did_fade = False cake_x = 290 cake_y = 5 key_pressed = False hoot_sound = pygame.mixer.Sound("sound/hoot.wav") ufo_sound = pygame.mixer.Sound("sound/ufo.wav") pop_sound = pygame.mixer.Sound("sound/pop.wav") open_sound = pygame.mixer.Sound("sound/unlock.wav") happy_birthday = pygame.mixer.Sound("sound/happybirthday.wav") pygame.mixer.init() pygame.mixer.music.load('sound/music.wav') pygame.mixer.music.set_volume(0.3) scan = pygame.image.load('pictures/scan.jpg') spritesheet = SpriteSheet('tiles/sheet.png') pumpkin = spritesheet.image_at((ts * 6, ts * 20, ts, ts), -1) seedling = spritesheet.image_at((ts * 7, ts * 19, ts, ts), -1) stone1 = spritesheet.image_at((ts * 1, ts * 57, ts, ts)) stone2 = spritesheet.image_at((ts * 2, ts * 57, ts, ts)) stone3 = spritesheet.image_at((0, ts * 57, ts, ts)) ground1 = spritesheet.image_at((0, 0, ts, ts)) ground2 = spritesheet.image_at((ts, 0, ts, ts)) ground3 = spritesheet.image_at((ts * 2, 0, ts, ts)) fence = spritesheet.image_at((0, ts * 22, ts, ts), -1) path1 = spritesheet.image_at((ts * 5, 0, ts, ts)) tree2 = spritesheet.image_at((ts * 2, ts, ts * 2, ts * 2), -1) log = spritesheet.image_at((ts * 6, ts * 5, ts * 2, ts), -1) skull = spritesheet.image_at((ts * 6, ts * 131, ts, ts), -1) fountain = spritesheet.image_at((0, ts * 116, ts * 3, ts * 3), -1) statue = spritesheet.image_at((ts * 4, ts * 113, ts, ts * 2), -1) statue2 = spritesheet.image_at((ts * 3, ts * 115, ts, ts * 2), -1) statue3 = spritesheet.image_at((ts * 4, ts * 115, ts, ts * 2), -1) grave = spritesheet.image_at((ts * 3, ts * 8, ts, ts), -1) key = spritesheet.image_at((ts * 7, ts * 131, ts, ts), -1) bear = spritesheet.image_at((ts * 3, ts * 128, ts, ts), -1) heart = pygame.image.load('tiles/heart.png') cake_hover = pygame.image.load('tiles/cake.png') cake_hover.set_colorkey(cake_hover.get_at((0, 0)), pygame.RLEACCEL) cake_hover = pygame.transform.scale(cake_hover, (scalesize * 4, scalesize * 4)) cat1 = Character('cat2', -100, 20) cat2 = Character('cat2', 900, 40) cat3 = Character('cat3', -100, 60) morgan = Character('morgan', -64, 50) zander = Character('zander', -64, 70) ghost = Character('ghost', -120, 70) ace = Character('alex', 575, 188) geoff = Character('geoff', 450, -80) martin = Character('martin', 800 + 64 + 20, 50) chest_closed = spritesheet.image_at((ts * 6, ts * 107, ts, ts), -1) chest_open = spritesheet.image_at((ts * 6, ts * 108, ts, ts), -1) # scale things.. chest_closed = pygame.transform.scale(chest_closed, (scalesize, scalesize)) chest_open = pygame.transform.scale(chest_open, (scalesize, scalesize)) pumpkin = pygame.transform.scale(pumpkin, (scalesize, scalesize)) seedling = pygame.transform.scale(seedling, (scalesize, scalesize)) ground1 = pygame.transform.scale(ground1, (scalesize, scalesize)) ground2 = pygame.transform.scale(ground2, (scalesize, scalesize)) ground3 = pygame.transform.scale(ground3, (scalesize, scalesize)) grave = pygame.transform.scale(grave, (scalesize, scalesize)) key = pygame.transform.scale(key, (scalesize, scalesize)) bear = pygame.transform.scale(bear, (scalesize * 2, scalesize * 2)) stone1 = pygame.transform.scale(stone1, (scalesize, scalesize)) stone2 = pygame.transform.scale(stone2, (scalesize, scalesize)) stone3 = pygame.transform.scale(stone3, (scalesize, scalesize)) path1 = pygame.transform.scale(path1, (scalesize, scalesize)) tree2 = pygame.transform.scale(tree2, (scalesize * 2, scalesize * 2)) fence = pygame.transform.scale(fence, (scalesize, scalesize)) log = pygame.transform.scale(log, (scalesize * 2, scalesize)) skull = pygame.transform.scale(skull, (scalesize, scalesize)) statue = pygame.transform.scale(statue, (scalesize, scalesize * 2)) fountain = pygame.transform.scale(fountain, (scalesize * 3, scalesize * 3)) statue2 = pygame.transform.scale(statue2, (scalesize, scalesize * 2)) statue3 = pygame.transform.scale(statue3, (scalesize, scalesize * 2)) background = ( ("S1", "S1", "S1", "S1", "S2", "P1", "P1", "P1", "S3", "S1", "S1", "S1", "S1"), ("G2", "G2", "G2", "G2", "G2", "P1", "P1", "P1", "G2", "G2", "G2", "G2", "G2"), ("G2", "G2", "G2", "G2", "G2", "P1", "P1", "P1", "G2", "G2", "G2", "G2", "G2"), ("G2", "G2", "G2", "G2", "G2", "P1", "P1", "P1", "G2", "G2", "G2", "G2", "G2"), ("G2", "G2", "G2", "G2", "G2", "P1", "P1", "P1", "G2", "G2", "G2", "G2", "G2"), ("G2", "G2", "G2", "G2", "P1", "P1", "P1", "P1", "P1", "G2", "G2", "G2", "G2"), ("G2", "G2", "G2", "G2", "P1", "P1", "P1", "P1", "P1", "G2", "G2", "G2", "G2"), ("G2", "G2", "G2", "G2", "P1", "P1", "P1", "P1", "P1", "G2", "G2", "G2", "G2"), ("G2", "G2", "G2", "P1", "P1", "P1", "P1", "P1", "P1", "P1", "G2", "G2", "G2"), ("G2", "G2", "G2", "P1", "P1", "P1", "P1", "P1", "P1", "P1", "G2", "G2", "G2"), ) foreground = ( (" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "), (" ", "PD", "PD", " ", " ", " ", " ", " ", " ", " ", "PD", " ", " "), ("F1", " ", "T2", " ", " ", " ", " ", " ", " ", "A1", " ", "A2", " "), ("F1", "GR", " ", "T2", " ", " ", " ", " ", " ", " ", "PD", "T2", " "), ("F1", "SK", " ", " ", " ", " ", " ", " ", " ", " ", "PU", " ", " "), ("F1", "T2", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "), ("F1", " ", "A3", " ", " ", " ", " ", " ", " ", " ", "L1", " ", " "), ("F1", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", "T2", " "), ("T2", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "), (" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "), ) drawn = 0 is_shaking = 0 while not gameExit: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() # For the sake of video capture, this will require # a hit of the space bar to start the whole thing.. key_input = pygame.key.get_pressed() if key_pressed != True: if key_input[pygame.K_SPACE]: key_pressed = True font_heading = 'EightBitDragon-anqx.ttf' font_heading = pygame.font.Font(font_heading, 30) gameDisplay.blit( font_heading.render('INSERT COIN', 1, (255, 255, 255)), (325, 280)) pygame.display.update() continue #debug #print(event) loc_x = 0 loc_y = 0 if did_fade == False: for map_y in background: for map_x in map_y: if map_x == 'S1': gameDisplay.blit(stone1, (loc_x, loc_y)) if map_x == 'S2': gameDisplay.blit(stone2, (loc_x, loc_y)) if map_x == 'S3': gameDisplay.blit(stone3, (loc_x, loc_y)) if map_x == 'G1': gameDisplay.blit(ground1, (loc_x, loc_y)) if map_x == 'G2': gameDisplay.blit(ground2, (loc_x, loc_y)) if map_x == 'G3': gameDisplay.blit(ground3, (loc_x, loc_y)) if map_x == 'P1': gameDisplay.blit(path1, (loc_x, loc_y)) loc_x = loc_x + scalesize loc_y = loc_y + scalesize loc_x = 0 loc_x = 0 loc_y = 0 if did_fade == False: for map_y in foreground: for map_x in map_y: if map_x == 'GR': gameDisplay.blit(grave, (loc_x, loc_y)) if map_x == 'SK': gameDisplay.blit(skull, (loc_x, loc_y)) if map_x == 'PD': gameDisplay.blit(seedling, (loc_x, loc_y)) if map_x == 'PU': gameDisplay.blit(pumpkin, (loc_x, loc_y)) if map_x == 'T2': gameDisplay.blit(tree2, (loc_x, loc_y)) if map_x == 'F1': gameDisplay.blit(fence, (loc_x, loc_y)) if map_x == 'L1': gameDisplay.blit(log, (loc_x, loc_y)) if map_x == 'A2': gameDisplay.blit(statue2, (loc_x, loc_y)) if map_x == 'A3': gameDisplay.blit(statue3, (loc_x, loc_y)) if map_x == 'A1': if not summoned: statue_x = loc_x statue_y = loc_y if summoning > 0: if summoning == 1: pygame.mixer.Sound.play(ufo_sound) summoning = summoning + 1 statue_x = statue_x + random.randint(-5, 5) statue_y = statue_y + random.randint(-5, 5) if summoning > 80: # ugh python - ?? dim = statue.get_size() lst = list(dim) lst[0] = lst[0] + 100 lst[1] = lst[1] + 100 dim = tuple(lst) statue_x = statue_x - 50 * (summoning - 80) statue_y = statue_y - 50 * (summoning - 80) statue = pygame.transform.scale( statue, dim) if summoning == 117: pygame.mixer.Sound.play(pop_sound) if summoning > 120: summoned = True gameDisplay.blit(statue, (statue_x, statue_y)) loc_x = loc_x + scalesize loc_y = loc_y + scalesize loc_x = 0 # Foreground tiles that don't fit into my tile engine if chest != 'hidden': if chest == 'open': gameDisplay.blit(chest_open, (390, 380)) else: gameDisplay.blit(chest_closed, (390, 380)) if show_key: gameDisplay.blit(key, (390, 350)) if show_bear: gameDisplay.blit(bear, (358, 353)) if show_cake: gameDisplay.blit(cake_hover, (cake_x, cake_y)) if did_fade != True: gameDisplay.blit(fountain, (327, 490)) gameDisplay.blit(morgan.get_image(), morgan.get_location()) gameDisplay.blit(martin.get_image(), martin.get_location()) gameDisplay.blit(zander.get_image(), zander.get_location()) gameDisplay.blit(ghost.get_image(), ghost.get_location()) gameDisplay.blit(geoff.get_image(), geoff.get_location()) if summoned: gameDisplay.blit(ace.get_image(), ace.get_location()) gameDisplay.blit(cat1.get_image(), cat1.get_location()) gameDisplay.blit(cat2.get_image(), cat2.get_location()) gameDisplay.blit(cat3.get_image(), cat3.get_location()) # This is the non-interactive .. thing. Each phase is an 'act' of the animation. # I'm sure there are better ways of doing this.. this is what I came up with, # while drinking a cup of tea. # Morgan walks in to the right if phase == 0: if done_hoot != True: pygame.mixer.Sound.play(hoot_sound) done_hoot = True t1 = cat1.move_right(900) t2 = cat2.move_left(-100) t3 = cat3.move_right(900) font = 'EightBitDragon-anqx.ttf' font = pygame.font.Font(font, 30) gameDisplay.blit(font.render('England', 1, (255, 255, 255)), (350, 140)) gameDisplay.blit(font.render('2020', 1, (255, 255, 255)), (378, 185)) if t1 and t2 and t3: frame_counter = frame_counter + 1 if frame_counter > 50: frame_counter = 0 phase = 1 pygame.mixer.music.play(1) if phase == 1: if morgan.move_right(360): phase = 2 # Martin walks in from the left if phase == 2: if martin.move_left(420): phase = 3 # A heart appears above us for a few frames if phase == 3: frame_counter = frame_counter + 1 if frame_counter < 50: gameDisplay.blit(heart, (406, 30)) else: frame_counter = 0 phase = 4 # We walk down together if phase == 4: t1 = morgan.move_down(300) t2 = martin.move_down(300) if t1 and t2: phase = 5 # A speech bubble of some sort if phase == 5: dialogue(morgan, 'Hello everybody!') phase = 6 if phase == 6: dialogue(martin, 'We have brought you here today for some news...') phase = 7 if phase == 7: dialogue(martin, 'But first...') phase = 8 if phase == 8: dialogue(morgan, 'ZANDER!!!') phase = 9 if phase == 9: t1 = zander.move_right(900) t2 = ghost.move_right(890) if t1 and t2: phase = 10 if phase == 10: dialogue(martin, 'ZANDER!!!!!!') phase = 11 if phase == 11: if zander.move_left(340): phase = 12 if phase == 12: if zander.move_down(220): phase = 13 # Add some frames between z arriving and speaking. if phase == 13: frame_counter = frame_counter + 1 if frame_counter > 10: frame_counter = 0 phase = 14 if phase == 14: dialogue(zander, '???') phase = 15 if phase == 15: dialogue(martin, 'GEOFFFFFF!!!!!!') phase = 16 if phase == 16: if geoff.move_down(220): phase = 17 if phase == 17: frame_counter = frame_counter + 1 if frame_counter > 10: frame_counter = 0 phase = 18 if phase == 18: dialogue(geoff, 'Want to see my new Beano?') phase = 19 if phase == 19: dialogue(martin, 'We\'re missing one...') phase = 20 if phase == 20: dialogue(morgan, '>> SUMMON ALEX <<') phase = 21 if phase == 21: if summoning == 0: summoning = 1 if summoned: phase = 22 if phase == 22: frame_counter = frame_counter + 1 if frame_counter > 10: frame_counter = 0 phase = 23 if phase == 23: dialogue(ace, 'HERE!') phase = 24 if phase == 24: t1 = ace.move_up(120) t2 = ace.move_left(390) if t1 and t2: phase = 25 if phase == 25: if ace.move_down(215): phase = 26 if phase == 26: dialogue(martin, 'Now that everybody is here, we just want to say..') phase = 27 if phase == 27: show_cake = True frame_counter = frame_counter + 1 if frame_counter > 50: pygame.mixer.Sound.play(happy_birthday) frame_counter = 0 cake = pygame.image.load('tiles/cake.png') cake.set_colorkey(cake.get_at((0, 0)), pygame.RLEACCEL) cake = pygame.transform.scale(cake, (scalesize * 2, scalesize * 2)) dialogue_all('everybody', cake, 'HAPPY BIRTHDAY GRANDPA!') phase = 28 if phase == 28: dialogue(morgan, 'We hope you have an amazing day!') phase = 29 if phase == 29: frame_counter = frame_counter + 1 if frame_counter > 100: frame_counter = 0 phase = 30 if phase == 30: show_cake = False dialogue(zander, 'Wait, what\'s in the chest?') phase = 31 if phase == 31: dialogue(ace, 'Yeh, I was in the middle of a game!') phase = 32 if phase == 32: dialogue(morgan, 'Well let\'s open it and find out!') show_key = True phase = 33 if phase == 33: frame_counter = frame_counter + 1 if frame_counter == 90: pygame.mixer.Sound.play(open_sound) if frame_counter > 100: frame_counter = 0 phase = 34 if phase == 34: show_key = False chest = 'open' frame_counter = frame_counter + 1 if frame_counter > 100: frame_counter = 0 phase = 35 pygame.mixer.init() pygame.mixer.music.load('sound/lullaby.wav') pygame.mixer.music.set_volume(1) pygame.mixer.music.play(1) if phase == 35: chest = 'hidden' show_bear = True frame_counter = frame_counter + 1 if frame_counter == 1: pygame.mixer.music.play(1) if frame_counter > 100: frame_counter = 0 phase = 36 if phase == 36: dialogue(martin, 'That\'s interesting...') phase = 37 if phase == 37: dialogue(morgan, 'That means...') phase = 38 if phase == 38: dialogue(geoff, 'What does it mean?') phase = 39 if phase == 39: dialogue(zander, 'Oh no...') phase = 40 if phase == 40: dialogue(ace, 'Not again...') phase = 41 if phase == 41: dialogue(morgan, 'Yes, again.') phase = 42 if phase == 42: dialogue(morgan, 'Arriving April 2021! A new player!') phase = 43 if phase == 43: dialogue(geoff, 'I\'m not sharing my Lego.') phase = 44 if phase == 44: dialogue(morgan, 'Hush all of you!') phase = 45 if phase == 45: dialogue(morgan, 'Thank you for listening to our news!') phase = 46 if phase == 46: dialogue(martin, 'We hope you are excited as we are!') phase = 47 if phase == 47: frame_counter = frame_counter + 1 if frame_counter > 100: frame_counter = 0 phase = 48 if phase == 48: did_fade = True fadeout() phase = 49 if phase == 49: pygame.draw.rect(gameDisplay, (0, 0, 0), (30, 30, 740, 540)) font_heading = 'EightBitDragon-anqx.ttf' font_heading = pygame.font.Font(font_heading, 20) font_body = 'EightBitDragon-anqx.ttf' font_body = pygame.font.Font(font_body, 15) gameDisplay.blit( font_heading.render('Sound Credits', 1, (255, 255, 255)), (320, 60)) gameDisplay.blit( font_body.render( 'https://freesound.org/people/BeezleFM (unlock)', 1, (193, 193, 193)), (140, 100)) gameDisplay.blit( font_body.render( 'https://freesound.org/people/erkanozan/ (ufo)', 1, (193, 193, 193)), (140, 120)) gameDisplay.blit( font_body.render( 'https://freesound.org/people/Breviceps/ (owl)', 1, (193, 193, 193)), (140, 140)) gameDisplay.blit(font_heading.render('Music', 1, (255, 255, 255)), (370, 180)) gameDisplay.blit( font_body.render('David Vitas @davidvitas (Lullaby Music)', 1, (193, 193, 193)), (230, 240)) gameDisplay.blit( font_body.render('sawsquarenoise (Towel Defence Ending)', 1, (193, 193, 193)), (230, 220)) gameDisplay.blit(scan, (150, 280)) frame_counter = frame_counter + 1 if frame_counter > 300: frame_counter = 0 fadeout() phase = 50 if phase == 50: pygame.draw.rect(gameDisplay, (0, 0, 0), (30, 30, 740, 540)) font_heading = 'EightBitDragon-anqx.ttf' font_heading = pygame.font.Font(font_heading, 20) font_body = 'EightBitDragon-anqx.ttf' font_body = pygame.font.Font(font_body, 15) gameDisplay.blit( font_heading.render('Graphics', 1, (255, 255, 255)), (355, 60)) gameDisplay.blit( font_body.render( 'https://pipoya.itch.io/pipoya-rpg-tileset-32x32 (tiles)', 1, (193, 193, 193)), (140, 100)) gameDisplay.blit( font_body.render( 'https://pipoya.itch.io/pipoya-free-rpg-character-sprites-32x32', 1, (193, 193, 193)), (90, 120)) gameDisplay.blit( font_body.render('(character sprites)', 1, (193, 193, 193)), (320, 140)) gameDisplay.blit( font_heading.render('Thanks to all content creators!', 1, (255, 255, 255)), (220, 180)) gameDisplay.blit( font_body.render('starfighter.dev', 1, (193, 193, 193)), (330, 250)) gameDisplay.blit(scan, (150, 280)) frame_counter = frame_counter + 1 if frame_counter > 300: fadeout() frame_counter = 0 phase = 51 if phase == 51: pygame.draw.rect(gameDisplay, (0, 0, 0), (30, 30, 740, 540)) pygame.mixer.music.fadeout(5000) #cat1 = Character('cat1', -100, 20) #cat2 = Character('cat2', 900, 40) #cat3 = Character('cat3', -100, 60) pygame.display.update() clock.tick(60)
open('armors/armor_types/list_of_types.json', "r", encoding="utf-8")).items() ] armor_mods = [ ModificationOfArmor(k, v) for k, v in json.load( open('armors/armor_mods/list_of_modification.json')).items() ] weapon_mods = [ ModificationOfWeapon(k, v) for k, v in json.load( open('weapons/weapon_mods/list_of_modification.json')).items() ] weapon_types = [ TypeOfWeapon(k, *v) for k, v in json.load( open('weapons/weapons_types/list_of_types.json', "r", encoding="utf-8")).items() ] enemies = [ Character(choice(enemy_names)), Character(choice(enemy_names)) ] load = input('Do you want to load a saved player? (y/n): ') if load == 'y': # HM select file in folder 'save' and choose the player json path_to_characters = Path(SAVE_FOLDER) list_of_file = [child for child in path_to_characters.iterdir()] create_choice_list([child.name for child in list_of_file]) index = int(input("Choose your save: ")) character = create_player( json.load(open(list_of_file[index])), armor_types, weapon_types, armor_mods, weapon_mods,
class BlackJack: """ BlackJack game """ def __init__(self) -> None: self.player = Character() self.dealer = Dealer() self.menu = ActionMenu(self.dealer) self.minimum = 10 self.maximum = int(self.minimum * 1.5) self.bet = 0 def __call__(self) -> None: self.execute() def execute(self) -> None: """ Starts the game """ while self.player.money > self.minimum: try: self._make_bet() self._first_deal() self._construct_screen() if self._natural_21(): continue choice = self.menu.handle_options() self._perform_move(choice) self._show_cards(show_hidden=True) self._determine_winner() self._update_min_max() self._clear_hands() except KeyboardInterrupt: clear() print("\nThanks for playing!\n") sleep() clear() sys.exit(0) self._game_over() def _game_over(self) -> None: """ Game over messages """ msg = "You do not have enough money for the minimum bet of ${}" print(msg.format(self.minimum)) print("\nGAME OVER") def _clear_hands(self) -> None: """ Reset the player and dealers hands """ self.dealer.hand = [] self.player.hand = [] def _perform_move(self, choice: str) -> None: """ Translate the string choice into an action """ if choice == "Stand": self.dealer.deal(self.dealer) elif choice == "Hit": self.dealer.deal(self.player) def _update_min_max(self) -> None: """ Updates in and max attributes by 50%, to a max threshold of 500 """ if self.maximum < 500: self.minimum *= 2 self.maximum *= 2 else: self.minimum = 350 self.maximum = 500 def _first_deal(self) -> None: """ Deals 2 cards to the dealer and player """ print("\nDealer dealing cards....") sleep() self.dealer.deal(self.dealer) self.dealer.deal(self.dealer) self.dealer.deal(self.player) self.dealer.deal(self.player) def _natural_21(self) -> bool: """ Determines if player has 21 and hands over winnings if True """ if self.player.card_count == 21: winnings = self.bet + (self.bet * 2.5) msg = "Natural 21! You earn ${}" print(msg.format(winnings)) sleep() self.player.money += winnings self._update_min_max() self._clear_hands() return True return False def _make_bet(self) -> None: """ Prompts player to make a bet """ clear() print("Player: ${}\n".format(self.player.money)) msg = "Make your bet (min: ${}, max: ${})." print(msg.format(self.minimum, self.maximum)) entered_bet = input(">> ") if not entered_bet.isdigit(): print("Please enter a number.") sleep() flush_input() return self._make_bet() bet = int(entered_bet) if self.minimum > bet or self.maximum < bet: print("${} is outside the min and max bets".format(bet)) sleep() self._make_bet() self.bet = bet self.player.money -= bet flush_input() def _construct_screen(self) -> None: """ Constructs players stats and dealers and players hands """ clear() print("Player Wallet: ${}".format(self.player.money)) print("Bet: ${}\n".format(self.bet)) self._show_cards() flush_input() def _show_cards(self, show_hidden: bool = False) -> None: """ Prints the players and dealers cards in hand. Args: show_hidden (bool): show dealers face down card if True. """ print("Player: {}".format(self.player.str_hand())) print("Dealer: {}\n".format(self.dealer.str_hand(show_hidden))) def _determine_winner(self) -> None: """ Determines whether player or dealer has cards closer to 21 """ player_hand = self.player.card_count dealer_hand = self.dealer.card_count if player_hand == dealer_hand: self._draws() elif player_hand == 21 or dealer_hand > 21: self._win() elif dealer_hand == 21 or player_hand > 21: self._lose() elif player_hand > dealer_hand: self._win() elif dealer_hand > player_hand: self._lose() else: raise ValueError("Unknown winner.") def _draws(self) -> None: """ Give back the bet to the player """ print("\nDraw!") sleep() self.player.money += self.bet self.bet = 0 def _win(self) -> None: """ Give player double his bettings in money """ winnings = self.bet * 2 print("\nPlayer Wins!") sleep() print("Player recieves ${}\n".format(self.bet)) sleep() self.player.money += winnings self.bet = 0 def _lose(self) -> None: """ Dealer takes betting money """ print("\nPlayer Loses!\n") sleep() self.dealer.money += self.bet self.bet = 0
class Game: def __init__(self): self.player = Character() self.monsters = [Goblin(), Troll(), Dragon()] self.monster = self.get_next_monster() # game loop while self.player.hit_points and (self.monster or self.monsters): print('\n' + '=' * 20) print(self.player) self.monster_turn() print('-' * 20) self.player_turn() self.cleanup() print('\n' + '=' * 20) if self.player.hit_points: print("You win!") elif self.monster or self.monsters: print("You lose!") sys.exit() def get_next_monster(self): try: return self.monsters.pop(0) except IndexError: return None def monster_turn(self): if self.monster.attack(): print("{} is attacking!".format(self.monster)) if self.player.dodge(): print("You dodged the attack!") else: print("You got hit anyway!") self.player.hit_points -= 1 else: print("{} isn't attacking this turn".format(self.monster)) def player_turn(self): action = input("Action ([A]ttack, [R]est, [Q]uit): ").lower() if action == 'a': print("You're attacking {}!".format(self.monster)) if self.player.attack(): if self.monster.dodge(): print("{} dodged your attack!".format(self.monster)) else: if self.player.leveled_up(): self.monster.hit_points -= 2 else: self.monster.hit_points -= 1 print("You hit {} with your {}!".format(self.monster, self.player.weapon)) else: print("You missed!") elif action == 'r': self.player.rest() elif action == 'q': print("Quited") sys.exit() else: self.player_turn() def cleanup(self): if self.monster.hit_points <= 0: self.player.experience += self.monster.experience print("You killed {}!".format(self.monster)) self.monster = self.get_next_monster()