Exemple #1
0
def charcount(s):
    result = {}
    # your code here - converting a string to list of character is easy. You just call list(s). You then need to
    # call the count_list function in the util module.
    from util import count_list
    result = count_list(s)
    return result
Exemple #2
0
def wordcount_file(fname_with_path):
    s = ""
    # your code for read the content of files - in our class we talked about how to read file line by line. Here you can
    # just call f.read() to read file content as a string.
    f = open(fname_with_path,"r")
    s = f.read()
    words = tokenize(s) # call the tokenize method you just implemented
    lower_case(words) # call the lower_case method you just implemented
    dc =  util.count_list(words) # here you need to call the count_list function you implemented in util.py for task 4
    return dc
def wordcount_file(fname_with_path):
    s = ""
    # your code for read the content of files - in our class we talked about how to read file line by line. Here you can
    # just call f.read() to read file content as a string.
    file = open(fname_with_path)
    s = file.read()
    words = tokenize(s) # call the tokenize method you just implemented
    lower_case(words) # call the lower_case method you just implemented
    dc = util.count_list(words) # here you need to call the count_list function you implemented in util.py for task 4
    return dc
Exemple #4
0
def king(player):
	util.clear()
	if player['bad_points'] > 5:
		k("Why have you come here? I know your evil deeds!")
		t = choice('Kill him', "Tell him you are sorry for the bad things you did")
		if t == '1':
			s_print("You draw your " + player['main_weapon'])
			k("So it is treason then?")
			battle.king_fight()
		else:
			k("If you truly wish to be pardoned, you can, but you will have to pay for your crimes!")
			k("Guards, lock him in the dungeon until he has paid for his crimes!")
			util.sentence(player['bad_points'] * 3)
	
	elif player['mission1'] == False and util.count_list(player['monster_parts'], 'Kraveb Head') >= 3:
		player['mission1'] = True
		player['weapons'].append("Ice Pick")
		k("You have completed your quest! Very good, here is an Ice Pick!")
		k("It is a deadly weapon at close range against enemies, weild it with skill and you will be very strong in battle")
		player['gold'] += 25
		k("Also, here is 25 gold coins for finishing the task so fast")
		k("And now I have another mission for you!")
		time.sleep(1)
		util.clear()
		k("A fiend roams my lands, his name is Maximus the III")
		k("He claims he is the heir to this throne, although he is not, and attemps to stir the commonfolk up")
		k("I would allow you to hunt him but you have not proven yourself yet")
		k("Find and kill a Thorg, and you will be strong enough to battle him!")
	elif player['mission1'] != True:
		k("You, warrior! You seem to be strong, I have a quest for you!")
		k("Monsters plague my lands, and if you bring me the head of three kraveb, I will grant you a special weapon!")
	elif player['mission1'] == True and player['mission2'] != True and 'Thorg' in player['kills']:
		k("You are a strong warrior, for you have defeated a thorg!")
		k("Now I know you are strong enough to battle Maximus himself!")
		k("For now he is banished to the realm of monsters, here is a key to that land, but beware, it is a very dangerous place to be!")
		player['unlocked_locations'].append("Monster Lands")
		s_print("You have unlocked a new location: Monster Lands")
		player['mission2'] = True
		database.save(player)
	elif player['mission3'] == False:
		k("Go to the monsterlands, and defeat Maximus the III")
	elif player['mission3'] == True:
		k("You have defeated Maximus the III? You are more powerful then I first thought")
		k("You are very powerful, powerful enough to travel to dangerous lands")
		s_print("You unlocked a new location: Far Place")
		player['unlocked_locations'].append('Far Place')
		database.save(player)
	input()
