def main(): ''' INPUT: none USAGE: runs the game OUTPUT: whatever the game dictates ''' # First, get user name to generate the user's character, then print stats print('What is your name?') player1 = Character(user_input()) gen_stats(player1) player1.moves = move_list print('Here are your stats:') print_stats(player1) # Generate first opponent and stats foe1 = Character('Felix') gen_stats(foe1) foe1.moves = move_list print('*****************************\n' + "Here are your opponent's stats") print_stats(foe1) start_battle = False while not start_battle: init_input = input("Ready to battle? (y)es or (n)o >>> ") if init_input == "y": break battle_sequence(player1, foe1) if player1.hp == 0: print("You got knocked the F*** Out!") else: print("You knocked out {}!".format(foe1.name)) print("Thank you for playing!")
def execute(self, data): try: self.name = data.getString() self.factionId = data.getInt32() print "new challenger" ralph = Actor("models/ralph", { "run": "models/ralph-run", "walk": "models/ralph-walk" }) ralph.reparentTo(render) ralph.setScale(.2) ralph.setPos(main.ralphStartPos) if main.name == self.name: main.character = Character(self.name, ralph, self.factionId) main.base.camera.setPos(main.character.actor.getX(), main.character.actor.getY() + 10, 2) # Try this out main.characters[self.name] = main.character else: main.characters[self.name] = Character(self.name, ralph, self.factionId) main.taskMgr.add(self.main.move, "moveTask") #main.taskMgr.doMethodLater(1, self.main.CPHandler, "CPHandlerTask") #self.log('Received [' + str(Constants.RAND_INT) + '] Int Response') except: self.log('Bad [' + str(Constants.RAND_INT) + '] Int Response') print_exc()
def setUp(self): sword = Weapon('Spartan Sword', 1, 20) bow = Weapon('Long Bow', 5, 60) self.leonidas = Character('King Leonidas', 10, sword, 200) self.legolas = Character('Elf Legolas', 5, bow, 100, 4) self.hulk = Character('Incredible Hulk', 100, None, 800, 2)
def main(): player = Character(input('What is your name, slave?\n'), 15) orc = Character('Foul orc') troll = Character('Fetid troll') knight = Character( 'Knight', 10, 5, 1, None, Equipment(Weapon('Sword', '1hsw', 2), Armor('Shiny armor', 1))) arena = Arena() fight = FightManager(arena, [player, orc, troll, knight], player) print('You enter the arena.') print(knight.equipment.weapon) wageFight(fight) corpses = fight.arena.corpses if fight.hasPlayer(): print('You survived another fight.') #Loot and continue lootCorpses(player, corpses) elif len(fight.arena.fighters) > 0: winner = fight.arena.fighters.pop(0) print('%s won the fight !' % winner.name) else: print( 'Draw ! All fighters lost their lives, the crowd cheers to revive the most brutal.' ) #Continue if fought best print(player) print(player.inventory.items) print('End.')
def battleEngineTest(): # Battle Engine Object be = BattleEngine() # Create opponents for battle player1 = Character("Player1", "Welsh", "Mesmer", 100, 100) player2 = Character("Player2", "Scottish", "Elementalist", 100, 100) # Test Battle Status and Friendly Status player1.setBattleStatus(False) player1.setFriendlyStatus(True) print(" Player 1's Status is " + (str(player1.getBattleStatus())) + " " + (str(player1.getFriendlyStatus()))) opponents = [] opponents.append(player1) opponents.append(player2) # Print Character Info for battle print(opponents[0].charactername) print(opponents[1].charactername) print(opponents) be.engineTest(opponents)
def test_gets_correct_id(self): expected_1 = 1 expected_2 = 2 sut_1 = Character(char_id=expected_1) sut_2 = Character(char_id=expected_2) self.assertEqual(expected_1, sut_1.char_id) self.assertEqual(expected_2, sut_2.char_id)
def test_CharacterGainsTenExperienceOnSuccessful(self): testCharacter1 = Character() testCharacter2 = Character() roll = testCharacter2.armor + 1 attack = Attack(testCharacter1, testCharacter2, roll) attack.attemptAttack() self.assertEqual(10, testCharacter1.experiencePoints)
def test_MinDmgAlwaysOne(self): testCharacter1 = Character() testCharacter2 = Character() testCharacter1.strength = 1 roll = 20 attack = Attack(testCharacter1, testCharacter2, roll) attack.attemptAttack() self.assertEqual(4, testCharacter2.hitPoints)
def test_ifRollIs20CriticalHitDoubleDamage(self): testCharacter1 = Character() testCharacter2 = Character() roll = 20 attack = Attack(testCharacter1, testCharacter2, roll) attack.attemptAttack() self.assertEqual(3, testCharacter2.hitPoints)
def test_ifTargetCharacterHitTakesOneDamage(self): testCharacter1 = Character() testCharacter2 = Character() roll = testCharacter2.armor attack = Attack(testCharacter1, testCharacter2, roll) attack.attemptAttack() self.assertEqual(4, testCharacter2.hitPoints)
def main(): ITEMS_PER_PLAYER = 0 existed = True new = False level = 1 while (True): print() main, existed = safe_load("Main", existed, new, level=level) viic14, existed = safe_load("Buddy", existed, new, level=level) for _ in range(ITEMS_PER_PLAYER): main.add_item(Item(main)) viic14.add_item(Spell(viic14)) if (existed): break if (not 'n' in input("Press enter to start \n")): break menu = {'1': "Fight", '2': "Show player stats", '0': "Quit"} menu_funct = { '1': lambda: Combat({ 'Bona gent': [main, viic14], "Mala gent": [ Character("Enemy1", main.level - randint(0, 1)), Character("Enemy2", viic14.level - randint(0, 1)) ] }).start(), '2': lambda: print(f"{main._item_stats}\n\n{viic14._item_stats}"), '0': lambda: 0 } pstr = '\n\t'.join([f"[{num}] {desc}" for num, desc in menu.items()]) del menu try: move = input(f"Menu: \n\t{pstr}\n> ") while (move != '0'): menu_funct.get( move, lambda: print("Invalid opion. Please choose another one"))() move = input(f"\nMenu: \n\t{pstr}\n> ") except KeyboardInterrupt: if ('n' in input("\nSave anyway? [y] ").lower()): exit(0) print() main.save() viic14.save()
def test_CharacterLevelsAfter1000ExperiencePoints(self): testCharacter1 = Character() testCharacter2 = Character() testCharacter1.experiencePoints = 990 roll = testCharacter2.armor attack = Attack(testCharacter1, testCharacter2, roll) attack.attemptAttack() self.assertEqual(testCharacter1.level, 2)
def setUp(self): sword = Weapon('Spartan Sword', 1, 20) bow = Weapon('Long Bow', 5, 60) self.leonidas = Character('King Leonidas', 10, sword, 200) self.legolas = Character('Elf Legolas', 5, bow, 100, 4) self.hulk = Character('Incredible Hulk', 100, None, 800, 2) self.arena = Battleground('Thunderdome', 20, 20) self.battle = Battle(self.arena)
def test_StrModIsAppliedToAttack(self): testCharacter1 = Character() testCharacter2 = Character() testCharacter1.strength = 12 roll = testCharacter2.armor - 1 attack = Attack(testCharacter1, testCharacter2, roll) attack.attemptAttack() self.assertEqual(3, testCharacter2.hitPoints)
def test_DeadCharacterCannotBeAttacked(self): testCharacter1 = Character() testCharacter2 = Character() testCharacter2.isAlive = False testCharacter2.hitPoints = 0 roll = testCharacter2.armor attack = Attack(testCharacter1, testCharacter2, roll) attack.attemptAttack() self.assertEqual(0, testCharacter2.hitPoints)
def test_ifTargetCharacterHP0OrLessTargetIsDead(self): testCharacter1 = Character() testCharacter2 = Character() testCharacter2.hitPoints = 1 roll = testCharacter2.armor attack = Attack(testCharacter1, testCharacter2, roll) attack.attemptAttack() testCharacter2.checkLivingStatus() self.assertFalse(testCharacter2.isAlive)
def test_CharacterOnlyLevelsEvery1000ExperiencePoints(self): testCharacter1 = Character() testCharacter2 = Character() testCharacter1.experiencePoints = 1001 testCharacter1.level = 2 roll = testCharacter2.armor attack = Attack(testCharacter1, testCharacter2, roll) attack.attemptAttack() self.assertEqual(testCharacter1.level, 2)
def test_StrModIsDoubleOnCritHit(self): testCharacter1 = Character() testCharacter2 = Character() testCharacter1.strength = 12 testCharacter2.hitPoints = 6 roll = 20 attack = Attack(testCharacter1, testCharacter2, roll) attack.attemptAttack() testCharacter2.checkLivingStatus() self.assertFalse(testCharacter2.isAlive)
def test_RollModifierOnEvenLevel(self): testCharacter1 = Character() testCharacter2 = Character() testCharacter1.experiencePoints = 2000 testCharacter1.levelUp() testCharacter1.levelUp() roll = 1 modifiedRoll = Roll(testCharacter1, testCharacter2, roll) modifiedRoll.modifyRoll() self.assertEqual(2, modifiedRoll.modifiedRoll)
def dict2Character(d): if (d == "Empty"): return None name = d["Name"] style = d["Style"] weapon = d["Weapon"]["Name"] weaponbonus = (d["Weapon"]["Health"], d["Weapon"]["Attack"], d["Weapon"]["Defense"], d["Weapon"]["Speed"], d["Weapon"]["Type"]) maxhealth = d["MaxHealth"] health = d["Health"] attack = d["Attack"] defense = d["Defense"] speed = d["Speed"] exp = d["Experience"] money = d["Money"] stash = d["Stash"] loc = [d["location"][0], d["location"][1], d["location"][2]] character = Character(Name=name, Style=style, Weapon=weapon, WeaponBonus=weaponbonus, Health=health, Attack=attack, Defense=defense, Speed=speed, Money=money, Stash=stash, location=loc, Experience=exp) character.MaxHealth = maxhealth return character
def run_game(self): ''' This method implements a single game frame. It will work depends on ''' if self.__current_game_state is GAME_MENU: try: if self.__game_start_mode is LOAD_GAME: player_position, dungeon_map = DungeonGameSaveLoad.load_game() self.__dungeon_map.init_from_load(player_position, dungeon_map) else: map_size = int(input('Map size (>= 5): ')) self.__dungeon_map.generate_new_map(map_size) except NoSavedDataFileError as error: logging.error(f'User have chosen to load the game but we can\'t find game save data on address:\ {error}.') logging.info('Sorry, but there is no game save data. Please, save the game firstly or find the\ save data file.') self.process_game_start() else: self.__character = Character('User', DungeonGameConfig.PLAYER_HP, self.__dungeon_map) self.__current_game_state = GAMEPLAY self.__update_list.add_children(self.__dungeon_map, self.__character) elif self.__current_game_state is GAMEPLAY: logging.info(f'Current character stats: hp - {self.__character.get_hp()}, num of treasures - \ {self.__character.get_treasures_number()}') self.__update_list.update()
def main(): char = Character('Name') choose_race(char) choose_subrace(char) roll_dice(char) choose_class(char) pprint(char.__dict__)
def main(): # the way I'm creating messages here is still inefficient # just for testing purposes # update: created a function print_out for text printing print_out("Hello Adventurer! Your Journey starts here\n") print_out("What would your name be?\n", 0.2) name = str(input()) character_1 = Character(100, name) character_1.damage(45) time.sleep(0.5) character_1.heal(1000) time.sleep(0.5) character_1.damage(45) time.sleep(0.5) character_1.damage(45) time.sleep(0.5) character_1.damage(45) time.sleep(0.5)
def next_stage(self): self.ship = Animation(frames_path['ship'], ((self.w/16)*14, 200), self.screen) self.ship.reduce_scale(4) self.ship.centralize() self.sound_queue.append(sounds['stage']) self.played_sections += 1 self.last_dig = None self.curr_dig = None self.show_item = False self.stage_done = False self.treasure_found = False self.stage_begin = True self.block_index = 0 self.stage_map = Map(3 + self.played_sections, self.screen, self.w, self.h) self.char = Character(self.screen, Gameplay.char_sex, self.stage_map.blocks[self.block_index]) self.char.reduce_scale(4) self.char.centralize() self.elements = [self.bg, self.stage_map, self.ship, self.char]
def loadCharacters(filePath): try: characters = [] attributes = [] names = [] data = validateJSON(filePath) for (k,v) in data.items(): for character in v: properties = [] for feature in character['features']: for key,value in feature.items(): for values,v in value.items(): properties += [[key,values,v]] if not (key in attributes): attributes += [key] state = True names += [character['name']] person = Character( character['name'], character['imgUrl'], properties, state ) characters += [person] return characters,attributes,names except ValueError as error: return "Error, wrong JSON"
def populate(self, squadtype): st = self.squad_type = SquadTypeHandler.load(squadtype) self.squad_type_name = st.name self.leader_rank = st.leader_rank self.devotion = choice(CharInfo.devotions) self.loyalty = choice(CharInfo.loyalties) if st.choice != "False": options = st.choice.split("/") winner = choice(options) for group in options: for key in group.split("&"): if key not in winner: st.squadroles[key] = 0 for role, amount in st.squadroles.items(): for _ in range(int(amount)): context = { "legion": self.legion, "company": self.company, "role": SquadRole.load(role.title()), "squad": self } char = Character(**context) char.generate_fill() self.members.append(char) if len(self.members) == st.size: break
def dict2Character(d): name = d["Name"] style = d["Style"] weapon = d["Weapon"]["Name"] weaponbonus = (d["Weapon"]["Health"], d["Weapon"]["Attack"], d["Weapon"]["Defense"], d["Weapon"]["Speed"], d["Weapon"]["Type"]) maxhealth = d["MaxHealth"] health = d["Health"] attack = d["Attack"] defense = d["Defense"] speed = d["Speed"] money = d["Money"] stash = d["Stash"] character = Character(Name=name, Style=style, Weapon=weapon, WeaponBonus=weaponbonus, Health=health, Attack=attack, Defense=defense, Speed=speed, Money=money, Stash=stash) character.MaxHealth = maxhealth return character
def test_ConstModIsAppliedToHitPoints(self): testCharacter1 = Character() testCharacter1.constitution = 12 testCharacter1.updateHitPoints( testCharacter1.getConstitutionModifier()) self.assertEqual(6, testCharacter1.hitPoints)
def createCharacter(): troy = Character("Troy", "Welsh", "Mesmer", 100, 100) troy.showDetails() # createa single item troysweapon = Item("Staff Of Ice", "Staff", 3, 4) troystunic = Item("Tunic Of Ice", "Armor", 10, 10) # add item to backpack dict troy.characterbackpack.addItemToBackpack(Backpack, troysweapon) troy.characterbackpack.addItemToBackpack(Backpack, troystunic) # get the entire Item Object by Item Class Name newweapon = troy.characterbackpack.getItemFromBackpack( Backpack, troysweapon) print("This is the name of my new item") print(newweapon.itemname) # get the entire Item Object by Item Class Name newarmor = troy.characterbackpack.getItemFromBackpack(Backpack, troystunic) print("This is the name of my new item") print(newarmor.itemname) # get the entire object by Dict index - a string value newitem = troy.characterbackpack.findItemInBackpack( Backpack, "Tunic Of Ice") print(newitem.itemname) print(newitem.itemsize)
def test_character(name): toon = Character(name) toon.gen.str_pts = 5 toon.gen.dex_pts = 21 toon.gen.con_pts = 6 toon.gen.pre_pts = 3 toon.gen.spd_pts = 3 toon.skills.append(SkillBase.get_language("Flooboobian", 3)) toon.skills.append(SkillBase.get_culture("Flooboobian", 2)) toon.skills.append(SkillBase.get_area_knowledge("Flooboobia", 1)) toon.skills.append(SkillBase.get_skill("Acrobatics", 3)) toon.skills.append(SkillBase.get_skill("Riding", 5)) toon.skills.append(SkillBase.get_skill("Teamwork", 3)) toon.skills.append(SkillBase.get_skill("Running", 0)) toon.skills.append(SkillBase.get_skill("Swimming", 1)) toon.skills.append(SkillBase.get_skill("Tactics", 3)) toon.skills.append(SkillBase.get_skill("Tracking", 3)) toon.skills.append(SkillBase.get_skill("Survival", 3)) toon.skills.append(SkillBase.get_skill("AnimalHandler", 3)) toon.skills.append(SkillBase.get_melee_weapon("Sword", 6)) toon.skills.append(SkillBase.get_ranged_weapon("Bow", 12)) toon.skills.append(SkillBase.get_profession("Ranger", 2)) toon.skills.append(SkillBase.get_profession("Bowyer", 1)) toon.skills.append(SkillBase.get_extreme_env("Tundra", 2)) toon.skills.append(SkillBase.get_beast("Horse", 2)) toon.skills.append(SkillBase.get_beast("Hound", 2)) toon.skills.append(SkillBase.get_beast("Hawk", 1)) toon.recalc() print(toon) print(toon.roll("MW:Sword")) print(toon.roll("Tactics"))