def main(): #召喚 m1 = monster.Monster(4, 1) m2 = monster.Monster(4, 5) m3 = monster.Monster(7, 5) mons = [m1, m2, m3] f1 = fish.Fish(9, 2) #魚召喚 p1 = player.Player() map1 = field.map() # map召喚 #ゲーム全体のモードのコントロール mode = 0 opening.main() while True: if mode == 0: #野 mode, id = field.main(p1, mons, f1, map1) #フィールドでの流れ elif mode == 3: #街ナカ mode = town.main(p1) #街ナカ elif mode == 10: #バトル m1 = mons[id] print("モンスター出現!! hp", m1.hp, " 攻撃力", m1.at, " 防御力", m1.df) flag = battle.battle(p1, m1) #戦闘シーン if flag == 1: #モンスターをやっつけた mons.pop(id) mode = 0 #野 elif flag == 2: #プレイヤが死んだらゲームオーバー print("game over") return elif flag == 3: #プレイヤが逃げ出した mode = 0 #野
def __init__(self, difficulty, level, player): self.maze = [[1 for i in range(0, 7)] for j in range(0, 7)] self.difficulty = difficulty self.level = level for row in self.maze: row[0] = 0 row[len(row) - 1] = 0 for i in range(0, len(self.maze[1])): self.maze[0][i] = 0 self.maze[len(self.maze) - 1][i] = 0 self.maze[0][3] = 1 #self.maze[6][3]=1 self.startrow = 0 self.startcol = 3 self.endrow = 6 self.endcol = 3 self.player = player self.playerposrow = self.startrow self.playerposcol = self.startcol if self.difficulty == 'easy': #level + 12 self.bossmonster = monster.Monster(self.level + 15) self.bossposrow = 3 self.bossposcol = 3 elif self.difficulty == 'hard': #level + 17 self.bossmonster = monster.Monster(self.level + 20) self.bossposrow = 3 self.bossposcol = 3
def __init__(self): self.caves = self.create_caves() cave1 = self.caves[0] sword = item.Item("sword", "A pointy sword.", cave1) coin = item.Item("coin", "A shiny gold coin. " "Your first piece of treasure!", cave1) orc = monster.Monster(cave1, 'orc', 'A generic dungeon monster') self.player = player.Player(cave1)
def game_start(): """Initial player creation""" # Gets player name and creates default player player_name = input("What is your name? ") player = m.Monster(player_name, 200, 200, 3, 10, 1.4, 0, 0) return player
def action(self): self.counter += 1 if self.ic == len(self.instructions): return False, None monster_type, delay = self.instructions[self.ic] if self.counter >= delay: self.counter = 0 self.ic += 1 return True, monster.Monster(monster_type, self.path) return True, None
def get_play(): name = input("Как твоё имя?") straight = int(input("Выбери силу")) pl = player.Player(name=name, straight=straight) mn = monster.Monster(name=name, mtype=0, straight=straight) fig = fight.Fight(pl, mn) fig.tick() print(pl.hp)
def breakWall(self, direction): if direction == 'up': if self.playerposcol == 0 or self.playerposrow == 1: return self.maze[self.playerposrow - 1][self.playerposcol] = 1 if self.difficulty == 'hard': self.map[self.playerposrow - 1][self.playerposcol] = 1 self.playerposrow -= 1 elif direction == 'down': if self.playerposcol == 0 or self.playerposrow == ( (len(self.maze)) - 2): return self.maze[self.playerposrow + 1][self.playerposcol] = 1 if self.difficulty == 'hard': self.map[self.playerposrow + 1][self.playerposcol] = 1 self.playerposrow += 1 elif direction == 'right': if self.playerposcol == ((len(self.maze[1])) - 2) or self.playerposrow == 0: return self.maze[self.playerposrow][self.playerposcol + 1] = 1 if self.difficulty == 'hard': self.map[self.playerposrow][self.playerposcol + 1] = 1 self.playerposcol += 1 elif direction == 'left': if self.playerposcol == 1 or self.playerposrow == 0: return self.maze[self.playerposrow][self.playerposcol - 1] = 1 if self.difficulty == 'hard': self.map[self.playerposrow][self.playerposcol - 1] = 1 self.playerposcol -= 1 input('Monster encountered') clearScreen() self.monstertimer = 0 if self.difficulty == 'easy': monster1 = monster.Monster((random.randint(6, 8)) + self.level) elif self.difficulty == 'hard': monster1 = monster.Monster((random.randint(10, 12)) + self.level) self.battle(monster1)
def __init__(self): self.snake = snake.Snake() self.monster = monster.Monster(ri(-24,24) * 10,ri(-24,24) * 10) self.interface = Screen() self.interface.setup(500, 500) self.interface.tracer(0) self.interface.onkey(self.up, "Up") self.interface.onkey(self.down, "Down") self.interface.onkey(self.left, "Left") self.interface.onkey(self.right, "Right") self.interface.listen()
def create_dungeon_floor_monster_list(monsters, entity): my_list = [] temp_list = monsters.split(" ") monster_list = [] for m in temp_list: monster_list.append(m.split(",")) for i in range(len(monster_list)): with open("data/monsters.csv") as csv_file: csv_reader = csv.reader(csv_file, delimiter=",") for row in csv_reader: if row[0][0] == monster_list[i][0]: my_list.append(monster.Monster(*row)) my_list[-1].set_x(monster_list[i][1]) my_list[-1].set_y(monster_list[i][2]) entity.add( my_list[-1].return_x(), my_list[-1].return_y(), my_list[-1].return_mchar(), my_list[-1], ) return my_list
import pygame import monster import spell import trap m1 = monster.Monster(name='Matazza The Zapper', atkdef=(1300, 1000), nivel=3) m2 = monster.Monster(name='Alexandrite Dragon', atkdef=(1900, 1500), nivel=4) print('{0} Vs {1}'.format(m1.name, m2.name)) print(m1.attack(m2)) s = spell.Spell(name='Mystic Typhoon') print(s.name) t = trap.Trap(name='Mirror Force') print(t.name)
def add_new_monster(self): self.monsters.insert(0, monster.Monster())
str(self._pc.get_max_health())) print('Mana: ' + str(self._pc.get_cur_mana()) + '/' + str(self._pc.get_mana())) for m in self._monsters: print(m.get_name() + ': ' + str(m.get_cur_health()) + '/' + str(m.get_max_health())) # using magic elif i == '2': print( 'this does not do anything yet, check back when it is updated' ) # using an item elif i == '3': print( 'this does not do anything yet, check back when it is updated' ) print('you have defeated the forces of evil, exiting the game now') return True if __name__ == '__main__': wep = weapon.Weapon('Sword', 5, 10, 10, 5) pc = player.Player('Test', 50, 2, 2, 50, 3, 100) pc.set_weapon(wep) mon1 = monster.Monster('Slime01', 20, 3, 5, 2, 10) mon2 = monster.Monster('Slime02', 10, 5, 8, 1, 5) mon3 = monster.Monster('Slime03', 20, 3, 5, 3, 3) mon_list = [mon1, mon2, mon3] battle = Battle(pc, mon_list, 500) battle.battle_loop()
def __init__(self, should_spawn=True): super(Room, self).__init__("room", 20, 40, True) if should_spawn: roll = randint(1, 100) if roll < self.chance_monster: self.monster = monster.Monster()
def scrape_monster(monster_link): page_link = 'http://www.orcpub.com' + monster_link page_response = requests.get(page_link, timeout=5) soup = BeautifulSoup(page_response.content, "html.parser") monster_name = soup.find_all('span',itemprop = 'name')[-1].get_text() monster = mn.Monster(monster_name) monster_info = soup.find_all(class_ = 'char-details-section') monster.size = monster_info[0].find_all('em')[0].get_text() monster.type = monster_info[0].find_all('em')[1].get_text() monster.align = monster_info[0].find_all('em', class_='m-l-5')[1].get_text() monster.armor_class = soup.find(string='Armor Class').find_parent(class_='char-details-field').find(class_='m-l-5').get_text() monster.hp = soup.find(string='Hit Points').find_parent(class_='char-details-field').find(class_='m-l-5').get_text().split('(')[0] monster.hit_die = '(' + soup.find(string='Hit Points').find_parent(class_='char-details-field').find(class_='m-l-5').get_text().split('(')[1] monster.speed = soup.find(string='Speed').find_parent(class_='char-details-field').find(class_='m-l-5').get_text() #str = soup.find_all('span') monster.str = soup.find(string='str').find_parent(class_='ability-label').find('div').get_text() monster.dex = soup.find(string='dex').find_parent(class_='ability-label').find('div').get_text() monster.con = soup.find(string='con').find_parent(class_='ability-label').find('div').get_text() monster.int = soup.find(string='int').find_parent(class_='ability-label').find('div').get_text() monster.wis = soup.find(string='wis').find_parent(class_='ability-label').find('div').get_text() monster.cha = soup.find(string='cha').find_parent(class_='ability-label').find('div').get_text() monster.proficiency = soup.find(string='Proficiency Bonus').find_parent(class_='char-details-field').find(class_='m-l-5').get_text() #saving throws are redundant try: monster.skills = soup.find(string='Skills').find_parent(class_='char-details-field').find(class_='m-l-5').get_text() except: monster.skills = '' try: monster.resistances = soup.find(string='Damage Resistances').find_parent(class_='char-details-field').find(class_='m-l-5').get_text() except: monster.resistances = '' try: monster.immunities = soup.find(string='Damage Immunities').find_parent(class_='char-details-field').find(class_='m-l-5').get_text() except: monster.immunities = '' try: monster.cond_immunities = soup.find(string='Condition Immunities').find_parent(class_='char-details-field').find(class_='m-l-5').get_text() except: monster.cond_immunities = '' try: monster.senses = soup.find(string='Senses').find_parent(class_='char-details-field').find(class_='m-l-5').get_text() except: monster.senses = '' try: monster.languages = soup.find(string='Languages').find_parent(class_='char-details-field').find(class_='m-l-5').get_text() except: monster.languages = '' monster.challenge = soup.find(string='Challenge').find_parent(class_='char-details-field').find(class_='m-l-5').get_text() monster.extras = '' monster.actions = '' monster.leg_actions = '' try: extra_html = soup.find_all(class_='col-xs-12 col-md-6')[0].find_all('strong') for i in extra_html: monster.extras += i.get_text() action_html = soup.find(string='Actions').find_parent('div').find_all('strong') except: monster.extras = '' try: action_html = soup.find(string='Actions').find_parent('div').find_all('strong') for i in action_html: monster.actions += i.get_text() except: monster.actions = '' try: leg_action_html = soup.find(string='Legendary Actions').find_parent('div').find_all('strong') for i in leg_action_html: monster.leg_actions += i.get_text() except: monster.leg_actions = '' return monster
def main(): pygame.init() # メイン画面の初期化,rectでサイズを指定 screen = pygame.display.set_mode(SCREEN_RECT.size) # メイン画面のタイトル pygame.display.set_caption("exit: press esc") clock = pygame.time.Clock() title = tl.Title(screen) item = it.Item() menu_display = False #主人公の画像読み込み player = pl.Player("assets/pipo-charachip029c.png", title, item) group = pygame.sprite.RenderUpdates() group.add(player) field_map = mp.Map(screen, "assets/maps/field-map.txt", player) player.mapSet(field_map) town_map = mp.Map(screen, "assets/maps/town-map.txt", player) town = tw.Town(player, field_map, 5) cave_map = mp.Map(screen, "assets/maps/cave-map.txt", player) cave = tw.Town(player, field_map, 4) monster = ms.Monster() battle = bt.Battle(player, monster) menu = mn.Menu(screen, player) shop = sp.Shop(menu, player, screen, item) inn = nn.Inn(menu, player, screen, item) global_count = 0 def dataSave(): player.saved_player_data += (str(player.hp) + "," + str(player.mp) + "," + str(player.exp) + "," + str(player.gold) + "," + str(player.wx) + "," + str(player.wy) + ",") if field_map.map_display: player.saved_player_data += "0" elif town.map_display: player.saved_player_data += "1" elif cave.map_display: player.saved_player_data += "2" for i in range(len(player.item_list)): player.saved_player_data += ("," + str(player.item_list[i][0])) if len(player.item_list) < 5: for i in range(5 - len(player.item_list)): player.saved_player_data += "," + str(0) with open("assets/saved-player-data.txt", mode="w") as fi: fi.write(player.saved_player_data) if player.where == 0: field_map.map_display = True town.map_display = False cave.map_display = False elif player.where == 1: field_map.map_display = False town.map_display = True cave.map_display = False if player.where == 2: field_map.map_display = False town.map_display = False cave.map_display = True while (True): menu_display = menu.menu_display pygame.event.clear() global_count += 1 if title.title_display: title.update() title.drawTri(240, 317 + 50 * title.title_select_num, global_count) elif shop.shop_display: shop.shopAnim() elif inn.inn_display: inn.innAnim() else: if not town.map_display: battle.update() if (not battle.battle_now): if (field_map.map_display): player.mapSet(field_map) field_map.draw(0) if player.wx <= 15 and player.wy <= 11: monster.decideMonster( "assets/monster-list/field-monsters.txt") elif player.wx <= 15 and player.wy > 11: monster.decideMonster( "assets/monster-list/field-monsters2.txt") elif player.wx > 15 and player.wy <= 11: monster.decideMonster( "assets/monster-list/field-monsters3.txt") elif player.wx > 15 and player.wy > 11: monster.decideMonster( "assets/monster-list/field-monsters4.txt") town.visited(8, 5) cave.visited(18, 28) elif (town.map_display): player.mapSet(town_map) town_map.draw(1) shop.update(3, 2) inn.update(6, 2) town.exit(6) elif (cave.map_display): player.mapSet(cave_map) monster.decideMonster( "assets/monster-list/cave-monsters.txt") cave_map.draw(8) cave.exit(29) group.update(menu_display) group.draw(screen) else: battle.battleAnim(screen) if menu.menu_display and not title.title_display: menu.update() # menu.drawTri(60,39+menu.menu_select_num*40,global_count) # フレームレートの設定 clock.tick(60) #イベント #keyはまとめてここに書かないと思った挙動にならない、正直めんどくさすぎる for event in pygame.event.get(): # 終了イベント if event.type == QUIT: dataSave() pygame.quit() sys.exit() if event.type == pygame.KEYDOWN: if event.key == K_ESCAPE: dataSave() pygame.quit() sys.exit() if not battle.battle_now: if not menu.menu_display: if event.key == pygame.K_RETURN: menu.menu_display = True else: if event.key == pygame.K_RETURN: menu.menu_display = False menu.show_statas = False menu.show_items = False menu.show_magics = False menu.item_select_tri = False menu.use_item_anim = False shop.KeyEvent(event) # if shop.shop_display: # player.moving_wait = False # if event.key==pygame.K_DOWN: # if(shop.shop_select_num == 2): # shop.shop_select_num = 0 # else: # shop.shop_select_num += 1 # if event.key==pygame.K_UP: # if(shop.shop_select_num == 0): # shop.shop_select_num = 2 # else: # shop.shop_select_num -= 1 # if event.key==pygame.K_RIGHT : # if len(player.item_list) < 5: # if shop.shop_select_num == 0 and player.gold >= int(item.all_item_list[0][3]): # player.item_list.append(item.all_item_list[0]) # player.gold -= int(item.all_item_list[0][3]) # elif shop.shop_select_num == 1 and player.gold >= int(item.all_item_list[1][3]): # player.item_list.append(item.all_item_list[1]) # player.gold -= int(item.all_item_list[1][3]) # if shop.shop_select_num == 2: # shop.shop_display = False # player.wy += 1 if inn.inn_display: player.moving_wait = False if event.key == pygame.K_DOWN: if (inn.inn_select_num == 1): inn.inn_select_num = 0 else: inn.inn_select_num += 1 if event.key == pygame.K_UP: if (inn.inn_select_num == 0): inn.inn_select_num = 1 else: inn.inn_select_num -= 1 if event.key == pygame.K_RIGHT: if inn.inn_select_num == 0 and player.gold >= 10: player.gold -= 10 player.hp, player.mp = player.max_hp, player.max_mp elif inn.inn_select_num == 1: inn.inn_display = False player.wy += 1 if menu.menu_display: if event.key == pygame.K_DOWN: if (menu.menu_select_num == 2): menu.menu_select_num = 0 else: menu.menu_select_num += 1 if event.key == pygame.K_UP: if (menu.menu_select_num == 0): menu.menu_select_num = 2 else: menu.menu_select_num -= 1 if event.key == pygame.K_LEFT: menu.show_statas = False menu.show_items = False menu.show_magics = False menu.item_select_tri = False menu.magic_select_tri = False if event.key == pygame.K_RIGHT and not menu.item_select_tri and not menu.magic_select_tri: if menu.menu_select_num == 0: menu.show_statas = True elif menu.menu_select_num == 1: menu.show_items = True menu.item_select_tri = True wait_count_item_show = global_count elif menu.menu_select_num == 2: menu.show_magics = True menu.magic_select_tri = True wait_count_magic_show = global_count if menu.item_select_tri == True and wait_count_item_show + 3 < global_count: if event.key == pygame.K_DOWN: if (menu.item_select_num == len(player.item_list) - 1): menu.item_select_num = 0 else: menu.item_select_num += 1 if event.key == pygame.K_UP: if (menu.item_select_num == 0): menu.item_select_num = len(player.item_list) - 1 else: menu.item_select_num -= 1 if event.key == pygame.K_RIGHT: menu.show_items = False menu.item_select_tri = False menu.use_item_anim = True wait_count_item_anim = global_count menu.use_item = player.item_list.pop( menu.item_select_num) player.hp += int(menu.use_item[2]) if player.hp > player.max_hp: player.hp = player.max_hp if menu.use_item_anim == True and wait_count_item_anim + 3 < global_count: menu.use_item_anim = False if menu.magic_select_tri == True and wait_count_magic_show + 3 < global_count: if event.key == pygame.K_DOWN: if menu.magic_arrow_num == menu.magic_arrow_max_num: menu.magic_arrow_num = 0 else: menu.magic_arrow_num += 1 if event.key == pygame.K_UP: if (menu.magic_arrow_num == 0): menu.magic_arrow_num = menu.magic_arrow_max_num else: menu.magic_arrow_num -= 1 if event.key == pygame.K_RIGHT and player.mp > player.selected_magic_mp and player.selected_magic_heal == 1: menu.show_magics = False menu.magic_select_tri = False menu.use_magic_anim = True player.mp -= player.selected_magic_mp player.hp += player.selected_magic_damage if player.hp > player.max_hp: player.hp = player.max_hp wait_count_magic_anim = global_count if menu.use_magic_anim == True and wait_count_magic_anim + 3 < global_count: menu.use_magic_anim = False if title.title_display: if event.key == pygame.K_DOWN: if (title.title_select_num == 1): title.title_select_num = 0 else: title.title_select_num += 1 if event.key == pygame.K_UP: if (title.title_select_num == 0): title.title_select_num = 1 else: title.title_select_num -= 1 if event.key == pygame.K_RIGHT: title.title_display = False player.moving_wait = False player.parameterSet() if player.where == 0: field_map.map_display = True town.map_display = False cave.map_display = False elif player.where == 1: field_map.map_display = False town.map_display = True cave.map_display = False elif player.where == 2: field_map.map_display = False town.map_display = False cave.map_display = True player.itemSet(item) for i in range(len(player.magic_list_num)): player.magic_list.append( player.all_magic_list[player.magic_list_num[i] - 1]) if battle.command_select_tri: if event.key == pygame.K_DOWN: if (battle.command_arrow_num == battle.command_arrow_max_num): battle.command_arrow_num = 0 else: battle.command_arrow_num += 1 if event.key == pygame.K_UP: if (battle.command_arrow_num == 0): battle.command_arrow_num = battle.command_arrow_max_num else: battle.command_arrow_num -= 1 if event.key == pygame.K_RIGHT: battle.command_select_tri = False if (battle.command_arrow_num == 0): battle.monster_selecting = True wait_count_select_monster = battle.battle_anim_count elif (battle.command_arrow_num == 1): battle.magic_selecting = True battle.magic_attack = True wait_count_select_magic = battle.battle_anim_count elif (battle.command_arrow_num == 2): battle.guard_anim = True battle.command_selecting = False wait_count_guard_anim = battle.battle_anim_count elif battle.command_arrow_num == 3: wait_count_escape_anim = battle.battle_anim_count battle.command_selecting = False battle.random_walk = 5 + battle.battle_anim_count % 10 if (global_count % 100 + player.lv * 3) >= 100: battle.escape_success = 1 else: battle.escape_success = 2 elif battle.command_arrow_num == 4: battle.item_select_tri = True battle.item_selecting = True wait_count_item_show_battle = battle.battle_anim_count if battle.item_select_tri: if wait_count_item_show_battle + 3 < battle.battle_anim_count: if event.key == pygame.K_DOWN: if (battle.item_select_num == len(player.item_list) - 1): battle.item_select_num = 0 else: battle.item_select_num += 1 if event.key == pygame.K_UP: if (battle.item_select_num == 0): battle.item_select_num = len( player.item_list) - 1 else: battle.item_select_num -= 1 if event.key == pygame.K_RIGHT: battle.item_selecting = False battle.item_select_tri = False battle.command_selecting = False battle.use_item_anim = True wait_count_item_anim = global_count battle.use_item = player.item_list.pop( battle.item_select_num) player.hp += int(battle.use_item[2]) if player.hp > player.max_hp: player.hp = player.max_hp if battle.use_item_anim == True and wait_count_item_anim + 3 < global_count: battle.use_item_anim = False battle.attack_monster_anim = True wait_count_restart = battle.battle_anim_count if battle.magic_selecting: if event.key == pygame.K_DOWN and ( wait_count_select_magic + 3) < battle.battle_anim_count: if (battle.magic_arrow_num == battle.magic_arrow_max_num): battle.magic_arrow_num = 0 else: battle.magic_arrow_num += 1 if event.key == pygame.K_UP and ( wait_count_select_magic + 3) < battle.battle_anim_count: if (battle.magic_arrow_num == 0): battle.magic_arrow_num = battle.magic_arrow_max_num else: battle.magic_arrow_num -= 1 if event.key == pygame.K_RIGHT and ( wait_count_select_magic + 3 ) < battle.battle_anim_count and player.mp > player.selected_magic_mp: battle.monster_selecting = True battle.magic_selecting = False wait_count_select_monster = battle.battle_anim_count player.selected_magic = battle.magic_arrow_num if event.key == pygame.K_LEFT and ( wait_count_select_magic + 3) < battle.battle_anim_count: battle.magic_selecting = False battle.magic_attack = False battle.command_select_tri = True if (battle.monster_selecting): if not battle.magic_attack: if event.key == pygame.K_RIGHT and ( wait_count_select_monster + 3) < battle.battle_anim_count: battle.monster_selecting = False battle.command_selecting = False battle.attack_player_anim = True wait_count_attack_monster = battle.battle_anim_count if (monster.defence >= player.attack): battle.damage = 1 else: battle.damage = player.attack - monster.defence if event.key == pygame.K_LEFT and ( wait_count_select_monster + 3) < battle.battle_anim_count: battle.monster_selecting = False battle.command_select_tri = True else: if event.key == pygame.K_RIGHT and ( wait_count_select_monster + 3) < battle.battle_anim_count: battle.monster_selecting = False battle.command_selecting = False battle.magic_player_anim = True wait_count_attack_monster = battle.battle_anim_count if event.key == pygame.K_LEFT and ( wait_count_select_monster + 3) < battle.battle_anim_count: battle.monster_selecting = False battle.magic_selecting = True wait_count_select_magic = battle.battle_anim_count if (battle.escape_success == 2): if event.key == pygame.K_RIGHT and ( wait_count_escape_anim + 3) < battle.battle_anim_count: battle.attack_monster_anim = True battle.escape_success = 0 wait_count_restart = battle.battle_anim_count if (player.defence >= monster.attack): battle.damage = 1 else: battle.damage = monster.attack - player.defence if (battle.escape_success == 1): if event.key == pygame.K_RIGHT and ( wait_count_escape_anim + 3) < battle.battle_anim_count: battle.escape_success = 0 battle.battle_now = False battle.battle_anim_count = 0 player.move_count = 0 battle.random_walk = 5 + battle.battle_anim_count % 10 monster.random_monster_num = global_count % 100 if (battle.attack_player_anim): if event.key == pygame.K_RIGHT and ( wait_count_attack_monster + 3) < battle.battle_anim_count: battle.attack_player_anim = False wait_count_restart = battle.battle_anim_count monster.hp -= battle.damage battle.random_walk = 5 + battle.battle_anim_count % 6 monster.random_monster_num = global_count % 100 if (monster.hp <= 0): battle.you_defeate = True else: battle.attack_monster_anim = True if (player.defence >= monster.attack): battle.damage = 1 else: battle.damage = monster.attack - player.defence if (battle.magic_player_anim): battle.magic_select_tri = False battle.magic_attack = False if event.key == pygame.K_RIGHT and ( wait_count_attack_monster + 3) < battle.battle_anim_count: battle.magic_player_anim = False wait_count_restart = battle.battle_anim_count if player.selected_magic_heal == 1: player.hp += player.selected_magic_damage if player.hp > player.max_hp: player.hp = player.max_hp else: monster.hp -= player.selected_magic_damage player.mp -= player.selected_magic_mp battle.random_walk = 5 + battle.battle_anim_count % 6 monster.random_monster_num = global_count % 100 if (monster.hp <= 0): battle.you_defeate = True else: battle.attack_monster_anim = True if (player.defence >= monster.attack): battle.damage = 1 else: battle.damage = monster.attack - player.defence if (battle.guard_anim): if event.key == pygame.K_RIGHT and ( wait_count_guard_anim + 3) < battle.battle_anim_count: battle.guard_anim = False battle.attack_monster_anim = True wait_count_restart = battle.battle_anim_count if (player.defence * 2 >= monster.attack): battle.damage = 1 else: battle.damage = monster.attack - player.defence * 2 if (battle.attack_monster_anim): if event.key == pygame.K_RIGHT and ( wait_count_restart + 3) < battle.battle_anim_count: if player.hp > battle.damage: player.hp -= battle.damage battle.battle_anim_count = 79 battle.attack_monster_anim = False else: battle.random_walk = 5 + battle.battle_anim_count % 10 monster.random_monster_num = global_count % 100 battle.attack_monster_anim = False battle.you_lose = True wait_count_you_lose = battle.battle_anim_count if (battle.you_defeate and (wait_count_restart + 3) < battle.battle_anim_count): player.exp += monster.exp player.gold += monster.gold if player.lv == len(player.lv_tables): battle.you_defeate = False battle.battle_now = False player.moving_wait = False battle.battle_anim_count = 0 player.move_count = 0 elif player.lv_tables[player.lv][5] <= player.exp: battle.you_defeate = False battle.lv_up_anim = True player.parameterSet() wait_count_lv_anim = battle.battle_anim_count else: battle.you_defeate = False battle.battle_now = False player.moving_wait = False battle.battle_anim_count = 0 player.move_count = 0 if (battle.lv_up_anim and (wait_count_lv_anim + 3) < battle.battle_anim_count): battle.lv_up_anim = False battle.lv_up_anim_2 = True wait_count_lv_anim_2 = battle.battle_anim_count if battle.lv_up_anim_2 and (wait_count_lv_anim_2 + 3) < battle.battle_anim_count: battle.lv_up_anim_2 = False battle.battle_now = False player.moving_wait = False battle.battle_anim_count = 0 player.move_count = 0 if (battle.you_lose and (wait_count_you_lose + 3) < battle.battle_anim_count): battle.you_lose = False battle.battle_now = False field_map.map_display = True town.map_display = False cave.map_display = False player.hp = player.max_hp player.mp = player.max_mp player.gold = player.gold // 2 battle.battle_anim_count = 0 player.move_count = 0 player.wx, player.wy = 4, 3 if event.type == pygame.KEYUP: if not player.moving_wait: if event.key == pygame.K_DOWN or event.key == pygame.K_UP or event.key == pygame.K_RIGHT or event.key == pygame.K_LEFT: player.moving_wait = True # print(player.lv_tables[player.lv][5]) # メイン画面の更新 pygame.display.update()
triangle=monster[3][1], cresentmoon=monster[3][2], hexagon=monster[3][3], square=monster[3][4], diamond=monster[3][5], star=monster[3][6], slash=monster[3][7], plus=monster[3][8]) m.append( mon.Monster(movement=monster[2], toughness=monster[5], dimension=dimensiondict, expansion=monster[1], horrorrating=monster[7], horrordamage=monster[8], combatrating=monster[9], combatdamage=monster[10], abilities=monster[11], awareness=monster[6], name=monster[0], flavortext="", text="")) rnd.shuffle(m) Agame.monstercup = m # for gate in Agame.gates: # print gate # print gate.location # for loc in Agame.locations:
def battle(hero): lvl = hero.level mob = monster.Monster(type, lvl) mob.appear() while mob.alive: #prints HP Bar hpbar = "[" n = int((hero.hp / hero.maxHP) * 10) for i in range(1, 10): if i <= n: hpbar += "||" else: hpbar += ' ' hpbar += "]" #print Battle options action = input( "------------------------------ \n" + hpbar + "\n HP:" + str(hero.hp) + "/" + str(hero.maxHP) + "\n [Attack] [Inventory] \n [" + hero.heroSkill + "] [Run] \n------------------------------ \n > ").lower().strip() #attack option if action == "attack": os.system('clear') modify = random.randint(hero.level - 2, hero.level + 7) damage = hero.atk + modify print("You hit monster for " + str(damage) + " Damage.") mob.hp -= damage #Check to see if monster is dead if mob.hp <= 0: mob.alive = False print("Final fantasy fanfare song") levelUp(hero, mob.xpValue) break #monster attack if mob.alive: mobdify = random.randint(-10, 10) mobattack = mob.atk + mobdify print("Monster hits you for " + str(mobattack) + " Damage.") hero.hp -= mobattack if hero.hp <= 0: hero.alive = False print("you dead") break #Run command handling if action == "run": coward = random.randint(0, 100) if coward >= 50: print("you run like a coward and escape") mob.alive = False else: print( "You couldnt get away, not only are you a coward but you are slow." ) print("Monster hits you for " + str(mob.atk) + " Damage.") hero.hp -= mob.atk if hero.hp <= 0: hero.alive = False print("you dead") break #skill handler if action == hero.heroSkill: os.system('clear') if hero.hp > 25: modify = random.randint(hero.level - 2, hero.level + 7) damage = hero.atk * 2 + modify * 2 hero.hp -= 25 print("You use your " + hero.heroSkill + " monster for " + str(damage) + " Damage. \n Costing you 25hp.") mob.hp -= damage #Check to see if monster is dead if mob.hp <= 0: mob.alive = False print("Final fantasy fanfare song") levelUp(hero, mob.xpValue) break #monster attack if mob.alive and modify < hero.level + 5: mobdify = random.randint(-10, 10) mobattack = mob.atk + mobdify print("Monster hits you for " + str(mobattack) + " Damage.") hero.hp -= mobattack if hero.hp <= 0: hero.alive = False print("you dead") break if modify > hero.level + 5: print("You crit the monster stunning him.") else: print("not enough HP to use this skill.") #inventory handler if action == "inventory": inventory.prints(hero) item = input("use item or [cancel]") if item == "cancel": os.system('clear') else: inventory.use(hero, item)
# # 1. 默认路径,以Python.3.7为例 大致有: # ../Python37/python37.zip # ../Python37/DLLs # ../Python37/lib # ../Python37/ # ../Python37/lib/site-packages # 2. 当前程序路径 # 3. 环境变量 %PYTHONPATH% 中定义的路径 # 因此,对应的为了避免在程序中直接修改 sys.path 可以有三种方式 # 1. 将模块放入默认路径 # 2. 将模块放入当前程序路径 # 3. 将模块放入 环境变量 %PYTHONPATH% 中定义的路径 或 在 环境变量 %PYTHONPATH% 中加入模块路径 # # 一般来说常用方式是,先在环境变量 %PYTHONPATH% 中加入指定的便于管理的路径,然后将模块都放入这些路径里。 # # 对于之前的例子,可以先修改环境变量 # C:\Users\rays1>echo %PYTHONPATH% # D:\environment\python\modules # # 然后将模块放入 D:\environment\python\modules # # 然后程序中就可以直接 import 模块 # # 注意修改了环境变量后,要重新开启一个命令行或者重启IDE否则不会加载新的环境变量 import hero import monster h = hero.Hero() m = monster.Monster()
def createMonsters(case): monsters = [monster.Monster((8,13), [(8, 13), (8, 12), (8, 11), (7,11), (6, 11), (6, 12), (6, 13), (7,13)])] print case if case == 1: monsters += [monster.Monster((3,1),[(3,1),(3,2),(2,2),(2,1)])] monsters += [monster.Monster((7,1),[(7,1),(7,2),(6,2),(6,1)])] monsters += [monster.Monster((7,5),[(7,5),(7,4)])] elif case == 2: monsters += [monster.Monster((2,10),[(2,10),(2,11),(2,12),(3,12),(3,11),(3,10)])] monsters += [monster.Monster((4,8),[(4,8),(5,8),(6,8),(7,8),(8,8),(7,8),(6,8),(5,8)])] route = [] for i in range(1,14): route += [(4,i)] for i in [4,3,2,1]: route += [(i,13)] for i in range(13,0,-1): route += [(1,i)] routeCopy = route + [] for i in reversed(routeCopy[:-1]): route+= [i] monsters += [monster.Monster((4,1),route)] elif case == 3: monsters += [monster.Monster((1,3),[(1,3),(2,3)])] monsters += [monster.Monster((3,1),[(3,1),(3,2),(3,3),(3,2)])] monsters += [monster.Monster((2,8),[(2,8),(2,9),(2,10),(2,11),(2,10),(2,9)])] monsters += [monster.Monster((4,12),[(4,12),(4,12),(4,13),(4,13)])] monsters += [monster.Monster((6,8),[(6,8),(6,9)])] monsters += [monster.Monster((2,1),[(3,1),(4,1),(5,1),(6,1),(7,1),(8,1),(8,1),\ (7,1),(6,1),(5,1),(4,1),(3,1),(2,1),(1,1)])] return monsters
def __init__(self, file_path): self.starting_blocks = [] self.starting_enemies = [] self.starting_coins = [] self.starting_powerups = [] self.starting_flag = [] self.starting_fires = [] self.blocks = pygame.sprite.Group() self.enemies = pygame.sprite.Group() self.coins = pygame.sprite.Group() self.powerups = pygame.sprite.Group() self.flag = pygame.sprite.Group() self.fires = pygame.sprite.Group() self.active_sprites = pygame.sprite.Group() self.inactive_sprites = pygame.sprite.Group() with open(file_path, 'r') as f: data = f.read() map_data = json.loads(data) self.width = map_data['width'] * game.GRID_SIZE self.height = map_data['height'] * game.GRID_SIZE self.start_x = map_data['start'][0] * game.GRID_SIZE self.start_y = map_data['start'][1] * game.GRID_SIZE for item in map_data['blocks']: x, y = item[0] * game.GRID_SIZE, item[1] * game.GRID_SIZE img = game.block_images[item[2]] self.starting_blocks.append(block.Block(x, y, img)) for item in map_data['fires']: x, y = item[0] * game.GRID_SIZE, item[1] * game.GRID_SIZE self.starting_fires.append(fire.Fire(x, y, game.fire_img)) for item in map_data['bears']: x, y = item[0] * game.GRID_SIZE, item[1] * game.GRID_SIZE self.starting_enemies.append(bear.Bear(x, y, game.bear_images)) for item in map_data['monsters']: x, y = item[0] * game.GRID_SIZE, item[1] * game.GRID_SIZE self.starting_enemies.append( monster.Monster(x, y, game.monster_images)) for item in map_data['coins']: x, y = item[0] * game.GRID_SIZE, item[1] * game.GRID_SIZE self.starting_coins.append(coin.Coin(x, y, game.coin_img)) for item in map_data['oneups']: x, y = item[0] * game.GRID_SIZE, item[1] * game.GRID_SIZE self.starting_powerups.append(oneUp.OneUp(x, y, game.oneup_img)) for item in map_data['hearts']: x, y = item[0] * game.GRID_SIZE, item[1] * game.GRID_SIZE self.starting_powerups.append(heart.Heart(x, y, game.heart_img)) for i, item in enumerate(map_data['flag']): x, y = item[0] * game.GRID_SIZE, item[1] * game.GRID_SIZE if i == 0: img = game.flag_img else: img = game.flagpole_img self.starting_flag.append(flag.Flag(x, y, img)) self.background_layer = pygame.Surface([self.width, self.height], pygame.SRCALPHA, 32) self.scenery_layer = pygame.Surface([self.width, self.height], pygame.SRCALPHA, 32) self.inactive_layer = pygame.Surface([self.width, self.height], pygame.SRCALPHA, 32) self.active_layer = pygame.Surface([self.width, self.height], pygame.SRCALPHA, 32) if map_data['background-color'] != "": self.background_layer.fill(map_data['background-color']) if map_data['background-img'] != "": background_img = pygame.image.load( map_data['background-img']).convert_alpha() if map_data['background-fill-y']: h = background_img.get_height() w = int(background_img.get_width() * game.HEIGHT / h) background_img = pygame.transform.scale( background_img, (w, game.HEIGHT)) if "top" in map_data['background-position']: start_y = 0 elif "bottom" in map_data['background-position']: start_y = self.height - background_img.get_height() if map_data['background-repeat-x']: for x in range(0, self.width, background_img.get_width()): self.background_layer.blit(background_img, [x, start_y]) else: self.background_layer.blit(background_img, [0, start_y]) if map_data['scenery-img'] != "": scenery_img = pygame.image.load( map_data['scenery-img']).convert_alpha() if map_data['scenery-fill-y']: h = scenery_img.get_height() w = int(scenery_img.get_width() * game.HEIGHT / h) scenery_img = pygame.transform.scale(scenery_img, (w, game.HEIGHT)) if "top" in map_data['scenery-position']: start_y = 0 elif "bottom" in map_data['scenery-position']: start_y = self.height - scenery_img.get_height() if map_data['scenery-repeat-x']: for x in range(0, self.width, scenery_img.get_width()): self.scenery_layer.blit(scenery_img, [x, start_y]) else: self.scenery_layer.blit(scenery_img, [0, start_y]) pygame.mixer.music.load(map_data['music']) self.gravity = map_data['gravity'] self.terminal_velocity = map_data['terminal-velocity'] self.completed = False self.blocks.add(self.starting_blocks) self.enemies.add(self.starting_enemies) self.coins.add(self.starting_coins) self.powerups.add(self.starting_powerups) self.flag.add(self.starting_flag) self.fires.add(self.starting_fires) self.active_sprites.add(self.coins, self.enemies, self.powerups, self.fires) self.inactive_sprites.add(self.blocks, self.flag) # with this speed up blitting on slower computers? for s in self.active_sprites: s.image.convert() for s in self.inactive_sprites: s.image.convert() self.inactive_sprites.draw(self.inactive_layer) # is converting layers helpful at all? self.background_layer.convert() self.scenery_layer.convert() self.inactive_layer.convert() self.active_layer.convert()
def get_play(): name = input("ваше имя") straight = int(input("введите силу")) pl = player.Player(name, straight, hp) mn = monster.Monster(name, type, strenght, hp)
def movePlayer(self, direction): self.monstertimer += 1 if direction == 'up': if self.maze[self.playerposrow - 1][self.playerposcol] is 1: self.playerposrow -= 1 else: self.breakWall(direction) elif direction == 'down': if self.maze[self.playerposrow + 1][self.playerposcol] is 1: self.playerposrow += 1 else: self.breakWall(direction) elif direction == 'right': if self.maze[self.playerposrow][self.playerposcol + 1] is 1: self.playerposcol += 1 else: self.breakWall(direction) elif direction == 'left': if self.maze[self.playerposrow][self.playerposcol - 1] is 1: self.playerposcol -= 1 else: self.breakWall(direction) if self.difficulty == 'hard' and self.playerposrow != self.endrow and self.playerposcol != self.endcol: self.map[self.playerposrow][self.playerposcol] = self.maze[ self.playerposrow][self.playerposcol] self.map[self.playerposrow + 1][self.playerposcol] = self.maze[self.playerposrow + 1][self.playerposcol] self.map[self.playerposrow - 1][self.playerposcol] = self.maze[self.playerposrow - 1][self.playerposcol] self.map[self.playerposrow][self.playerposcol + 1] = self.maze[ self.playerposrow][self.playerposcol + 1] self.map[self.playerposrow][self.playerposcol - 1] = self.maze[ self.playerposrow][self.playerposcol - 1] self.map[self.playerposrow + 1][self.playerposcol + 1] = self.maze[self.playerposrow + 1][self.playerposcol + 1] self.map[self.playerposrow + 1][self.playerposcol - 1] = self.maze[self.playerposrow + 1][self.playerposcol - 1] self.map[self.playerposrow - 1][self.playerposcol + 1] = self.maze[self.playerposrow - 1][self.playerposcol + 1] self.map[self.playerposrow - 1][self.playerposcol - 1] = self.maze[self.playerposrow - 1][self.playerposcol - 1] if self.monstertimer > 3: if random.randint(1, 10) >= 7: self.monstertimer = 0 input('Monster Encountered') clearScreen() if self.difficulty == 'easy': monster1 = monster.Monster((random.randint(1, 6)) + self.level) elif self.difficulty == 'hard': monster1 = monster.Monster((random.randint(6, 10)) + self.level) self.battle(monster1) if self.player.getCurrentHp() is not 0: self.player.healHp(5) self.player.regenMp(1)
def setup(self): self.all_monsters.append(monster.Monster('George', 'player', level=14)) self.monsters_in_party = self.all_monsters
def setup_monsters(self): # Give us some dummy monsters for now so we can beat the shit out of them self.monster_x = self.monsters_in_player_party[0] self.monster_y = monster.Monster('Bob', 'npc', level=4) self.monsters = [self.monster_x, self.monster_y]