def _check_mouseclick(self, mous_pos): if self.choiceButtons.choice1.rect.collidepoint( mous_pos ) and self.game_active and self.playerConsole.clicked == False and self.battle_active == False: battle(self, "Village") #self.playerConsole.showNextText(self, "None", "", pygame.image.load("CREATE Task Folder\Image Assets\Enemy_images\Goblin Miner.png").convert_alpha()) if self.choiceButtons.choice6.rect.collidepoint( mous_pos ) and self.game_active and self.playerConsole.clicked == False and self.battle_active == False: self.playerConsole.showNextText( self, "Hi", "There", pygame.image.load( "CREATE Task Folder\Image Assets\Enemy_images\Goblin Miner.png" ).convert_alpha()) if self.mainMenu.loadButton.rect.collidepoint( mous_pos) and not self.game_active: self.loadData() if self.mainMenu.newGameButton.rect.collidepoint( mous_pos) and not self.game_active: self.game_active = True self.playerConsole.resetConsole() #self.place.starterVillage(self) if self.mainMenu.quitButton.rect.collidepoint( mous_pos) and not self.game_active: sys.exit() if self.game_active: if self.battle_active == True: self.combatGUI.mouseEvents(mous_pos) self.swapButton.mouseEvents(mous_pos) #self.playerConsole.mouseEvents(mous_pos, self) self.Inventory.mouseEvents(self, mous_pos)
def attackr(inp): """Checks if player can attack a bot, and attacks it if they can""" global PLAYER, BOTS, CURRENT_MAP m = ai.getPoss(PLAYER.pos) try: for i in BOTS.value(): if BOTS[i].level == CURRENT_MAP.value().id: if tuple(BOTS[i].pos) in m: combat.battle(PLAYER, BOTS[i], CURRENT_MAP.value(), False, {'printInv':utils.printInv, 'delBot':delBot, 'cls':_cls}) except: pass
def main(): clear_screen() player = None try: with open('saves/_continue.txt') as f: continue_name = f.read() except: continue_name = 'None' choice = show_options(['Continue - {}'.format(continue_name), 'Load', 'Create', 'Exit']) if choice == 0: player = load(continue_name) elif choice == 1: player = load_file() elif choice == 2: print('hello') player = create_account() save(player) elif choice == 3: quit_game() print(player.name, '-', player.level) for k, v in player.stats.items(): print(k, '-', player.stats[k]) while True: clear_screen() choice_num = show_options(['Walk Around', 'Fight', 'Sleep', 'Save'], 'What would you like to do? (Turn {})\n'.format(player.turns)) if choice_num == 0: player.turns += 1 elif choice_num == 1: player.turns += 1 enemy = Player('Enemy') if battle(player, enemy) is True: cur_lvl = player.level exp_gain = int(random() * 8) + 1 player.exp += exp_gain print('You won!', player.name, 'gains', exp_gain, 'exp.') if player.level > cur_lvl: print(player.name, 'is now level', player.level) else: player = load_file() elif choice_num == 2: player.turns += 1 player.full_restore() show_options(['Continue'], 'You feel well rested.\n') elif choice_num == 3: save(player) show_options(['Continue'], 'Your game was saved.\n')
def _tickBefore(): """_tick manager for Before events""" global EVENTS, BOTS, CURRENT_MAP, PLAYER, MAP_ID, GAME GAME.currentmap = CURRENT_MAP.value().id if random.randint(1,300) == 150: amount = random.randint(10,30) raw_input("You found $%s!" % (amount)) PLAYER.moneyAdd(amount) def resPos(): print "Player position is BAD. (Hackz?)" x = raw_input() if x == "skip": return None else: PLAYER.pos = [2,2] if PLAYER.health[0] < 1: print "You died! DEBUG: ", PLAYER.health raw_input("[Exit]") sys.exit() if hax(PLAYER.pos) is True: resPos() #Fire events/objects if tuple(PLAYER.pos) in CURRENT_MAP.value().obj: CURRENT_MAP.value().obj[tuple(PLAYER.pos)]['exec'](CURRENT_MAP.value().obj[tuple(PLAYER.pos)]['obj']) if tuple(PLAYER.pos) in EVENTS.value().keys(): EVENTS.e[tuple(PLAYER.pos)].fire() for i in BOTS.value(): if BOTS[i].level == CURRENT_MAP.value().id and BOTS[i].pr == True and BOTS[i].alive is True: BOTS[i].move() for i in BOTS.value(): if BOTS[i].level == CURRENT_MAP.value().id: if tuple(BOTS[i].pos) in ai.getPoss(PLAYER.pos) or BOTS[i].pos == PLAYER.pos: if BOTS[i].atk is True and BOTS[i].alive is True: combat.battle(PLAYER, BOTS[i], CURRENT_MAP.value(), True, {'printInv':utils.printInv, 'delBot':delBot, 'cls':_cls}) break #@DEV If more then one bot attacks, should we let it happen? Or ignore one like we are doing now?
def mainmenu(): print "MAIN MENU:\n" choice = raw_input( "What do you wish to do:\n1. new game\n2. load game\n3. save current game\n4. exit\n" ) if choice == '1': config.clear() newgame() elif choice == '2': config.clear() memorycard.loadgame() elif choice == '3': config.clear() memorycard.savefile() elif choice == '4': config.clear() exit() elif choice == '5': print "Which function do you want to jump to:" call = raw_input("\n1. quests\n2. combat\n3. storyline\n") if call == '1': config.clear() quests.main() elif call == '2': config.clear() combat.battle(c) elif call == '3': config.clear() storyline.story() else: config.clear() mainmenu() else: print "Error with your choice. Exiting." time.sleep(5) exit()
def fight(current_board, eng_type, scot_type): """ does all the fights in contested regions computer_role is scottish or english """ contested_regions = list() for region in current_board.regions: if region.is_contested(): contested_regions.append(region) first_played = current_board.who_goes_first if first_played == 'ENGLAND': order_decider_type = eng_type elif first_played == 'SCOTLAND': order_decider_type = scot_type if order_decider_type == 'comp': while len(contested_regions) > 0: try: region_index_to_fight = random.randint( 0, len(contested_regions) - 1) ''' if current_board.who_goes_first == 'SCOTLAND': region_index_to_fight = random.randint(0, len(contested_regions) - 1) else: print('contested regions:') for i, region in enumerate(contested_regions): print(region.name + '[' + str(i) + ']', end = '\t') bad_input = True while bad_input: try: region_index_to_fight = int(input('Which region do you want to fight now (type index)')) except ValueError: print('type a number') continue if region_index_to_fight not in range(len(contested_regions)): print('type a valid index') else: bad_input = False ''' except AttributeError: raise Exception( 'error in cardplay not assigning who_goes_first to board') for block in contested_regions[ region_index_to_fight].blocks_present: if block.allegiance == 'ENGLAND': contested_regions[region_index_to_fight].combat_dict[ 'Defending'].append(block) else: contested_regions[region_index_to_fight].combat_dict[ 'Attacking'].append(block) attack = contested_regions[region_index_to_fight].combat_dict[ 'Attacking'] defense = contested_regions[region_index_to_fight].combat_dict[ 'Defending'] if type(attack) != list or type(defense) != list: raise Exception('attack and defense are not lists') combat.battle(attack, defense, list(), list(), current_board, eng_type, scot_type) contested_regions = list() for region in current_board.regions: if region.is_contested(): contested_regions.append(region) else: #Human picks which regions to contest first while len(contested_regions) > 0: try: if current_board.who_goes_first == 'SCOTLAND': print('contested regions:') for i, region in enumerate(contested_regions): print(region.name + '[' + str(i) + ']', end='\t') bad_input = True while bad_input: try: region_index_to_fight = int( input( 'Which region do you want to fight now (type index)' )) except ValueError: print('type a number') continue if region_index_to_fight not in range( len(contested_regions)): print('type a valid index') else: bad_input = False else: region_index_to_fight = random.randint( 0, len(contested_regions) - 1) except AttributeError: raise Exception( 'error in cardplay not assigning who_goes_first to board') for block in contested_region[ region_index_to_fight].blocks_present: if block.allegiance == 'ENGLAND': contested_regions[region_index_to_fight].combat_dict[ 'Defending'].append(block) else: conteseted_regions[region_index_to_fight].combat_dict[ 'Attacking'].append(block) attack = contested_regions[region_index_to_fight].combat_dict[ 'Attacking'] defense = contested_regions[region_index_to_fight].combat_dict[ 'Defending'] if type(attack) != list or type(defense) != list: raise Exception('attack and defense are not lists') combat.battle(attack, defense, list(), list(), current_board, eng_type, scot_type) contested_regions = list() for region in current_board.regions: if region.is_contested(): contested_regions.append(region)
def storyline(name, stats): # Loop to keep the game running when the player is alive print( name, ', you are a human. You have been captured by an elven/dwarven faction and sent to prison, ', sep='', end='') print('sentenced to death by combat.') input( 'The guards bring you to an arena, forced to fight another human. Press enter to continue.' ) print() health = combat.battle_tutorial(stats) if health == 'game_over': gameover() print('You have won your first battle. You will fight again tomorrow.') print('You will now be brought back to your cell.') input('Press enter to continue.') print() print('*** Sleeping ***') input('Press enter to continue.') print() print('A spirit has come to your cell and gives you a sword and shield!') print('But you must immediately fight a dwarf...') input('Press enter to continue.') health = combat.battle('dwarf', stats, health) if health == 'game_over': gameover() print('You defeated the dwarf, but the battle is far from over...') print('You must now find/fight your way out of the prison.') # Goes to prison hallway sequence print( 'From your cell there are two hallways you can choose from: Hallway 1 or Hallway 2. One of these has an enemy' ' while the other provides safe passage to the next part of the prison.' ) hallway = choice('1', '2') # First hallway choice is 1. if hallway == '1': print( 'You chose correctly. From here there are two hallways you can choose from: Hallway 3 or Hallway 4. One ' 'of these has an enemy while the other provides safe passage to the next part of the prison.' ) hallway = choice('3', '4') if hallway == '3': print( 'You chose correctly. You can see light near the end of both of the next hallways. From here there ' 'are two hallways you can choose from: Hallway 7 or Hallway 8. One of these has an enemy while the ' 'other allows you to escape the prison without facing an enemy.' ) hallway = choice('7', '8') if hallway == '7': print( 'Congratulations on escaping the prison! But you still have one enemy left: the final boss!' ) health = combat.battle('boss', stats, health) if health == 'game_over': gameover() else: print( 'Congratulations, you have reached the end of Prison Escape!' ) print('Thank you! We hope you\'ll play again!') input('Press enter to end the game.') if hallway == '8': rand = encounter() if rand <= 50: print('You have encountered a dwarf.') health = combat.battle('dwarf', stats, health) if health == 'game_over': gameover() elif rand > 50: print('You have encountered an elf.') health = combat.battle('elf', stats, health) if health == 'game_over': gameover() print( 'Congratulations on escaping the prison! But you still have one enemy left: the final boss!' ) health = combat.battle('boss', stats, health) if health == 'game_over': gameover() else: print( 'Congratulations, you have reached the end of Prison Escape!' ) print('Thank you! We hope you\'ll play again!') input('Press enter to end the game.') if hallway == '4': rand = encounter() if rand <= 50: print('You have encountered a dwarf.') health = combat.battle('dwarf', stats, health) if health == 'game_over': gameover() elif rand > 50: print('You have encountered an elf.') health = combat.battle('elf', stats, health) if health == 'game_over': gameover() print( 'You can see light near the end of both of the next hallways. From here there are two hallways you ' 'can choose from: Hallway 9 or Hallway 10. One of these has an enemy while the other provides safe ' 'passage to the next part of the prison.') hallway = choice('9', '10') if hallway == '9': print( 'Congratulations on escaping the prison! But you still have one enemy left: the final boss!' ) health = combat.battle('boss', stats, health) if health == 'game_over': gameover() else: print( 'Congratulations, you have reached the end of Prison Escape!' ) print('Thank you! We hope you\'ll play again!') input('Press enter to end the game.') if hallway == '10': rand = encounter() if rand <= 50: print('You have encountered a dwarf.') health = combat.battle('dwarf', stats, health) if health == 'game_over': gameover() elif rand > 50: print('You have encountered an elf.') health = combat.battle('elf', stats, health) if health == 'game_over': gameover() print( 'Congratulations on escaping the prison! But you still have one enemy left: the final boss!' ) health = combat.battle('boss', stats, health) if health == 'game_over': gameover() else: print( 'Congratulations, you have reached the end of Prison Escape!' ) print('Thank you! We hope you\'ll play again!') input('Press enter to end the game.') # First hallway choice is 2. if hallway == '2': rand = encounter() if rand <= 50: print('You have encountered a dwarf.') health = combat.battle('dwarf', stats, health) if health == 'game_over': gameover() elif rand > 50: print('You have encountered an elf.') health = combat.battle('elf', stats, health) if health == 'game_over': gameover() print( 'From here there are two hallways you can choose from: Hallway 5 or Hallway 6. One of these has an enemy ' 'while the other provides safe passage to the next part of the prison.' ) hallway = choice('5', '6') if hallway == '5': print( 'You chose correctly. You can see light near the end of both of the next hallways. From here there ' 'are two hallways you can choose from: Hallway 11 or Hallway 12. One of these has an enemy while the ' 'other allows you to escape the prison without facing an enemy.' ) hallway = choice('11', '12') if hallway == '11': print( 'Congratulations on escaping the prison! But you still have one enemy left: the final boss!' ) health = combat.battle('boss', stats, health) if health == 'game_over': gameover() else: print( 'Congratulations, you have reached the end of Prison Escape!' ) print('Thank you! We hope you\'ll play again!') input('Press enter to end the game.') if hallway == '12': rand = encounter() if rand <= 50: print('You have encountered a dwarf.') health = combat.battle('dwarf', stats, health) if health == 'game_over': gameover() elif rand > 50: print('You have encountered an elf.') health = combat.battle('elf', stats, health) if health == 'game_over': gameover() print( 'Congratulations on escaping the prison! But you still have one enemy left: the final boss!' ) health = combat.battle('boss', stats, health) if health == 'game_over': gameover() else: print( 'Congratulations, you have reached the end of Prison Escape!' ) print('Thank you! We hope you\'ll play again!') input('Press enter to end the game.') if hallway == '6': rand = encounter() if rand <= 50: print('You have encountered a dwarf.') health = combat.battle('dwarf', stats, health) if health == 'game_over': gameover() elif rand > 50: print('You have encountered an elf.') health = combat.battle('elf', stats, health) if health == 'game_over': gameover() print( 'You can see light near the end of both of the next hallways. From here there are two hallways you ' 'can choose from: Hallway 13 or Hallway 14. One of these has an enemy while the other provides safe ' 'passage to the next part of the prison.') hallway = choice('13', '14') if hallway == '13': print( 'Congratulations on escaping the prison! But you still have one enemy left: the final boss!' ) health = combat.battle('boss', stats, health) if health == 'game_over': gameover() else: print( 'Congratulations, you have reached the end of Prison Escape!' ) print('Thank you! We hope you\'ll play again!') input('Press enter to end the game.') if hallway == '14': rand = encounter() if rand <= 50: print('You have encountered a dwarf.') health = combat.battle('dwarf', stats, health) if health == 'game_over': gameover() elif rand > 50: print('You have encountered an elf.') health = combat.battle('elf', stats, health) if health == 'game_over': gameover() print( 'Congratulations on escaping the prison! But you still have one enemy left: the final boss!' ) combat.battle('boss', stats, health) if health == 'game_over': gameover() else: print( 'Congratulations, you have reached the end of Prison Escape!' ) print('Thank you! We hope you\'ll play again!') input('Press enter to end the game.')
def her_execution(board, position, role, eng_type, scot_type): ''' Activates the HERALD card. position: 'opp' or 'comp' - ai or player board: Board object ''' #List of available nobles to steal enemy_nobles = [] if role == 'SCOTLAND': enemy_role = 'ENGLAND' else: enemy_role = 'SCOTLAND' for enemy_region in board.get_controlled_regions(enemy_role): for block in enemy_region.blocks_present: if type(block) == blocks.Noble and block.name != 'MORAY' and block.allegiance != role: enemy_nobles.append(block) if position == 'opp': #Print out available nobles for noble in enemy_nobles: print(noble.name) #Take input valid_input = False while not valid_input: name_input = input('Which noble will you try to take?: ').strip().upper() #Check if the input is valid for noble in enemy_nobles: if name_input == noble.name: valid_input = True noble_to_steal = noble if not valid_input: print('Invalid input. Please try again.') elif position == 'comp': ### ### ### PICK A RANDOM NOBLE - TEMPORARY ### ### num_nobles = len(enemy_nobles) rand_selection = random.randint(0,num_nobles-1) noble_to_steal = enemy_nobles[rand_selection] print('Computer picked ' + noble_to_steal.name) ### ### ### ### ### #Roll the die and take the number from the list print('Roll a die to take the noble. 1-4 = success, 5-6 = failure.\n>') rand_num = dice.roll(1)[0] print('DIE ROLL: ' + str(rand_num)) if rand_num <= 4: #STEAL NOBLE noble_to_steal.change_allegiance() print('Success') print(noble_to_steal.name, 'changed allegiance.' ) #Find the noble's region noble_region = combat.find_location(board, noble_to_steal) if len(board.regions[noble_region.regionID].blocks_present) > 1: for block in noble_region.blocks_present: if block == noble_to_steal: print(block.name + ' added to attacking dict') board.regions[noble_region.regionID].combat_dict['Attacking'].append(block) else: print(block.name + ' added to defending dict') board.regions[noble_region.regionID].combat_dict['Defending'].append(block) print('DID HERALD BATTLE IN HERALD FUNCTION') board.regions[noble_region.regionID].combat_dict['Attacking'][0].change_allegiance() combat.battle(board.regions[noble_region.regionID].combat_dict['Attacking'], board.regions[noble_region.regionID].combat_dict['Defending'], list(), list(), board, eng_type, scot_type) #Move the noble to its own region - will sort it into attacker/defender #board.move_block(noble_to_steal, noble_region.regionID, noble_region.regionID, position) else: print('Failure')
def play_game(): #Determine scenario #scenario = prompt_scenario() scenario = 'CAMPAIGN' #Determine which side the computer plays: #computer_role, opp_role = prompt_ai_side() eng_type = 'comp' scot_type = 'comp' #Create list of blocks block_list = initialize_blocks.initialize_blocks() #Initialize board current_board = board.Board() #Fill board with pieces current_board.fill_board(block_list, scenario) for block in current_board.all_blocks: if type(block) == blocks.Noble: current_board.all_nobles.append(block) #Initialize table with known probabilities #location_prob_table = location_prob.init_probability_table(current_board, block_list) #Initialize card deck deck = cards.Deck() """GAME START""" game_playing = True if scenario == 'BRUCE': year = 1306 else: year = 1297 winter.levy(current_board, 'start') edward_prev_winter = [False] if scenario == 'BRUCE': if current_board.all_blocks[28] in current_board.scot_pool: current_board.scot_pool.remove(current_board.all_blocks[28]) if current_board.all_blocks[21] in current_board.scot_pool: current_board.scot_pool.remove(current_board.all_blocks[21]) while game_playing: """INITIALIZE YEAR - deal, etc""" #print('Year: ' + str(year)) deck.reset() eng_hand, scot_hand = deck.deal_hands() #When this gets to 5, end the year turn_counter = 0 play_turn = True while play_turn: print('Year: ' + str(year)) turn_counter += 1 current_board.turn = turn_counter #Reference to cards visible to the computer #known_cards = computer_hand #probabilites of cards #probability_cards = deck.count_probabilities(known_cards) #Find out what england wants to play if eng_type == 'opp': eng_card = eng_hand[opp_card_choice(eng_hand)] eng_parameter = 0 elif eng_type == 'comp': eng_card, eng_parameter = cardplay.select_comp_card(current_board, eng_hand, 'ENGLAND') #Find out what scotland wants to play if scot_type == 'opp': scot_parameter = 0 scot_card = scot_hand[opp_card_choice(scot_hand)] elif scot_type == 'comp': scot_card, scot_parameter = cardplay.select_comp_card(current_board, scot_hand, 'SCOTLAND') #Remove card from hands eng_hand.remove(eng_card) #Remove card from computer hand scot_hand.remove(scot_card) #Figure out who goes first, if it is true then Computer goes first - also resolves cards who_goes_first, year_cut_short = cardplay.compare_cards(current_board, eng_card, scot_card, eng_type, scot_type, eng_parameter, scot_parameter) #Get a list all the regions that are contested contested_regions = current_board.get_contested_regions() for i,region in enumerate(contested_regions): contested_regions[i] = clean_up_dict(contested_regions[i]) current_board.regions[contested_regions[i].regionID] = contested_regions[i] current_board = clean_up_board(current_board) contested_regions = current_board.get_contested_regions() #If the human goes first find out what region they want to battle in while len(contested_regions) > 0: if who_goes_first == False: battle_region = contested_regions[opp_battle_choice(contested_regions)] battle_region = set_up_combat_dict(current_board, battle_region) if battle_region.is_contested(): combat.battle(battle_region.combat_dict['Attacking'], battle_region.combat_dict['Defending'], battle_region.combat_dict['Attacking Reinforcements'], battle_region.combat_dict['Defending Reinforcements'],current_board, eng_type, scot_type) contested_regions.remove(battle_region) current_board.regions[battle_region.regionID] = battle_region else: battle_region = contested_regions[random.randint(0, len(contested_regions)-1)] battle_region = set_up_combat_dict(current_board, battle_region) if battle_region.is_contested(): combat.battle(battle_region.combat_dict['Attacking'], battle_region.combat_dict['Defending'], battle_region.combat_dict['Attacking Reinforcements'], battle_region.combat_dict['Defending Reinforcements'],current_board, eng_type, scot_type) contested_regions.remove(battle_region) current_board.regions[battle_region.regionID] = battle_region border_raids.border_raid(current_board, eng_type, scot_type) update_roster.update_roster(block_list, current_board) if year_cut_short or turn_counter >= 5: play_turn = False year += 1 if win(block_list, year, scenario, current_board): print(win(block_list, year, scenario, current_board)) return 'game over' for i,region in enumerate(current_board.regions): current_board.regions[i].enterers = {'ENGLAND':dict(), 'SCOTLAND':dict()} input_toggle.toggle_input('other') winter.update_roster(current_board) #moray_loca = combat.find_location(current_board, search.block_name_to_object(current_board.all_blocks, 'MORAY')) winter.initialize_winter(current_board, block_list, eng_type, scot_type,edward_prev_winter) winter.winter_builds(current_board, eng_type, scot_type) winter.update_roster(current_board) input_toggle.toggle_input('other')
def showHelp(): clear() print("go <direction> -- moves you in the given direction") print("inventory -- opens your inventory") print("pickup <item> -- picks up the item") print() input("Press enter to continue...") create_world() playing = True while playing: if player.location.monsters != []: player.refresh_derived() battle([player], player.location.monsters) print_situation() commandSuccess = False while not commandSuccess: commandSuccess = True command = input("What now? ") commandWords = command.split() if commandWords[0].lower( ) == "go": #cannot handle multi-word directions player.go_direction(commandWords[1]) elif commandWords[0].lower( ) == "pickup": #can handle multi-word objects targetName = command[7:] target = player.location.getItemByName(targetName) if target != False: player.pickup(target)