def spacePort(player): new_enemy = newEnemy() print("""You head down to the Space Port. Location: Space Port \"What do you think you're doing here?\" asks a {0.name} as he pulls out a laser rifle. """.format(new_enemy)) battle(player, new_enemy)
def spaceBar(player): new_enemy = newEnemy() print("""You head over to the Space Bar. Location: Space Bar Walking into the bar you find a fight going on. A {0.name} pulls out a laser rifle and points it at you. """.format(new_enemy)) battle(player, new_enemy)
def restaurant(player): new_enemy = newEnemy() print("""You head up to a local restaurant. Location: Restaurant A bunch of species clamor for deals. Stepping in, you bump into one. \"You're not getting out of here alive.\" says a {0.name}, pulling out a force knife. """.format(new_enemy)) battle(player, new_enemy)
def corridor(player): new_enemy = newEnemy() print("""As you head back to the bar, you notice someone following you. Location: Corridor You stop and turn, asking him what he is doing? \"I'm robbing you, but you'll probably end up dead,\" says the {0.name}, Needler in his hand. """.format(new_enemy)) battle(player, new_enemy)
def main(): global p_eqArmor global p_eqWeapon runtime = 1 while runtime == 1: choice = input("Commands Test: >> ").lower() print("") commands(choice) if runtime == 2: battle()
def addBattle(self, battle_id, battle_type, natType, founder, host_ip, port, maxplayers, password, rank, mapname, name, mod, lan=False): exists = False host = self.userFromName(founder) if host == None: print "Couldn't find ", founder return False #does this battle already exist? if so, do not add it again! for x in self.battleList: if x.server_id == int(battle_id): x.name = name x.host = host x.host_ip = host_ip x.port = int(port) x.battle_type = int(battle_type) x.natType = int(natType) x.maxplayers = int(maxplayers) x.passworded = bool(int(password)) x.rank = int(rank) x.mapName = mapname x.modName = mod x.lan = lan print "Battle ", x.server_id, "'s fields were updated!" exists = True if not exists: self.battleList.append( battle(self.parent_window, self, int(battle_id), int(battle_type), int(natType), host, host_ip, int(port), int(maxplayers), bool(int(password)), rank, mapname, name, mod, lan)) index = self.indexFromBattleId(int(battle_id)) if index == -1: return False self.battleList[index].Id = index # Update the list display (set more elements, and sort which also refreshes) #self.parent_window.list_lobby_1_games.SetItemCount(len(self.battleList)) self.parent_window.list_lobby_1_games.InsertImageItem( index, self.battleList[index].passworded_int) self.parent_window.list_lobby_1_games.Sort() return True
def main(first_time): """ Runs the main game functions, such as movement and geospatial location of the player, and checks for battle probability. """ print("\nNow, what would you like to do?") time.sleep(1) movement = input( "\nMove forward (f), backward (b), leftward(l), or rightward(r): " ).lower() paces = random.randint(4, 10) moved = True if players_pokemon.max_hp > players_pokemon.hp: players_pokemon.hp += paces if players_pokemon.hp > players_pokemon.max_hp: players_pokemon.hp = players_pokemon.max_hp if movement in 'f': moved = player.assess_geospace(1, paces) elif movement in 'b': moved = player.assess_geospace(1, paces / -1) elif movement in 'l': moved = player.assess_geospace(0, paces / -1) elif movement in 'r': moved = player.assess_geospace(0, paces) else: print("Invalid entry. Try again.\n") time.sleep(1) return time.sleep(1) if moved: if assess_encounter_probability(paces, first_time): battle() return
def encounter(character): """ Encounter an enemy :param character: :return: """ location = character["location"] locations = process_json("locations.json") enemies = process_json("enemies.json") curr_location = locations["locations"][location] location_enemies = list(curr_location["enemies"].keys()) location_rates = list(curr_location["enemies"].values()) max_rate = 0 for item in location_rates: max_rate += item if max_rate != 1 and max_rate > 0: none_rate = 1 - max_rate location_rates.append(none_rate) location_enemies.append("none") if len(location_enemies) > 0: print("You look around for enemies...") choice = numpy.random.choice(location_enemies, 1, location_rates) if choice[0] != "none": print("###########################") print("##########BATTLE###########") print("###########################") print(choice[0] + " wants to fight") enemy = enemies["enemies"][choice[0]] battle(character, enemy) else: print("No enemies were found") else: print("There are no enemies in this area.")
def attacks(self, victim): if battle(self, victim): if victim.player is not None: #this was occupied by some player, that player must reliquish control victim.player.relinqishControl(victim) victim.belongsTo(self.player) pygame.mixer.music.load('SoundEffects/March.wav') pygame.mixer.music.play(0) victim.army = self.army self.army = 0 victim.color_surface() victim.updateTroopDisplay() self.updateTroopDisplay() else: victim.updateTroopDisplay() self.updateTroopDisplay()
def addBattle(self, battle_id, battle_type, natType, founder, host_ip, port, maxplayers, password, rank, mapname, name, mod, lan=False): exists = False host = self.userFromName(founder) if host == None: print "Couldn't find ", founder return False #does this battle already exist? if so, do not add it again! for x in self.battleList: if x.server_id == int(battle_id): x.name = name x.host = host x.host_ip = host_ip x.port = int(port) x.battle_type = int(battle_type) x.natType = int(natType) x.maxplayers = int(maxplayers) x.passworded = bool(int(password)) x.rank = int(rank) x.mapName = mapname x.modName = mod x.lan = lan print "Battle ", x.server_id, "'s fields were updated!" exists = True if not exists: self.battleList.append(battle(self.parent_window, self, int(battle_id), int(battle_type), int(natType), host, host_ip, int(port), int(maxplayers), bool(int(password)), rank, mapname, name, mod, lan)) index = self.indexFromBattleId(int(battle_id)) if index == -1: return False self.battleList[index].Id = index # Update the list display (set more elements, and sort which also refreshes) #self.parent_window.list_lobby_1_games.SetItemCount(len(self.battleList)) self.parent_window.list_lobby_1_games.InsertImageItem(index, self.battleList[index].passworded_int) self.parent_window.list_lobby_1_games.Sort() return True
import tree # Create a knight sir_cumstance = generateKnightStats() # Tell us about him print "Sir Cumstance is ", statsToString(sir_cumstance) # Have an adventure print "he was exploring the glade and meet an evil wizard, who atacked..." # With a battle # Python note: The * notation is unpacking e.g. # battle(*sir_cumstance) = battle(sir_cumstance[0], sir_cumstance[1], sir_cumstance[2], sir_cumstance[3]) result = battle(*sir_cumstance) print "the result is..." print battleResultToText(result) # Have 100 battles to collect some data to learn from knightStats, battleResults = haveSomeBattles(1000) i = 4 print "One of the battles (number %s) was %s resulting in %s" %(i, statsToString(knightStats[i]), battleResultToText(battleResults[i])) print "%s%% of battles won" % (100*sum(battleResults)/len(battleResults)) # Create a decision tree by learning from the battle data battleTree = tree.makeTree(knightStats, battleResults, 4) # We can experiment with different tree depths, this can lead to over fitting the data,
import pprint import tree # Create a knight sir_cumstance = generateKnightStats() # Tell us about him print "Sir Cumstance is ", statsToString(sir_cumstance) # Have an adventure print "he was exploring the glade and meet an evil wizard, who atacked..." # With a battle # Python note: The * notation is unpacking e.g. # battle(*sir_cumstance) = battle(sir_cumstance[0], sir_cumstance[1], sir_cumstance[2], sir_cumstance[3]) result = battle(*sir_cumstance) print "the result is..." print battleResultToText(result) # Have 100 battles to collect some data to learn from knightStats, battleResults = haveSomeBattles(1000) i = 4 print "One of the battles (number %s) was %s resulting in %s" % ( i, statsToString(knightStats[i]), battleResultToText(battleResults[i])) print "%s%% of battles won" % (100 * sum(battleResults) / len(battleResults)) # Create a decision tree by learning from the battle data battleTree = tree.makeTree(knightStats, battleResults, 4) # We can experiment with different tree depths, this can lead to over fitting the data, # especially if we have a small data set.
from alchemy import * from battle import * from userinput import * from locations import * from windows import * loadMap("world.txt") MakeMiniMap() placeingredients() print "PYGAME GAME BY CASEY YARDLEY" clock = pygame.time.Clock() var.cx = 17 * var.tilepix var.cy = 20 * var.tilepix while var.run == True: pygame.display.set_caption("PYGAME GAME") # User Input myEvents() movement() userInKey() var.imouse = MouseItems() DropPickItems() # Actions togMiniMap() alchemy() battle() towns() # Windows windowAll() pygame.display.flip() clock.tick(40)
def go_to(character): """ Travel to an adjacent location :param character: :return: """ locations = process_json("locations.json") old_location = character["location"] accesses = character["access"] loc_list = locations["locations"][old_location]["adjacent"] enemies = process_json("enemies.json") while True: print(', '.join(loc_list)) new_location = input("Choose a location (q to quit): ") for loc in locations["xref"]: if loc.startswith(new_location): new_location = loc break if "Recall" in character[ "skills"] and new_location not in loc_list and new_location == "Starterville": if character["mp"] > 10: character["location"] = new_location character["mp"] -= 10 print("You are now in " + new_location) print("You used 10 mana") break else: print("You do not have enough mana for Recall!") break if new_location in loc_list: if new_location not in accesses and len( list(locations["locations"][new_location] ["enemies"].keys())) > 0: print("You do not have access to this location!") while True: challenge = input( "Would you like to attempt clear this location?(y/n): " ) if challenge == "y": location_enemies = list( locations["locations"][new_location] ["enemies"].keys()) if len(location_enemies) > 0: for i in range(0, 5): if len(location_enemies) != 1: random = numpy.random.randint( 0, len(location_enemies) - 1) enemy = enemies["enemies"][ location_enemies[random]] else: enemy = enemies["enemies"][ location_enemies[0]] if character["hp"] > 0: battle(character, enemy) else: print("You were defeated!") break if character["hp"] > 0: print("You defeated the gauntlet") print("You now have access to this location!") accesses.append(new_location) break elif challenge == "n": break if old_location in locations["locations"][new_location][ "adjacent"]: if new_location in accesses or len( list(locations["locations"][new_location] ["enemies"].keys())) == 0: character["location"] = new_location print("You are now in " + new_location) break else: print("You can not go back the same way!") while True: cont = input("Continue?(y/n): ") if cont == "y": character["location"] = new_location print("You are now in " + new_location) break elif cont == "n": break else: print("Invalid option!") break elif new_location == "q": break else: print("Invalid location, please try again")
if self.attack_start.collidepoint(event.pos): print("attack_start was pressed") print(self.damage["atk_hp"], self.damage["def_hp"]) self._finish() if self.command_mind.collidepoint(event.pos): print("command_of_mind was pressed") def displayupdate(self): pygame.display.update() if __name__ == '__main__': atk = {"name":"name", "hit": 400, "avoid": 300, "geo": 1.1, "map_geo": 1.1, "HP": 4500, "EN": 200, "ARMOR": 1450, "MOBILE": 120, "weapon":"w_name", "w_atk": 3500, "w_hit": 30, "w_geo": 1.0, "counter": False } _def = {"name":"name", "hit": 300, "avoid": 300, "geo": 1.1, "map_geo": 1.1, "HP": 4500, "EN": 200, "ARMOR": 1450, "MOBILE": 120, "weapon":"w_name", "w_atk": 3500, "w_hit": 30, "w_geo": 1.0, "counter": True } battle = battle.Battle() result_damage = battle(atk, _def) # {atk_hp, def_hp, atk_hit, def_hit} disp = DisplayWindow(atk, _def, result_damage) disp()
#!/usr/bin/env python3 from intro import intro from choose1 import prebattle from battle import * rival_name = intro() answer = 'y' while (answer == 'y'): chosen_Pokemon = prebattle(rival_name) battle([chosen_Pokemon[0]], rival_name, [chosen_Pokemon[1]]) answer = input("\nWould you like to battle again? ('y' or 'n') ") while (answer != 'n' and answer != 'y'): answer = input("That's not a valid answer. Would you like to battle again? ('y' or 'n') ") print("\nThanks for playing!")
if kills == 1: print("You killed {0} mob.".format(kills)) else: print("You killed {0} mobs.".format(kills)) # Start of Game new_enemy = newEnemy() showIntro(new_enemy) tempCash = int(random.randint(1, 25) + 75) + 200 # Creates New Player # (block, health, maxhealth, defense, kills, biocort, cash, exp, seu, seutotal, weapondmg, weapontype, clips, healtimes, level, nextlevel): # weapontype: 1 = pistol / 2 = rifle new_player = Player(0, 100, 100, 35, 0, 2, tempCash, 0, 3, 10, "laser pistol", 30, 1, 5, 0, 1, 100) battle(new_player, new_enemy) if new_player.health <= 0: endGame(new_player.kills) gameState = 0 else: new_player.kills += 1 new_player.healtimes = 0 gameState = 1 oldInput = "1" # Game Loop while gameState: # After Returning To Main Game Loop, Print Out One Of These if oldInput == "1": print("Dusting yourself off, you decide where to go.")
player.statsRefresh() area1 = area('A',1,area1mobs) area2 = area('B',1,area2mobs) area3 = area('C',1,area3mobs) area4 = area('Home',0,None) areaIndex = [area1, area2, area3, area4] currentArea = area4 print('Welcome to RPG v0.2') while player.alive(): newArea = mainMenu(areaIndex,currentArea) currentArea = newArea print currentArea.name print currentArea.flag if area.checkAreaType(currentArea): mob = currentArea.generateMonster() battle(player,mob) '''starter = raw_input('Where would you like to go?') goto(starter)''' ''' while True: battle(player,poring) poring = monster('Poring',1,[4,4,4,4,4,4],50) '''