def play(self, person): # вывод текста сцены print self.QuestText # сражение, если оно есть в сцене if self.IsBattle: bttl = battle.Battle() if bttl.play(person) == False: return 'end' # выводим возможные выходы print u"\nВаши действия?" i = 0 for exit in self.Exits: i += 1 print u"%d - %s" % (i, exit[1]) # выбор выхода while True: try: action = int(raw_input("-->")) except: print u"Нельзя совершить такое действие!" continue try: #возвращаем имя следующей сцены return self.Exits[action - 1][0] except: print u"Нет выхода с таким номером!" continue
def new_battle(self, battle_info): '''创建一场战斗''' self.logger.info('new_battle %s' % (battle_info)) battle_id = gworld.gen_object_id() _battle = battle.Battle(self, battle_id, battle_info) self.battles[battle_id] = _battle return _battle
def start_battle(enemies): """Start battle, the player cannot """ encounter = battle.Battle(player, enemies, bag, app) battle_wins, battle_kills, battle_exps = encounter.play() global battles global wins global kills global exps global level global currentLevel battles += 1 wins += battle_wins kills += battle_kills exps += battle_exps #print(battle_exps) player.exp += battle_exps #print(player.exp) print(player.exp) currentLevel = math.floor(0.1 * math.sqrt(player.exp)) if level < currentLevel: level += currentLevel app.write('Congratulation, you have leveled up to level ' + str(level)) player.level += 1 print_results() player.reset() for enemy in enemies: enemy.reset() return set_movement()
def main(team1file, team2file, team1player, team2player): team1 = team.get_team_from_file(team1file) team2 = team.get_team_from_file(team2file) player1 = team1player player2 = team2player singlebattle = battle.Battle(team1, team2, player1, player2) result = singlebattle.battle() print("Winner: " + str(result))
def check_tall_grass(self): if self.gamemap.game_map.background2[self.player.x - 1][self.player.y - 1].name == "Tall Grass": if random.randint(1, 100) < 16: battle.Battle(self, random.choice(self.gamemap.random_monsters)(), "3").play()
def events(self): #checking trigger hitboxes if (self.trigger_hitbox[0].checkbox(self.player)): self.player.room_i = 20 self.player.setposx(2) if (self.trigger_hitbox[1].checkbox(self.player)): room = battle.Battle(random.randint(0, 3), self.player) del room
def test_04_battle_one_char(self): traits = character.CharacterCollection(ref_folder) c1 = traits.generate_random_character() c2 = traits.generate_random_character() rules = battle.BattleRules(rules_file) b = battle.Battle(c1, c2, traits, rules, print_console='No') self.assertEqual(len(str(b)) > 5, True) if c2.name in str(b) or c1.name in str(b): self.assertEqual(True, True) else: self.assertEqual(True, False) b2 = battle.Battle(c1, c2, traits, rules, print_console='Yes') self.assertEqual(len(str(b2)) > 5, True) if c2.name in str(b2) or c1.name in str(b2): self.assertEqual(True, True) else: self.assertEqual(True, False)
def play(armies, debug=False, resize=False, first_intelligence="PLAYER", second_intelligence="AI_WIP", show_AI=False): if resize: print("\x1b[8;24;80t") # print ("\x1b[8;{};80t".format(textutils.BATTLE_SCREEN.max_screen_len)) automated = (first_intelligence != 'PLAYER') and (second_intelligence != 'PLAYER') bat = battle.Battle(armies[0], armies[1], debug_mode=debug, automated=automated, show_AI=show_AI) # graphics.Screen.wrapper(graphics.battle_screen, catch_interrupt = True, arguments=[bat]) return bat.start_battle()
async def test_fight(message): player = instances.read_playerfile(message.author.id) p1 = battle.BattlePlayer(client, player, message.author) robot_poke = p1.curr_party[0].poke.to_dict() robot_poke['name'] += '_bot' robot_poke = instances.read_pokedict(robot_poke) p2 = battle.BattleAI('Mr. Roboto', [robot_poke], 'RAND', 'Hey, I won!', 'Hey, You won!') battle_instance = battle.Battle(p1, p2, client, message.channel) await battle_instance.play_battle()
def __init__(self, x,y, current_name):# Где начался бой pygame.init() self.w_event = events.Events() self.fraction = attacker # першими ходять атакуючі battle_cell=core.load_cell(x,y,current_name) self.b_map_name = battle_cell[2] self.battle = battle.Battle() self.resources = resources.Resources() self.file = current_name self.indent_x=100 self.indent_y=50
def start_story_battle(self): """ Starts a battle with the story enemies and allies. """ story_battle = battle.Battle(self.game, [self.game.player], self.enemies) battle_result = story_battle.start_battle() if battle_result: return True else: return False
def main(): # Create 2 Warriors paul = Warrior("Paul", 50, 30, 10) sam = Warrior("Sam", 50, 30, 10) print(paul) print(sam) # Create Battle object battle1 = battle.Battle() print(battle1) # Initiate Battle battle1.startFight(paul, sam)
def __init__(self): # init pygame pygame.init() pygame.display.set_caption('O An Quan') # sys self.screen = pygame.display.set_mode(dist.SCREEN_SIZE) self.screen.fill(dist.COLOR['white']) self.clock = pygame.time.Clock() self.gameRunning = True self.screenIsMenu = True # game self.menu = menu.Menu() self.battle = battle.Battle()
def run_simulation(c1, c2): """ using character and planet, run the simulation """ print('running simulation...') traits = character.CharacterCollection(character.fldr) c1 = traits.generate_random_character() c2 = traits.generate_random_character() print(c1) print(c2) rules = battle.BattleRules(battle.rules_file) b = battle.Battle(c1, c2, traits, rules, print_console='Yes') print(b.status)
def main(team1file, team2file, team1player, team2player): if team1file == '': team1 = team.make_random_team(1) else: team1 = team.get_team_from_file(team1file) if team2file == '': team2 = team.make_random_team(2) else: team2 = team.get_team_from_file(team2file) player1 = team1player player2 = team2player singlebattle = battle.Battle(team1, team2, player1, player2) result = singlebattle.battle() print("Winner: " + str(result))
def test_AI(debug=False, resize=False, first_intelligence="AI_WIP", second_intelligence="AI_RANDOM", morales = (7,7), sizes = (20, 20), num_units=4, trials=100): final_results = [0, 0] for _ in range(trials): armies = [army_mysticsoft(0, Colours.CYAN, first_intelligence, num_units, size=sizes[0], morale=morales[0]), army_bizarro(1, Colours.MAGENTA, second_intelligence, num_units, size=sizes[1], morale=morales[1])] bat = battle.Battle(armies[0], armies[1], debug_mode=False, automated=True) results = bat.start_battle() for j in [0,1]: if results[j]: final_results[j] += 1 return final_results
def test_duel(debug=False, resize=False, first_intelligence="PLAYER", second_intelligence="AI_WIP"): armies = [army_mysticsoft(0, Colours.CYAN, first_intelligence), army_bizarro(1, Colours.MAGENTA, second_intelligence)] automated = (first_intelligence != 'PLAYER') and (second_intelligence != 'PLAYER') bat = battle.Battle(armies[0], armies[1], debug_mode=debug, automated=automated) armies[0].units[0].health = 100 armies[1].units[1].health = 100 import events import contexts events.duel_accepted(bat, contexts.Context({ 'csource':armies[0].units[0], 'ctarget':armies[1].units[1]}), bat.battlescreen, bat.narrator) return 0
def handle_entire_battle(self, new_position): fight = battle.Battle(self.player_character) self.UI.display_monster_info(fight.monster.name) is_figthing = True while is_figthing: is_figthing = fight.handle_fight_round() self.is_running = (self.player_character.current_hp > 0) if not self.is_running: ui.UI.display_by_line(ui.IMAGES_DIRECTORY + ui.RIP_FILE) if fight.monster_hp < 1: self.board.make_tile_empty(new_position) self.player_character.check_if_lvl_up() self.board.place_item(new_position) if self.is_running: self.UI.display_board_after_key_press()
def game(): """Player might want to choose this option to level up fast""" difficulty = set_difficulty() enemies = create_enemies(mode, difficulty) encounter = battle.Battle(player, enemies, bag, app) battle_wins, battle_kills, battle_exps = encounter.play() global battles global wins global kills global exps global level global currentLevel battles += 1 wins += battle_wins kills += battle_kills exps += battle_exps player.exp += battle_exps #this will return player level based on their experience points currentLevel = math.floor(0.1 * math.sqrt(player.exp)) if level < currentLevel: level += currentLevel app.write('Congratulation, you have leveled up to level ' + str(level)) player.level += 1 print_results() quit = quit_game() if quit == "n": app.write('Are you sure you want to quit the game') app.write('you character data will not be saved y/n') app.write("") app.wait_variable(app.inputVariable) choice = app.inputVariable.get() if choice == 'yes' or 'y': app.write("Thank you for playing RPG Battle.") time.sleep(2) app.quit() else: raise ValueError else: player.reset() for enemy in enemies: enemy.reset() return game()
def Mapper(): table = [] app.wait_variable(app.inputVariable) size = app.inputVariable.get() for i in range(size): row = [] for j in range(size): row.append(".") table.append(row) x = y = 0 table[y][x] = 'x' xb = yb = roll = random.randint(0, size) table[yb][xb] = 'h' for row in table: print(''.join(row)) app.wait_variable(self.app.inputVariable) line = app.inputVariable.get() while line: table[y][x] = '.' if line.strip() == 'right': x += 1 elif line.strip() == 'left': x -= 1 elif line.strip() == 'up': y -= 1 elif line.strip() == 'down': y += 1 elif line.strip() == 'quit': app.quit() else: app.write('Please input a valid direction') app.wait_variable(self.app.inputVariable) line = app.inputVariable.get() table[y][x] = 'x' for row in table: self.app.write(''.join(row)) app.wait_variable(self.app.inputVariable) line = app.inputVariable.get() if x and y == xb and yb: mapper = battle.Battle(player, enemies, app) return mapper
async def battle(self, ctx): if not self.bot.battleBool: #Must Wait for Battler if (self.bot.battlerOne == None): self.bot.battlerOne = ctx.author await ctx.send( ctx.author.display_name + " wants to battle!\nType s!battle to battle them") #Second Battler is Ready else: if (ctx.author != self.bot.battlerOne): await ctx.send("First Battler: " + self.bot.battlerOne.display_name + "\nSecond Battler: " + ctx.author.display_name) battleDmOne = await self.bot.battlerOne.create_dm() await battleDmOne.send("You are battling with " + ctx.author.display_name) self.bot.battlerTwo = ctx.author battleDmTwo = await self.bot.battlerTwo.create_dm() await battleDmTwo.send("You are battling with " + self.bot.battlerOne.display_name) self.bot.battleBool = True self.bot.battleMain = bt.Battle(self.bot.battlerOne, self.bot.battlerTwo, ctx.message.channel) self.bot.battlerOne = None else: await ctx.send("You can't battle yourself!!!!") else: await ctx.send("Battle already started, wait for it to finish")
def test(): grunt0 = troop.Grunt("Ranger1", 25, 25, 1, 20, 10, 5, 20) grunt1 = troop.Grunt("Ranger2", 25, 25, 1, 20, 10, 5, 20) grunt2 = troop.Grunt("Ranger3", 25, 25, 1, 20, 10, 5, 20) grunt3 = troop.Grunt("Soldier1", 50, 50, 1, 1, 20, 20, 10) grunt4 = troop.Grunt("Soldier2", 50, 50, 1, 1, 20, 20, 10) grunt5 = troop.Grunt("Soldier3", 50, 50, 1, 1, 20, 20, 10) champion = troop.Grunt("Champion", 1000, 1000, 1, 1, 20, 20, 50) test0 = battalion.Battalion("bat1", grunt0, 30) test1 = battalion.Battalion("bat2", grunt1, 30) test2 = battalion.Battalion("bat3", grunt2, 30) test3 = battalion.Battalion("bat4", grunt3, 30) test4 = battalion.Battalion("bat5", grunt4, 30) test5 = battalion.Battalion("bat6", grunt5, 30) army0 = army.Army() army0.add_troop(test0) army0.add_troop(test1) army0.add_troop(test2) army0.add_troop(test3) army0.add_troop(test4) army0.add_troop(test5) army0.insert_troop(champion, 2) army1 = army.Army() army1.add_troop(test0) army1.add_troop(test1) army1.add_troop(test2) army1.add_troop(test3) army1.add_troop(test4) army1.add_troop(test5) battle0 = battle.Battle(army0.army, army1.army) print(len(battle0.big_army)) print(battle0)
battles = 0 wins = 0 kills = 0 mode = set_mode() race = set_race(mode) char_name = set_name() player = create_player(mode, race, char_name) app.write(player) app.write("") difficulty = set_difficulty() enemies = create_enemies(mode, difficulty) while True: encounter = battle.Battle(player, enemies, app) battle_wins, battle_kills = encounter.play() battles += 1 wins += battle_wins kills += battle_kills print_results() quit = quit_game() if quit == "n": app.write("Thank you for playing Team Fortress.") time.sleep(2) app.quit()
def update(self, values, event=None): if self.screenSetUp: if event != None: if event.type == MOUSEBUTTONUP: if event.button == 1: pos = pygame.mouse.get_pos() clicked = False for button in values.buttons[:]: clicked = misc.is_point_inside_rect( pos[0], pos[1], button.rect) if clicked: if button.code == 0: values.settings.mode = 0 self.state = 1 self.screenSetUp = False elif button.code == 5: raise Exception #Create game elif button.code == 6: self.state = 2 self.screenSetUp = False #Army builder selected elif button.code == 7: values.state = 1 self.screenSetUp = False elif button.code == 9: self.state = 0 self.screenSetUp = False elif button.code == 11: self.tabGroup.empty() self.textGroup.empty() for button in values.buttons[:]: if button.code >= 16: values.buttons.remove(button) self.set_up_battlefield_tab(values) #Selecting Armies tab elif button.code == 12: self.tabGroup.empty() self.textGroup.empty() for button in values.buttons[:]: if button.code >= 16: values.buttons.remove(button) self.set_up_armies_tab(values) #Start game button elif button.code == 14: """ if (self.missionSettings.currentBattlefield != None and self.missionSettings.currentDeployment != None): values.state = 1 self.state = 1 self.tabGroup.empty() self.textGroup.empty() self.screenSetUp = False self.gameSetup = False else: print("Selections to be made!") """ if (self.missionSettings.currentBattlefield != None and self.missionSettings.player1Army != None and self.missionSettings.player2Army != None and self.missionSettings.pointCap != None): if ((self.missionSettings.player1Army. totalPoints <= self.missionSettings.pointCap) and (self.missionSettings.player2Army. totalPoints <= self.missionSettings.pointCap)): print("READY TO PLAY") #Reset game setup variables values.state = 2 self.screenSetUp = False self.state = 1 self.gameSetup = False self.currentArmy = None self.tabGroup.empty() self.textGroup.empty() #Create battle values.battle = battle.Battle( values, [ self.missionSettings. player1Army, self. missionSettings.player2Army ], self.missionSettings. currentBattlefield.storage) self.missionSettings.currentBattlefield = None self.missionSettings.player1Army = None self.missionSettings.player2Army = None else: print("Armies above point cap") else: print("Selections to be made!") #Back out of game setup elif button.code == 15: self.state = 1 self.screenSetUp = False self.gameSetup = False self.currentArmy = None self.missionSettings.currentBattlefield = None self.missionSettings.player1Army = None self.missionSettings.player2Army = None self.tabGroup.empty() self.textGroup.empty() #Select battlefield elif button.code == 17: #Change previous selected battlefield's colour to white if self.missionSettings.currentBattlefield != None: image = values.font20.render( self.missionSettings. currentBattlefield.storage.name, True, values.colours["White"]) self.missionSettings.currentBattlefield.sprites[ 1].image = image self.missionSettings.currentBattlefield = button image = values.font20.render( self.missionSettings. currentBattlefield.storage.name, True, values.colours["Lime"]) self.missionSettings.currentBattlefield.sprites[ 1].image = image #Show battlefield info self.get_battlefield_tab_display(values) #Select an army elif button.code == 18: #Set army as current army if self.currentArmy != None: image = values.font20.render( self.currentArmy.storage.name, True, values.colours["White"]) self.currentArmy.sprites[ 1].image = image self.currentArmy = button image = values.font20.render( self.currentArmy.storage.name, True, values.colours["Lime"]) self.currentArmy.sprites[1].image = image #Assign army if there is a selected player if self.selectedPlayer == 1: self.missionSettings.player1Army = self.currentArmy.storage elif self.selectedPlayer == 2: self.missionSettings.player2Army = self.currentArmy.storage self.selectedPlayer = None for b in values.buttons: if b.code == 19: image = values.font20.render( "Player 1", True, values.colours["White"]) b.sprites[1].image = image elif b.code == 20: image = values.font20.render( "Player 2", True, values.colours["White"]) b.sprites[1].image = image #Display army info self.get_armies_tab_display(values) #Select player 1 button elif button.code == 19: #If player is already selected if self.selectedPlayer == 1: #Deselect player self.selectedPlayer = None #Turn highlight to white image = values.font20.render( "Player 1", True, values.colours["White"]) button.sprites[1].image = image #Else else: #Set selected player to 1 self.selectedPlayer = 1 #Highlight player text green image = values.font20.render( "Player 1", True, values.colours["Lime"]) button.sprites[1].image = image #Turn player 2 button white for b in values.buttons: if b.code == 20: image = values.font20.render( "Player 2", True, values.colours["White"]) b.sprites[1].image = image #Select player 2 button elif button.code == 20: #If player is already selected if self.selectedPlayer == 2: #Deselect player self.selectedPlayer = None #Turn highlight to white image = values.font20.render( "Player 2", True, values.colours["White"]) button.sprites[1].image = image #Else else: #Set selected player to 2 self.selectedPlayer = 2 #Highlight player text green image = values.font20.render( "Player 2", True, values.colours["Lime"]) button.sprites[1].image = image #Turn player 2 button white for b in values.buttons: if b.code == 19: image = values.font20.render( "Player 1", True, values.colours["White"]) b.sprites[1].image = image break else: self.group.empty() values.buttons = [] self.bgColour = None self.bgImage = None if self.state == 0: self.get_main_menu(values) elif self.state == 1: self.get_play_menu(values) elif self.state == 2: if not self.gameSetup: self.get_game_setup_menu(values) self.gameSetup = True self.set_up_battlefield_tab(values) self.screenSetUp = True
def Mapper(): table = [] app.wait_variable(app.inputVariable) size = int(app.inputVariable.get()) for i in range(size): row = ["|", "|"] for j in range(size): row.insert(1, ".") table.append(row) x = 1 y = 0 table[y][x] = 'x' rollx = random.randint(1, size) rolly = random.randint(1, size) xb = rollx yb = rolly table[yb][xb] = 'e' rollrockx = random.randint(2, size) rollrocky = random.randint(1, size) xr = rollrockx yr = rollrocky xrr = rollrockx - 1 xrrr = rollrockx + 1 table[yr][xr] = '/^\\' #Mountain object table[yr][ xrr] = '' #This makes it so that there are no extra dots in this line table[yr][xrrr] = '' #" " app.write("Please Input Directions") app.write("W: Up") app.write("A: Left") app.write("S: Down") app.write("D: Right") rolllakex = random.randint(2, size) rolllakey = random.randint(1, size) xl = rolllakex yl = rolllakey xll = rolllakex - 1 xlll = rolllakex + 1 xllll = rolllakex - 2 table[yl][xl] = '~~~~' #lake object table[yl][ xll] = '' #This makes it so that there are no extra dots in this line table[yl][xlll] = '' #" " table[yl][xllll] = '' #" " xs = xl + 1 ys = yl - 1 xsl = xs - 21 table[ys][xs] = '~~' #lake object table[ys][ xsl] = '' #This makes it so that there are no extra dots in this line app.write('') app.write("_" * size + "__") if rolllakex == rollrockx: rolllakex = random.randint(2, size) if rolllakey == rollrocky: rolllakey = random.randint(1, size) if rollx == rollrockx or rolly == rollrocky or rollx == rolllakex or rolly == rolllakey: rollx = random.randint(1, size) rolly = random.randint(1, size) for row in table: app.write(''.join(row)) app.write("=" * size + "==") app.wait_variable(app.inputVariable) line = app.inputVariable.get() while line: table[y][x] = '.' if line.strip() == 'd' or line.strip() == 'D': x += 1 elif line.strip() == 'a' or line.strip() == 'A': x -= 1 elif line.strip() == 'w' or line.strip() == 'W': y -= 1 elif line.strip() == 's' or line.strip() == 'S': y += 1 elif line.strip() == 'quit': app.quit() else: app.write('Please input a valid direction') app.wait_variable(app.inputVariable) line = app.inputVariable.get() table[y][x] = 'x' app.write("") app.write("") app.write("") app.write("") app.write("") app.write("") app.write("") app.write("") app.write("") app.write("") app.write("") app.write("") app.write("") app.write("") app.write("") app.write("") #This just makes it so that the screen isn't cluttered app.write("") app.write("Please Input Directions:") app.write("W: Up") app.write("A: Left") app.write("S: Down") app.write("D: Right") for row in table: app.write(''.join(row)) app.wait_variable(app.inputVariable) line = app.inputVariable.get() if x == xb and y == yb: mapper = battle.Battle(player, enemies, app) return mapper
pManager = base.PlayerManager(libpkmon.player, terrain, base.playerEvent, base.npcs) pManager.getPlayer().setPos(5 + 4, 10 + 4) LoadMap(pManager.getPlayer().getPos()) npcManager = base.NPCManager() for i in base.npcs: npcManager.new(i[0], i[1], base.npcs[i]) pEventList = [] runningNpcEvent = base.NPC(None, None) uMenu = menu.init_menu(menu.buttons, menu.inst) uBackpack = backpack.Backpack(wm, pManager.getPlayer()) uBattle = battle.Battle(uBackpack, wm) menu.inst[2].setBackpack(uBackpack) import time fps = 0 t = time.clock() direction = [] while True: evt.update() if evt.type == pygame.QUIT: break screen.fill((0, 0, 0)) # render terrain to gaming world rgx, rgy = world.getTerrainRange()
mv_dir_both = None atk_range_1 = 100 atk_range_2 = 100 for i in range(teamsize): team_1.charlist.append( character.Character("Tusk1_" + str(i), health_1, mana1, np.array([width * i / teamsize, 0]), max_atk_cd_1, atk_cd_1, max_spell_cd_1, spell_cd_1, atk_1, armor_1, mv_speed_1, mv_dir_both, atk_range_1, team_1)) team_2.charlist.append( character.Character("Tusk2_" + str(i), health_2, mana1, np.array([width * i / teamsize, 300]), max_atk_cd_2, atk_cd_2, max_spell_cd_2, spell_cd_2, atk_2, armor_2, mv_speed_2, mv_dir_both, atk_range_2, team_2)) #### Set up game #### ACRun = MainRun(width, height) #### create new battle #### # class Battle: # (max_time_, time_, team1_, team2_, timestep_, width_, height_, active_=True) sim = battle.Battle(200, 0, team_1, team_2, 0.5, width, height, window) ACRun.main() # while sim.active: # sim.update()
def draw_menu(stdscr): locale.setlocale(locale.LC_ALL, "") k = 0 cursor_x = 0 cursor_y = 0 name = "" curses.curs_set(0) curses.cbreak() curses.mousemask(curses.ALL_MOUSE_EVENTS) stdscr.keypad(1) game_box = stdscr.derwin(39, 99, 0, 1) command_box = stdscr.derwin(39, 48, 0, 101) last_mouse_x = 0 last_mouse_y = 0 direction = "right" state_handler = StateHandler(game_box, command_box, stdscr) state_handler.log_info(stdscr.getmaxyx()) curses.start_color() curses.use_default_colors() for i in range(0, curses.COLORS - 1): curses.init_pair(i + 1, i, i - 1) curses.init_pair(1, curses.COLOR_CYAN, curses.COLOR_RED) curses.init_pair(2, curses.COLOR_WHITE, curses.COLOR_RED) curses.init_pair(3, curses.COLOR_BLACK, curses.COLOR_WHITE) curses.init_pair(4, curses.COLOR_BLACK, curses.COLOR_BLUE) curses.init_pair(5, curses.COLOR_BLACK, curses.COLOR_GREEN) curses.init_pair(6, curses.COLOR_BLACK, curses.COLOR_MAGENTA) curses.init_pair(7, curses.COLOR_BLACK, curses.COLOR_YELLOW) curses.init_pair(8, curses.COLOR_BLACK, curses.COLOR_CYAN) #Color range 131 -> 147 reserved curses.init_pair(131, 232, 165) curses.init_pair(132, curses.COLOR_YELLOW, curses.COLOR_GREEN) curses.init_pair(133, curses.COLOR_RED, -1) curses.init_pair(134, curses.COLOR_GREEN, -1) curses.init_pair(135, curses.COLOR_CYAN, -1) curses.init_pair(136, curses.COLOR_YELLOW, -1) curses.init_pair(137, curses.COLOR_BLUE, -1) curses.init_pair(138, 130, -1) # Enhanced Dialogue curses.init_pair(139, 238, 242) #Cobblestone curses.init_pair(140, 237, 242) #Fence curses.init_pair(141, 240, 40) #Grass Fence curses.init_pair(142, 136, 40) #Tree Bot curses.init_pair(143, 40, 22) #Tree Top curses.init_pair(144, 220, 94) #Beer curses.init_pair(145, 94, 52) #Wooden Chair curses.init_pair(146, 237, 52) #floor fence curses.init_pair(147, curses.COLOR_WHITE, -1) curses.init_pair(148, curses.COLOR_YELLOW, 238) #Wall torch curses.init_pair(149, 94, -1) #brown fg, black bg curses.init_pair(150, 242, -1) #grey fg, black bg curses.init_pair(151, curses.COLOR_BLACK, 247) curses.init_pair(152, curses.COLOR_WHITE, curses.COLOR_RED) curses.init_pair(153, curses.COLOR_RED, 52) #Farming patch not planted curses.init_pair(154, curses.COLOR_YELLOW, 52) #Farming patch planted curses.init_pair(155, curses.COLOR_GREEN, 52) #Farming patch planted curses.init_pair(156, curses.COLOR_YELLOW, 40) #Yellow fg on grass bg (initally for AriamBush) curses.init_pair(157, curses.COLOR_YELLOW, 185) #Wheat curses.init_pair(158, 208, 208) # Fire? curses.init_pair(159, curses.COLOR_CYAN, curses.COLOR_CYAN) #Window? curses.init_pair(160, 130, curses.COLOR_RED) curses.init_pair(161, curses.COLOR_WHITE, 238) # Empty Bookcase curses.init_pair(162, curses.COLOR_WHITE, curses.COLOR_WHITE) curses.init_pair(163, curses.COLOR_BLACK, curses.COLOR_BLACK) height, width = state_handler.stdscr.getmaxyx() player_first_init = False while (k != ord('q')): stdscr.erase() game_box.border() command_box.border() if state_handler.player and state_handler.gamemap and not player_first_init: last_gamemap = state_handler.gamemap.name player_first_init = True #print("Player initialized") if state_handler.player is not False and state_handler.timer_started == False: state_handler.start_timer() if state_handler.map_screen == True: if state_handler.player.health <= 0: helper.popup(stdscr, state_handler, ["You have died"]) state_handler.game_state = states.Intro(state_handler) state_handler.command_state = states.main_menu(state_handler) state_handler.map_screen = False state_handler.command_state.commands[0].active = True state_handler.player = False state_handler.first_time = True continue state_handler.player.turn += 1 state_handler.check_overworld_status_effects() #if k == 9 and is_tab_enabled(state_handler): # k = 1 # state_handler.change_map_screen() # continue if state_handler.able_to_move == False: curses.halfdelay(2) for item in state_handler.gamemap.game_map.objects: if item.type == "monster" and item.path_to_target: item.color = 133 item.x, item.y = item.path_to_target[0] item.path_to_target.pop(0) if item.x == state_handler.player.x and item.y == state_handler.player.y: curses.flash() result = item.action() if result: if len([ "a" for monster in state_handler.gamemap.game_map.objects if monster.type == "monster" and len(monster.path_to_target) > 0 ]) < 1: #WTF state_handler.able_to_move = True if item.flag: state_handler.player.flags.append(item.flag) state_handler.gamemap.game_map.objects.remove(item) else: break if not state_handler.player: state_handler.able_to_move = True continue if state_handler.able_to_move == True: curses.cbreak() #curses.halfdelay(3) state_handler.timer.terminate() if k in [ curses.KEY_DOWN, curses.KEY_UP, curses.KEY_LEFT, curses.KEY_RIGHT, ord("w"), ord("a"), ord("s"), ord("d") ]: if state_handler.player.phaseshift: state_handler.player.phaseshift -= 1 #state_handler.check_tall_grass() name = "" if k == curses.KEY_DOWN or k == ord("s"): #if direction == "down": # curses.flushinp() direction = "down" next_direction = state_handler.player.x + 1 next_tile = next_direction, state_handler.player.y if state_handler.player.x < 37 and state_handler.check_collision( next_tile): state_handler.player.last_pos = state_handler.player.x, state_handler.player.y state_handler.player.minion_pos.append( state_handler.player.last_pos) if len(state_handler.player.minion_pos ) > state_handler.player.max_minions: state_handler.player.minion_pos.pop(0) state_handler.player.x = next_direction k = 1 elif k == curses.KEY_UP or k == ord("w"): #if direction == "up": # curses.flushinp() direction = "up" next_direction = state_handler.player.x - 1 next_tile = next_direction, state_handler.player.y if state_handler.player.x > 1 and state_handler.check_collision( next_tile): state_handler.player.last_pos = state_handler.player.x, state_handler.player.y state_handler.player.minion_pos.append( state_handler.player.last_pos) if len(state_handler.player.minion_pos ) > state_handler.player.max_minions: state_handler.player.minion_pos.pop(0) state_handler.player.x = next_direction k = 1 elif k == curses.KEY_LEFT or k == ord("a"): #if direction == "left": # curses.flushinp() direction = "left" next_direction = state_handler.player.y - 1 next_tile = state_handler.player.x, next_direction if state_handler.player.y > 1 and state_handler.check_collision( next_tile): state_handler.player.last_pos = state_handler.player.x, state_handler.player.y state_handler.player.minion_pos.append( state_handler.player.last_pos) if len(state_handler.player.minion_pos ) > state_handler.player.max_minions: state_handler.player.minion_pos.pop(0) state_handler.player.y = next_direction k = 1 elif k == curses.KEY_RIGHT or k == ord("d"): #if direction == "right": # curses.flushinp() direction = "right" next_direction = state_handler.player.y + 1 next_tile = state_handler.player.x, next_direction if state_handler.player.y < 96 and state_handler.check_collision( next_tile): state_handler.player.last_pos = state_handler.player.x, state_handler.player.y state_handler.player.minion_pos.append( state_handler.player.last_pos) if len(state_handler.player.minion_pos ) > state_handler.player.max_minions: state_handler.player.minion_pos.pop(0) state_handler.player.y = next_direction k = 1 elif k == ord(" "): state_handler.check_action = True state_handler.check_npc_action() if k != ord(" "): #Check for when you are not on top of NPCS, so I can define actions in states.py #for example over countertops at Hall of justice or shops state_handler.check_action = False state_handler.gamemap.check_events() for item in state_handler.gamemap.game_map.objects: if item.type == "monster": if state_handler.gamemap.cave: break if item.path_to_target or item.radar == False: break #check target target_direction = False breakable = False _directions = { "S": (1, 0), "N": (-1, 0), "W": (0, -1), "E": (0, 1), "SW": (1, -1), "NW": (-1, -1), "SE": (1, 1), "NE": (-1, 1) } original_position = (item.x, item.y) for key, v in _directions.items(): check = [original_position[0], original_position[1]] if key in ["S", "N", "W", "E"]: target_range = 5 else: target_range = 4 if state_handler.player.phaseshift > 0: target_range = 1 for i in range(target_range): check[0] += v[0] check[1] += v[1] #if not state_handler.check_collision((check[0], check[1]), player_control=False): # breakable = True # break if check[0] == state_handler.player.x and check[ 1] == state_handler.player.y: target_direction = key breakable = True break if breakable: break if breakable: if not target_direction: break state_handler.able_to_move = False check = [original_position[0], original_position[1]] while check[0] != state_handler.player.x or check[ 1] != state_handler.player.y: item.path_to_target.append((check[0], check[1])) check[0] += _directions[target_direction][0] check[1] += _directions[target_direction][1] item.path_to_target.append((check[0], check[1])) curses.ungetch(curses.KEY_F0) for item in state_handler.gamemap.game_map.objects: if item.type == "monster" and state_handler.player.x == item.x and state_handler.player.y == item.y: result = item.action() if result: if item.flag: state_handler.player.flags.append(item.flag) state_handler.gamemap.game_map.objects.remove(item) curses.cbreak() #Rendering to screen state_handler.gamemap.draw() #draw_commands(state_handler.ingame_menu, state_handler.command_box) if last_gamemap != state_handler.gamemap.name: #If we went to a new screen last_gamemap = state_handler.gamemap.name if state_handler.player: state_handler.player.minion_pos = [ (state_handler.player.x, state_handler.player.y) ] * state_handler.player.max_minions for idx, item in enumerate(state_handler.player.minions): stdscr.addch(state_handler.player.minion_pos[::-1][idx][0], state_handler.player.minion_pos[::-1][idx][1] + 1, state_handler.player.minions[idx]) state_handler.player.draw(game_box) for x in range(len(state_handler.gamemap.game_map.background2)): for y in range( len(state_handler.gamemap.game_map.background2[x])): if state_handler.gamemap.game_map.background2[x][y].over: if (state_handler.gamemap.game_map.background2[x][y].x, state_handler.gamemap.game_map.background2[x] [y].y) == (state_handler.player.x, state_handler.player.y): char = "@" if state_handler.player.phaseshift: char = str(state_handler.player.phaseshift) state_handler.gamemap.game_map.background2[x][ y].draw(state_handler, inverted=True, character=char) else: state_handler.gamemap.game_map.background2[x][ y].draw(state_handler) for item in state_handler.gamemap.game_map.objects: if (item.x, item.y) != (state_handler.player.x, state_handler.player.y ) and not state_handler.gamemap.fov: item.draw(state_handler) #If adding pets or followers later, this is the "formula" for translating last pos to draw #stdscr.addch(state_handler.player.last_pos[0], state_handler.player.last_pos[1] + 1, "h") #Drawing 'player interface' #interface_start = 41 #interface_end = 49 stdscr.addch(39, 1, curses.ACS_ULCORNER, curses.color_pair(136)) stdscr.addch(48, 1, curses.ACS_LLCORNER, curses.color_pair(136)) stdscr.addch(39, 13, curses.ACS_URCORNER, curses.color_pair(136)) stdscr.addch(48, 13, curses.ACS_LRCORNER, curses.color_pair(136)) for idx, item in enumerate(art.draw_portrait_dwarf()): stdscr.addstr(40 + idx, 2, item) stdscr.addstr(39, 17, f"Name: {state_handler.player.name}") stdscr.addstr( 40, 17, f"Type: {state_handler.player.race} {state_handler.player.vocation}" ) stdscr.addstr(42, 17, f"Stats:", curses.color_pair(136)) stdscr.addstr( 43, 17, f"Strength: {state_handler.player.get_combined_stats()['Strength']}" ) stdscr.addstr( 44, 17, f"Agility: {state_handler.player.get_combined_stats()['Agility']}" ) stdscr.addstr( 45, 17, f"Intelligence: {state_handler.player.get_combined_stats()['Intelligence']}" ) stdscr.addstr( 46, 17, f"Charisma: {state_handler.player.get_combined_stats()['Charisma']}" ) stdscr.addstr( 47, 17, f"Alchemy: {state_handler.player.get_combined_stats()['Alchemy']}" ) stdscr.addstr(48, 17, f"Farming: {state_handler.player.stats['Farming']}") ppos = f"Player-Pos: X: {state_handler.player.x} Y: {state_handler.player.y}" stdscr.addstr(45, int((150 - len(ppos)) / 2), ppos) turns = f"Turn: {state_handler.player.turn}" stdscr.addstr(46, int((150 - len(turns)) / 2), turns) info = f"Phaseshift = {state_handler.player.phaseshift}" stdscr.addstr(47, int((150 - len(info)) / 2), info) info_2 = f"Nr. of Status_effects = {len(state_handler.player.status_effects)}" stdscr.addstr(48, int((150 - len(info_2)) / 2), info_2) if state_handler.player.mindvision: state_handler.player.mindvision -= 1 for item in state_handler.gamemap.game_map.objects: item.draw(state_handler) for item in state_handler.player.flora: if item[1] + item[2] <= state_handler.timer.tid: state_handler.player.flora.pop( state_handler.player.flora.index(item)) if last_mouse_x != 0: state_handler.game_box.addstr(last_mouse_y, last_mouse_x - 1, name) else: #if k == 9 and is_tab_enabled(state_handler): # k = 1 # state_handler.change_map_screen() # state_handler.command_state = state_handler.gamemap.menu_commands(state_handler) # state_handler.command_state.commands[0].active = True # continue if k == curses.KEY_DOWN: get_next(state_handler.command_state, command_box) elif k == curses.KEY_UP: get_prev(state_handler.command_state, command_box) elif k == curses.KEY_RIGHT: pass elif k == curses.KEY_LEFT: cursor_x = cursor_x - 1 elif k == ord(" "): state_handler.game_state.execute() for item in state_handler.command_state.commands: if item.active: next_command_state = item.execute_command() if next_command_state == False: pass else: state_handler.command_state = next_command_state( state_handler) if hasattr(state_handler.command_state, "game"): state_handler.command_state.commands[ 0].active = True else: state_handler.command_state.commands[ 0].active = True next_game_state = item.execute_game() if next_game_state == False: pass elif hasattr(state_handler.command_state, "game"): state_handler.gamemap = state_handler.player.location( state_handler) state_handler.game_state = state_handler.gamemap.menu( state_handler) state_handler.ingame_menu = state_handler.gamemap.ingame_menu( state_handler) else: if state_handler.player != False: try: state_handler.gamemap = state_handler.player.location( state_handler) except: state_handler.gamemap = state_handler.player.location( state_handler, state_handler.player.last_target) state_handler.ingame_menu = state_handler.gamemap.ingame_menu( state_handler) state_handler.game_state = state_handler.gamemap.menu( state_handler) curses.ungetch(curses.KEY_F0) else: state_handler.game_state = next_game_state( state_handler) state_handler.game_state.draw() draw_commands(state_handler.command_state, state_handler.command_box) cursor_x = max(0, cursor_x) cursor_x = min(width - 1, cursor_x) cursor_y = max(0, cursor_y) cursor_y = min(height - 1, cursor_y) if state_handler.player: cursor_y = state_handler.player.y cursor_x = state_handler.player.x #statusbarstr = "Mouse: x: {} , y: {} | Pos: {}, {} | {}x{} | Action: {}".format(last_mouse_x, last_mouse_y,cursor_x, cursor_y, width, height, state_handler.action) #stdscr.attron(curses.color_pair(3)) #stdscr.addstr(height, 0, statusbarstr) #stdscr.attroff(curses.color_pair(3)) stdscr.refresh() k = stdscr.getch() #curses.flushinp() if k == curses.KEY_MOUSE: unused_1, last_mouse_x, last_mouse_y, unused_2, unused_3 = curses.getmouse( ) if last_mouse_x <= 97 and last_mouse_y <= 37 and state_handler.map_screen == True: for item in state_handler.gamemap.game_map.objects: if item.y == (last_mouse_x - 1) and item.x == last_mouse_y: name = item.name break else: name = state_handler.gamemap.game_map.background2[ last_mouse_y - 1][last_mouse_x - 2].name else: last_mouse_y = 0 last_mouse_x = 0 k = 1 if k == ord("e") and state_handler.player != False: inventory.view_equipment(state_handler.stdscr, state_handler) if k == ord("i") and state_handler.player != False: inventory.view_inventory_2(state_handler) if k == ord("p") and state_handler.player != False: inventory.view_spellbook(state_handler.stdscr, state_handler) if k == ord("l"): save_answer = helper.two_options( state_handler.stdscr, state_handler, ["Do you wish to [Save] the game?"], ["Yes", "No"]) if save_answer: state_handler.save_player() if k == ord("o") and state_handler.player != False: if len(state_handler.player.minions ) < state_handler.player.max_minions: state_handler.player.minions.append("W") if k == ord("c") and state_handler.player != False: battlemode = battle.Battle(state_handler, monster.CaveTroll(state_handler), battlefields.Battlefield("Dungeon")) battlemode.play() if k == ord("k") and state_handler.player != False: for var in dir(items): if var.startswith("__"): continue elif var == "Item": continue elif var == "abilities": continue elif var == "random": continue elif var == "art": continue elif var == "helper": continue elif var == "Sets": continue else: item_to_add = getattr(items, var)() state_handler.player.inventory.append(item_to_add) if k == ord("1"): if direction == "up": state_handler.player.x -= 4 if state_handler.player.x < 2: state_handler.player.x = 2 elif direction == "down": state_handler.player.x += 4 if state_handler.player.x > 36: state_handler.player.x = 36 elif direction == "left": state_handler.player.y -= 4 if state_handler.player.y < 2: state_handler.player.y = 2 elif direction == "right": state_handler.player.y += 4 if state_handler.player.y > 95: state_handler.player.y = 95 if k == ord("2"): state_handler.player.hotkeys["2"].execute(state_handler.player) if k == ord("3"): actions.SpeakTerminal(state_handler.stdscr, state_handler).execute() if k == ord("4"): state_handler.player.ascii = not state_handler.player.ascii if k == ord("5"): #state_handler.player.status_effects.append(abilities.StatBuff(5,"Intelligence", 13, state_handler.player)) helper.two_options(state_handler.stdscr, state_handler, ["Teleport Home?"], ["yes", "no"]) if k == ord("6"): #state_handler.timer.tid += 1209600 #anim = animation.boat_animation() #animation.play(anim, state_handler) helper.popup(state_handler.stdscr, state_handler, ["You arrive at [Port Avery, Blackcliff]"]) state_handler.timer.terminate()
import annchienta, scene, party, battle partyManager = party.getPartyManager() sceneManager = scene.getSceneManager() passiveObject = annchienta.getPassiveObject() # Fight with wolf here. audioManager.playMusic("music/battle_3.ogg") # Create some enemies enemies = [battle.getBattleManager().createEnemy("wolf")] # Start a battle. b = battle.Battle(partyManager.team + enemies) b.background = annchienta.Surface("images/backgrounds/woods.png") b.run() if b.won: partyManager.addRecord("tasumian_killed_" + passiveObject.getName()) partyManager.refreshMap()
break else: app.write("Party is full!") app.write("") time.sleep(1) break difficulty = set_difficulty() while True: move = map_.Map(players, mode, difficulty, app) # generates world map while True: enemies, leave = move.run() # runs map if leave: # quit cond break encounter = battle.Battle(players, enemies, app) # makes battle once map is returned battle_wins, battle_kills, loss = encounter.play() # runs battle battles += 1 wins += battle_wins kills += battle_kills if loss: break print_results() # if loss or exit quit = quit_game() # prompt user if quit == "n": app.write("Thank you for playing Alien Defense.") time.sleep(2) app.quit()