Exemple #5
0
def print_user():
    global player
    while True:
        util.clear()
        database.save(player)
        ### STRINGIGY BELOW
        print(Style.RESET_ALL + GREEN + BOLD + UNDERLINE + 'CURRENT RIG')
        print(Style.RESET_ALL + Fore.GREEN + 'LIFE ' + str(player['life']))
        print("CARRYING WEIGHT: " + str(player['current_weight']))
        print("MAIN WEAPON: " + player['main_weapon'] + ' | MIN DAMAGE: ' +
              str(player['main_weapon_min']) + ' | MAX DAMAGE: ' +
              str(player['main_weapon_max']) + ' | AMMO: ' +
              str(player['main_weapon_ammo']))
        print("SHIELD: " + player['shield'] + ' | DEFENSE: ' +
              str(player['shield_defense']))
        print("ARMOR: " + player['armor'] + ' | MIN DEFENSE: ' +
              str(player['armor_min']) + ' | MAX DEFENSE: ' +
              str(player['armor_max']))
        print("[1] Equip weapons/armor/shields")
        print("[2] Unequip All")
        print("[3] View Kills")
        print("[4] View Monsterparts")
        print("[5] Inventory overview")
        print(
            "[6] Clean Inventory [Removes duplicates of weapons/shields/armor]"
        )
        print('[7] Exit')
        i = input()
        if i == '1':
            print("[1] Equip Weapons")
            print("[2] Equip Shields")
            print("[3] Equip Armor")
            b = input()
            if b == '1':
                ###### EQUIP WEAPONS ########
                count = 0
                print(Style.RESET_ALL + Back.BLUE + "  WEAPONS  " +
                      Style.RESET_ALL)
                for weapon in player['weapons']:
                    print(Style.RESET_ALL + Fore.GREEN + '[' + str(count) +
                          ']  ' + weapon + ' | DAMAGE: ' +
                          str(util.get_stat_max(weapon)) + ' | WEIGHT: ' +
                          str(util.get_weight(weapon)))
                    count += 1
                choice = input()
                try:
                    new_weapon = player['weapons'][int(choice)]
                    if player['current_weight'] + util.get_weight(
                            new_weapon
                    ) > player[
                            'carry_ability']:  #checks if player is carrying too much weight
                        print("You are carrying too much weight!")

                    else:
                        player['main_weapon'] = new_weapon
                        player['main_weapon_min'] = util.get_stat_min(
                            player['main_weapon'])
                        player['main_weapon_max'] = util.get_stat_max(
                            player['main_weapon'])
                        player['current_weight'] += util.get_weight(new_weapon)
                        player['ammo'] = util.get_ammo(player, new_weapon)
                except:
                    print("Not an option!")
            elif b == '2':
                ######## EQUIP SHIELDS #########
                count = 0
                print(Style.RESET_ALL + Back.BLUE + "  SHIELDS  " +
                      Style.RESET_ALL)
                for shield in player['shields']:
                    print(Style.RESET_ALL + Fore.GREEN + '[' + str(count) +
                          ']  ' + shield + ' | DEFENSE: ' +
                          str(util.get_shield_stat_max(shield)) +
                          ' | WEIGHT: ' + str(util.get_weight(shield)))
                    count += 1
                choice = input()
                try:
                    new_shield = player['shields'][int(choice)]
                    if player['current_weight'] + util.get_weight(
                            new_shield) > player['carry_ability']:
                        print("You are carrying too much weight!")
                    else:
                        player['shield'] = new_shield
                        player['shield_defense'] = util.get_shield_stat_max(
                            new_shield)
                        player['current_weight'] += util.get_weight(new_shield)
                except:
                    print("Error! Unable to equip item!")
            elif b == '3':
                ######## EQUIP ARMOR ########
                count = 0
                print(Style.RESET_ALL + Back.BLUE + '  ARMOR  ' +
                      Style.RESET_ALL)
                for armor in player['armors']:
                    print(Style.RESET_ALL + Fore.GREEN + '[' + str(count) +
                          ']  ' + armor + ' | MIN DEFENSE: ' +
                          str(util.get_armor_stat_min(armor)) +
                          ' | MAX DEFENSE: ' +
                          str(util.get_armor_stat_max(armor)) + ' | WEIGHT: ' +
                          str(util.get_weight(armor)))
                    count += 1
                choice = input()
                try:
                    new_armor = player['armors'][int(choice)]
                    if player['current_weight'] + util.get_weight(
                            new_armor) > player['carry_ability']:
                        print("You cannot carry that much weight")
                    else:
                        player['armor'] = new_armor
                        player['armor_min'] = util.get_armor_stat_min(
                            new_armor)
                        player['armor_max'] = util.get_armor_stat_max(
                            new_armor)
                        player['current_weight'] += util.get_weight(new_armor)
                except:
                    print("Error! Could not equip item!")
            else:
                print("Not a choice!")
            input()
        elif i == '2':
            player['main_weapon'] = 'Fist'
            player['main_weapon_min'] = 1
            player['main_weapon_max'] = 1
            player['shield'] = 'None'
            player['shield_defense'] = 0
            player['armor'] = 'Skin'
            player['armor_min'] = 1
            player['armor_max'] = 1
            player['current_weight'] = 0
            print("All items unequped!")
            input()
        elif i == '3':
            print(Style.RESET_ALL + UNDERLINE + BOLD + Fore.BLUE +
                  '  KILLS  ' + Style.RESET_ALL)
            for kill in player['kills']:
                print(Fore.GREEN + '  -  ' + kill)
            input()
        elif i == '4':
            print(Style.RESET_ALL + UNDERLINE + BOLD + Fore.BLUE +
                  '  MONSTER PARTS  ' + Style.RESET_ALL)
            for part in player['monster_parts']:
                print(Fore.GREEN + '  -  ' + part)
            input()
        elif i == '7':
            break
        elif i == '5':
            print(GREEN + BOLD + UNDERLINE + '         ~ STATS ~         ' +
                  Style.RESET_ALL)
            print(Style.RESET_ALL + Fore.GREEN + 'LIFE ' + str(player['life']))
            print("You are currently: " + util.get_good_bad(player))
            print("CARRYING WEIGHT: " + str(player['current_weight']))
            print("MAIN WEAPON: " + player['main_weapon'] + ' | MIN DAMAGE: ' +
                  str(player['main_weapon_min']) + ' | MAX DAMAGE: ' +
                  str(player['main_weapon_max']) + ' | AMMO: ' +
                  str(player['main_weapon_ammo']))
            print("SHIELD: " + player['shield'] + ' | DEFENSE: ' +
                  str(player['shield_defense']))
            print("ARMOR: " + player['armor'] + ' | MIN DEFENSE: ' +
                  str(player['armor_min']) + ' | MAX DEFENSE: ' +
                  str(player['armor_max']))
            print(GREEN + BOLD + UNDERLINE + '     ~ ALL INVENTORY ~     ')
            print(Style.RESET_ALL + CYAN + BOLD + '  WEAPONS  ' +
                  Style.RESET_ALL)
            for weapon in player['weapons']:
                print(Fore.BLUE + weapon)
            print(Style.RESET_ALL + CYAN + BOLD + '  SHIELDS  ' +
                  Style.RESET_ALL)
            for shield in player['shields']:
                print(Fore.BLUE + shield)
            print(Style.RESET_ALL + CYAN + BOLD + '  ARMOR  ' +
                  Style.RESET_ALL)
            for a in player['armors']:
                print(Fore.BLUE + a)
            print(Style.RESET_ALL + CYAN + BOLD + '  KILLS  ' +
                  Style.RESET_ALL)
            print("Goblin: " + str(util.count_list(player['kills'], 'Goblin')))
            print("Orc: " + str(util.count_list(player['kills'], 'Orc')))
            print("Troll: " + str(util.count_list(player['kills'], 'Troll')))
            print("Kraveb: " + str(util.count_list(player['kills'], 'kraveb')))
            print("Thorg: " + str(util.count_list(player['kills'], 'thorg')))
            for k in player['kills']:
                if k not in ('kraveb', 'Goblin', 'Orc', 'thorg', 'Troll'):
                    print(Fore.BLUE + k)
            print(Style.RESET_ALL + CYAN + BOLD + '  MONSTER PARTS  ' +
                  Style.RESET_ALL)
            for part in player['monster_parts']:
                print(Fore.BLUE + part)
            print(Style.RESET_ALL + CYAN + BOLD + '  MISSIONS  ' +
                  Style.RESET_ALL)
            print(Fore.BLUE + "Mission 1: " + str(player['mission1']))
            print("Mission 2: " + str(player['mission2']))
            print("Mission 3: " + str(player['mission3']))
            print("Mission 4: " + str(player['mission4']))
            print("Mission 5: " + str(player['mission5']))
            print("Mission 6: " + str(player['mission6']))
            print("Mission 7: " + str(player['mission7']))
            print("Mission 8: " + str(player['mission8']))
            print("Mission 9: " + str(player['mission9']))
            print("Mission 10: " + str(player['mission10']))
            print("Mission 11 (Optional): " + str(player['mission11']))
            print("Mission 12 (Optional): " + str(player['mission12']))
            print("Mission 13 (Optional): " + str(player['mission13']))
            print("Mission 14 (Optional): " + str(player['mission14']))
            print("Mission 15 (Optional): " + str(player['mission15']))
            print("Mission 16 (Optional): " + str(player['mission16']))
            print(Style.RESET_ALL + CYAN + BOLD + '  SKILLS  ' +
                  Style.RESET_ALL)
            print(Fore.BLUE + 'SKILL ONE: ' + player['specialty1'] +
                  ' | LEVEL: ' + str(player['specialty1_level']))
            print('SKILL TWO: ' + player['specialty2'] + ' | LEVEL: ' +
                  str(player['specialty2_level']))
            input()
        elif i == '6':
            player = util.clean(player)