def test_create_character(self): expected = { 'name': "Link", 'coords': (0, 0), 'max_hp': 10, 'current_hp': 10, 'power': 6 } self.assertEqual(expected, create_character())
def create_father(world, scenario_state): father = create_character( world, (0, 4.5), "boy_chest", CharacterDirection.RIGHT, 2.5 ) scenario_state["father"] = father
def game(): """Initialaze and handles gameplay """ plot.prologue() start_time = time.time() player = maps.START[:] level = 1 map_ = maps.load_map_for_level(level) character.create_character() health = character.get_stats()["HP"] game_over = False while health > 0 and not game_over: os.system('clear') maps.print_map(map_, level, player) player = functions.player_move(map_, level, player) if functions.is_next_level(level, player): level += 1 map_ = maps.load_map_for_level(level) if inventory.item_in_inventory("Sword of a Thousand Truths"): game_over = True health = character.get_stats()["HP"] game_total_time = int(time.time() - start_time) if health < 0: plot.bye_bye() if health > 0: plot.epilogue() highscore.update_highscore(game_total_time) highscore.print_highscore()
def test_create_character (self): #invalid input assert not create_character(None, "TestCharName") assert not create_character(None, None) assert not create_character("TestUsername", None) #"TestUsername" does not exist, so a character cannot be created for it. assert not create_character("TestUsername", "TestCharname") #"Username" should work. assert create_character("Username", "TestCharName") assert create_character("Username2", "TestCharName")
def create_mother(world, scenario_state): mother = create_character( world, (1, 4), "girl", CharacterDirection.LEFT, 2.5 ) def ghosts(): scenario_state["ghosts"] = True mother.entity.add_component( Frightenable(ghosts) ) scenario_state["mother"] = mother
def test_regular_create_character(self, mock_class_selection, mock_create_name, mock_roll_die): new_character = { "Name": "Dustin", "Class": "Jedi Consular", "HP": 10, "Strength": 8, "Dexterity": 8, "Constitution:": 8, "Intelligence": 8, "Wisdom": 8, "Charisma": 8, "XP": 0, "Inventory": ["Lightsaber - Orange"], "Position": [7, 4] } self.assertEqual(create_character(), new_character)
def test_regular3_create_character(self, mock_class_selection, mock_create_name, mock_roll_die): new_character = { "Name": "Darth Vader", "Class": "Sith Warrior", "HP": 10, "Strength": 15, "Dexterity": 15, "Constitution:": 15, "Intelligence": 15, "Wisdom": 15, "Charisma": 15, "XP": 0, "Inventory": ["Lightsaber - Red"], "Position": [7, 4] } self.assertEqual(create_character(), new_character)
def test_regular5_create_character(self, mock_class_selection, mock_create_name, mock_roll_die, choose_inventory): new_character = { "Name": "Commander Cody", "Class": "Trooper", "HP": 10, "Strength": 18, "Dexterity": 9, "Constitution:": 16, "Intelligence": 15, "Wisdom": 5, "Charisma": 5, "XP": 0, "Inventory": ["Assault Cannon"], "Position": [7, 4] } self.assertEqual(create_character(), new_character)
def test_regular4_create_character(self, mock_class_selection, mock_create_name, mock_roll_die, choose_inventory): new_character = { "Name": "Boba Fett", "Class": "Bounty Hunter", "HP": 10, "Strength": 16, "Dexterity": 14, "Constitution:": 13, "Intelligence": 16, "Wisdom": 14, "Charisma": 16, "XP": 0, "Inventory": ["Sniper Rifle"], "Position": [7, 4] } self.assertEqual(create_character(), new_character)
def test_regular2_create_character(self, mock_class_selection, mock_create_name, mock_roll_die, choose_inventory): new_character = { "Name": "Han Solo", "Class": "Smuggler", "HP": 10, "Strength": 18, "Dexterity": 18, "Constitution:": 18, "Intelligence": 18, "Wisdom": 18, "Charisma": 18, "XP": 0, "Inventory": ["Blaster Pistol"], "Position": [7, 4] } self.assertEqual(create_character(), new_character)
def create_burglar(world, scenario_state): burglar = create_character( world, (1, 4), "burglar_lantern", CharacterDirection.LEFT, 2.5 ) burglar.entity.get_component(Animable).add_animation( FlickerAnimation(6, 0.75) ) burglar.entity.add_component( Lightable( Positionable(-20, 10, 60, 60), Positionable(-70, -40, 160, 160), (205, 155, 29, 64) ) ) scenario_state["burglar"] = burglar
def load_game() -> dict: """ Load a character save file from a json file. POST-CONDITION: Loads a character dictionary from a json file or calls a function to create a new character RETURN: A character as a dictionary Not sure how to doctest or unittest this function """ choice = input('Do you want to start a new game or load? (new,load) ').lower().strip() if choice == 'load': try: name = input("Input your character's name ").title().strip() # Loads file based on character's name filename = name + 'savefile.json' with open(filename) as file_object: my_character = json.load(file_object) return my_character except FileNotFoundError: # If file is not found game does not crash print('We could not find that character in our system') elif choice == 'new': print('Okay we will create a new game for you') return character.create_character() # Uses create_character function to create a new game return load_game() # Recursion if user either does not pick load or new or their file is not found
def new_or_old_character(): """Asks the user if they are a new player (creates new character) or if they have played before (loads a character) POSTCONDITION: a username is returned or None is returned if file does not exist RETURN: A new character or a username saved from a JSON file """ sentinel_value = True while sentinel_value is True: user_input = input( "Are you a new player? Type 'y' for yes and to create a new character," " or 'n' for no to load an old character from file\n") if user_input == 'y': # If user is a new player, create a new character new_character = character.create_character() return new_character elif user_input == 'n': # If user is not a new player, load a previously saved character new_character = get_stored_username() print("Welcome back,", new_character['Name']) return new_character else: print("Please enter y or n")
def test_type_create_character(self, mock_class_selection, mock_create_name, mock_roll_die, choose_inventory): self.assertIsInstance(create_character(), dict)
def Init_manche(): """ G{classtree} DESCRIPTION =========== Initialise chaque manche : placement du joueur, environnement, bonus, ennemies. PARAM ===== Sans parametre RETOUR ====== Sans retour """ #-afaire global manche, menu, player, allAssetGameZone, acutalAssetGameZone, Story, Shadow_background, color asheiyaAsset = [ "Run_Right_0", "Run_Right_45", "Run_Right_90", "Run_Right_-45", "Run_Right_-90", "Run_Left_0", "Run_Left_45", "Run_Left_90", "Run_Left_-45", "Run_Left_-90", "Wait_Right_0", "Wait_Right_45", "Wait_Right_90", "Wait_Right_-45", "Wait_Right_-90", "Wait_Left_0", "Wait_Left_45", "Wait_Left_90", "Wait_Left_-45", "Wait_Left_-90", ] projectileAsset = [ "Gun_Horizontal", "Gun_Slach", "Gun_UnSlash", "Gun_Vertical" ] if manche == 10: Shadow_background = hitbox.Create_ShadowBackgrond(1) acutalAssetGameZone = allAssetGameZone[ "Zone_" + str(allAssetGameZone["NumZone"])] #on concoit le joueur___________________________________________________________________________________________________________________________ assetPlayer = {} assetPlayer["position"] = [ "Wait", "Right", 0 ] #correspond a sa representation : course/attente, orientation, position du bras for Asheiya_doc in asheiyaAsset: assetPlayer[Asheiya_doc] = entity.create_asset("Asheiya/Asset/" + Asheiya_doc + ".txt") assetPlayer["Actual"] = assetPlayer[assetPlayer["position"][0] + "_" + assetPlayer["position"][1] + "_" + str(assetPlayer["position"][2])] xPlayer = 0 yPlayer = 0 vxPlayer = 0 vyPlayer = 0 player = entity.create_entity("Asheiya Briceval", xPlayer, yPlayer, assetPlayer, color["txt"]["Yellow"]) speedPlayer = 0.1 #deplaxcement pas seconde player = movingent.create_moving_ent(player, vxPlayer, vyPlayer, speedPlayer) lifePlayer = 18 armorPlayer = 25 player = livingent.create_living_ent(player, lifePlayer, armorPlayer) assetShot = {} for Shot_doc in [ "Gun_Horizontal", "Gun_Slash", "Gun_UnSlash", "Gun_Vertical" ]: assetShot[Shot_doc] = entity.create_asset("Asheiya/Projectile/" + Shot_doc + ".txt") damage = 5 shotDelay = 3 bulletSpeed = 0.04 colorBullet = color["txt"]["Red"] player = shootingent.create_shooting_ent(player, damage, bulletSpeed, assetShot, shotDelay, colorBullet) spowerSpeed = 1 #toutes les secondes on augmente de 1 la charge du super spowerMax = 100 #au bout de 100 charges on peut utiliser l'ultime player = character.create_character(player, spowerSpeed, spowerMax) allEntity.append(player) player = movingent.tp_entity(player, 20, 37) #placement des bonus : #-afair quand on les placera tous, automatiser le tout listeBonus = {"speedUp": 0.02, "fireRateUp": 1, "lifeUp": 5} xbonus = 9 ybonus = 33 assetBonus = {} assetBonus["boon1"] = entity.create_asset( "Boon/boon1.txt") #-afair en sorte que les accès soient automatisé assetBonus["Actual"] = assetBonus["boon1"] boon1 = entity.create_entity( "boon1", xbonus, ybonus, assetBonus, color["txt"] ["Green"]) #-afair en sorte que leurs noms s'incrémente tout seul boon1 = boon.create_boon(boon1, listeBonus) allEntity.append(boon1) listeBonus = {"lifeUp": 5, "armorMaxUp": 2} xbonus = 9 ybonus = 27 assetBonus = {} assetBonus["boonGenerator"] = entity.create_asset( "Boon/boonGenerator.txt") assetBonus["Actual"] = assetBonus["boonGenerator"] geneSpeed = 2 boong = entity.create_entity("boong1", xbonus, ybonus, assetBonus, color["txt"]["Cyan"]) boong = boon.create_boon_generator(boong, listeBonus, geneSpeed) allEntity.append(boong) assetCristal = {} assetCristal["Cristal"] = entity.create_asset("Mobs/Cristal.txt") assetCristal["Actual"] = assetCristal["Cristal"] Cristal_1 = {} Cristal_1 = entity.create_entity( "Cristal_1", 42, 24, assetCristal, color["txt"]["Pink"]) #position x=42,y=24 Cristal_1 = livingent.create_living_ent( Cristal_1, 9, 0) #9 point de vie, 0 point d'armure allEntity.append(Cristal_1) Cristal_2 = {} Cristal_2 = entity.create_entity( "Cristal_1", 73, 36, assetCristal, color["txt"]["Red"]) #position x=73,y=37 Cristal_1 = livingent.create_living_ent( Cristal_2, 12, 0) #12 point de vie, 0 point d'armure allEntity.append(Cristal_2) #Story storyFile = "Story/Zone_1.txt" maxLigne = 35 LastTime = time.time() Story = windows.create_story(storyFile, maxLigne, LastTime) # manche initialisé manche = 11 if manche == 20: #initialiser la deuxieme manche manche = 21 return