Ejemplo n.º 1
0
    def attack(self):
        clear()
        rdm_int = random.randint(1, self.weapon.accuracy)

        #Enemy missed its attack
        if rdm_int == 1:
            rdm_int = random.randint(1, 2)
            if rdm_int == 1:
                print(
                    f"{Colours.fg.cyan}You dodged {self.name_string}{Colours.fg.cyan}'s attack."
                )
            else:
                print(
                    f"{self.name_string}{Colours.fg.cyan} missed it's attack.")

        #Enemy hit attack
        else:
            damage_range = self.weapon.damage
            raw_damage = random.randint(damage_range[0], damage_range[1])

            damage_dealt = new_player.take_damage(raw_damage)

            print(
                f"{self.name_string + Colours.fg.cyan} attacked you, and dealt{Colours.fg.orange} {damage_dealt} damage{Colours.fg.cyan}."
            )

        sleep_and_clear(1.5)
Ejemplo n.º 2
0
  def create_account(cls):
    chosen_username, chosen_password, confirmed_password = None, None, None
    
    cls.get_accounts()
    clear()
      
    chosen_username = input(f"{Colours.fg.orange}Username: "******"{Colours.fg.red}Password: "******"{Colours.fg.red}Confirm Password: "******"{Colours.fg.red}An account with the username '{chosen_username}' and password '{chosen_password}' already exists. Please Login.")
      sleep_and_clear(2)
        
    elif chosen_password != confirmed_password:
      clear()
      print(f"{Colours.fg.red}Your password '{chosen_password}' doesn't match your confirmed password '{confirmed_password}'. Please try again.")
      sleep_and_clear(2)
   
   
    if not (chosen_username, chosen_password) in cls.accounts_dict and chosen_password == confirmed_password:
      cls.logged_in = True
      cls.account = (chosen_username, chosen_password)
      cls.save_account()
Ejemplo n.º 3
0
  def choose_enemy(enemy_chosen):
    if enemy_chosen == None:
      rdm_int = random.randint(1, 200)

      #filters
      enemies_filtered_by_location = list(filter(lambda x: entities.new_player.current_location in entities.all_enemies[x].spawn_location, entities.all_enemies))

      specific_enemy = list(filter(lambda x: rdm_int in entities.all_enemies[x].spawn_range, enemies_filtered_by_location))
  
      
      if len(specific_enemy) > 1:
        artifact_needed = list(filter(lambda x: x.location is entities.new_player.current_location, all_artifacts))[0]

        if artifact_needed in entities.new_player.artifacts_collected:
          specific_enemy.pop()
        else:
          specific_enemy.pop(0)

      enemy_chosen = specific_enemy[0]

    
    try:  
      entities.new_player.current_enemy = entities.all_enemies[enemy_chosen]
    except KeyError:
      entities.new_player.current_enemy = enemy_chosen


    clear()
    print(f"{Colours.fg.cyan}You encountered {entities.new_player.current_enemy.name_string}{Colours.fg.cyan}.")
    sleep_and_clear(1)
Ejemplo n.º 4
0
    def equip(self, equipment_to_equip):
        if equipment_to_equip.category == "weapon":
            self.weapon = equipment_to_equip

        elif equipment_to_equip.category == "armour":
            self.armour = equipment_to_equip

        clear()
        print(
            f"{Colours.fg.orange}You equipped {equipment_to_equip.name_string}{Colours.fg.orange}."
        )
        sleep_and_clear(1)
Ejemplo n.º 5
0
  def update_items_used(cls):
    for item_name in entities.new_player.items_used:
      turns_left = entities.new_player.items_used[item_name]

      if turns_left > 0:
        if turns_left == 1:
          clear()
          print(f"{System.get_object(item_name, objects.all_items).name_string}{Colours.fg.orange}'s effects ran out.")
          sleep_and_clear(1.5)

          cls.reset_item_effects(item_name)

        entities.new_player.items_used[item_name] -= 1
Ejemplo n.º 6
0
    def add_item(self, item_key, quantity=1):
        item_to_add = all_items[item_key]

        if self.item_exists(item_to_add):
            for key in self.items_dict:
                if self.items_dict[key][0] == item_to_add:
                    self.items_dict[key][1] += quantity

        else:
            if self.empty_slot_exists():
                self.items_dict[self.empty_slot_key] = [item_to_add, quantity]

            else:
                player_choice = ''
                clear()
                print(
                    f"{Colours.fg.orange + Colours.bold + Colours.underline}Your inventory is currently full.{Colours.reset}"
                )
                sleep(1.5)

                while player_choice not in self.items_dict:
                    clear()
                    print(
                        f"""{Colours.fg.red}Which item would you like to remove?   
{Colours.reset + Colours.fg.cyan}(Type a number from  1 to {self.total_slots}, according to the item number you want to replace){Colours.fg.yellow}

{Colours.fg.orange + Colours.underline}Item you want to buy:
""")
                    display_equipment_stats(item_key, item_quantity=quantity)
                    print('\n')

                    self.display_items_dict(clear_the_screen=False)

                    player_choice = input(f"{Colours.input_colour}> ")

                    if player_choice not in self.items_dict:
                        clear()
                        print(
                            f"{Colours.fg.red + Colours.underline}Please enter a number from 1 to {self.total_slots}.{Colours.reset}"
                        )
                        sleep(2)

                self.items_dict[player_choice] = [item_to_add, quantity]

        clear()
        print(
            f"{Colours.fg.orange}You received {Colours.bold + Colours.fg.red}{quantity} {Colours.fg.green}{item_to_add.name}{Colours.reset + Colours.fg.orange}."
        )
        sleep_and_clear(1.5)
Ejemplo n.º 7
0
    def stun(self):
        raw_damage = int(
            System.calculate_percentage(total=new_player.max_health,
                                        percentage=5))

        new_player.take_damage(raw_damage, armour_absorption=False)

        clear()
        print(
            f"{self.name_string}{Colours.fg.orange} stunned you for {Colours.fg.red}{raw_damage}{Colours.fg.orange} damage."
        )
        print(
            f"{self.name_string}{Colours.fg.lightblue} gained an extra turn.")
        sleep_and_clear(2)

        self.attack()
Ejemplo n.º 8
0
    def sleep_for_health(self):
        player_choice = ''
        valid_inputs = ("short", "long", "back")
        not_tired_string = f"{Colours.alert('You Try To Sleep, But Feel Well Rested. Get Tired By Defeating Enemies In The Wilderness.')}"

        while player_choice not in valid_inputs:
            clear()
            player_choice = input(
                f"""{Colours.fg.orange}Which rest would you like to take?

{Colours.tag("short")} {Colours.fg.yellow}Short Rest {Colours.fg.red + Colours.underline}(Heals 50% of your health){Colours.reset}
{Colours.tag("long")} {Colours.fg.yellow}Long Rest {Colours.fg.red + Colours.underline}(Heals 100% of your health{Colours.reset + Colours.fg.red} + {Colours.fg.red + Colours.underline}Chance to get attacked{Colours.reset + Colours.fg.red})

{Colours.tag('back')} {Colours.fg.yellow} Go Back

{Colours.fg.orange}
> """).lower().strip()

            clear()

            #Player is taking short rest
            if player_choice == "short":
                if self.is_tired[0] and self.is_tired[1]:
                    self.is_tired[0] = False
                    self.is_tired[1] = False

                    self.heal(50)

                else:
                    print(not_tired_string)
                    sleep_and_clear(3)

            #Player is taking long rest
            elif player_choice == "long":
                if False not in self.is_tired:
                    self.is_tired = [False, False, False]

                    self.heal(100)

                    rdm_int = random.randint(1, 5)
                    #Player got a nightmare
                    if rdm_int == 5:
                        exploration.Combat.start(goblin, is_players_turn=False)

                else:
                    print(not_tired_string)
                    sleep_and_clear(3)
Ejemplo n.º 9
0
    def escape_from_combat(self):
        print(self)
        self.has_escaped = self.armour.is_lighter_than(
            self.current_enemy.armour)

        clear()
        if self.has_escaped:
            print(
                f"{Colours.fg.cyan}You successfully escaped from {self.current_enemy.name_string}{Colours.fg.cyan}."
            )

        else:
            print(
                f"""{Colours.fg.cyan}You tried to escape from {self.current_enemy.name_string}{Colours.fg.cyan}, but failed.

{self.current_enemy.name_string} {Colours.fg.cyan} gets another turn.
""")
        sleep_and_clear(2)
Ejemplo n.º 10
0
    def drop_loot(self):
        clear()
        print(
            f"{Colours.fg.green}You defeated {new_player.current_enemy.name_string}{Colours.fg.green}!!!"
        )
        sleep_and_clear(2)

        if not self is artifact_keeper and not self is talgrog_the_giant:
            rdm_int = random.randint(1, 100)

            #Drop gold coins
            if rdm_int in range(1, 91):
                self.drop_gold_coins()

            #Drop weapon
            elif rdm_int in range(91, 96):
                if self.weapon.can_drop:
                    self.drop_equipment(self.weapon)
                else:
                    self.drop_gold_coins()

            #Drop armour
            elif rdm_int in range(96, 101):
                if self.armour.can_drop:
                    self.drop_equipment(self.armour)
                else:
                    self.drop_gold_coins()

        #Drop artifact
        elif self is artifact_keeper:
            filtered_artifacts = list(
                filter(
                    lambda artifact: artifact.location is new_player.
                    current_location, setting.all_artifacts))

            artifact_to_add = filtered_artifacts[0]
            new_player.artifacts_collected.append(artifact_to_add)
            new_player.artifacts_not_collected.remove(artifact_to_add)

            print(
                f"{Colours.fg.green}You received {artifact_to_add.name_string}{Colours.fg.green}."
            )

        sleep_and_clear(1)
Ejemplo n.º 11
0
    def use_item(self):
        player_choice = ''
        player_used_item = False

        while not player_choice in self.items_dict and player_choice != "back":
            clear()
            print(f"""{Colours.fg.orange}Which item would you like to use?
{Colours.fg.lightblue}(Type the inventory slot number of the item you want to use)
{Colours.fg.cyan}(Type '{Colours.fg.green}back{Colours.fg.cyan}' to go back)

""")
            self.display_items_dict(clear_the_screen=False)
            player_choice = input(f"{Colours.input_colour}> ").lower().strip()

        if player_choice != "back" and self.items_dict[player_choice] != [
                None, 0
        ]:
            #Set to True
            player_used_item = True

            #Get item object from inventory slot
            item_object = self.items_dict[player_choice][0]

            #Remove item
            self.remove_item(player_choice)

            #Applying item effects
            entities.new_player.apply_item_effects("Increase",
                                                   item_object.increases)

            entities.new_player.current_enemy.apply_item_effects(
                "Decrease", item_object.decreases)

            #Incrementing turns
            entities.new_player.items_used[
                item_object.name] = item_object.affected_turns

            clear()
            print(
                f"{Colours.fg.orange}You used {item_object.name_string}{Colours.fg.orange}."
            )
            sleep_and_clear(1.5)

        return player_used_item
Ejemplo n.º 12
0
  def play(cls):
    while not entities.new_player.is_dead() and not entities.new_player.current_enemy is entities.talgrog_the_giant:
      if entities.new_player.main_menu_choice == None:
        #Display main menu
        cls.display_main_menu()
        entities.new_player.main_menu_choice = input(f"{Colours.input_colour}> ").lower().strip()

      GameState.save_account()

      #Try to execute player's choice
      try:
        cls.main_menu_choices[entities.new_player.main_menu_choice]()

      #Player entered invalid choice
      except KeyError:
        clear()
        print(f"{Colours.alert('INVALID COMMAND, TYPE THE LETTERS IN THE SQUARE BRACKETS.')}")
        sleep_and_clear(2)

      #Reset player choice
      entities.new_player.main_menu_choice = None

      GameState.save_account()
    

    if entities.new_player.current_enemy is entities.talgrog_the_giant and not entities.new_player.has_won:
      exploration.Combat.start_combat()

    #Player is dead
    if entities.new_player.is_dead():
      cls.display_death_message()
      GameState.reset_account()

    #Player has won
    else:
      cls.display_win_message()
      GameState.reset_account()


    GameState.save_account()
Ejemplo n.º 13
0
 def load_account(cls):
   username, password = None, None
   
   cls.get_accounts()
   clear()
     
   username = input(f"{Colours.fg.orange}Username: "******"{Colours.fg.red}Password: "******"{Colours.alert('Invalid username or password.')}")
     sleep_and_clear(2)
       
   else:
     cls.logged_in = True
     cls.account = (username, password)
     entities.new_player = cls.accounts_dict[cls.account]["Player"]
     objects.new_inventory = cls.accounts_dict[cls.account]["new_inventory"]
     entities.all_enemies = cls.accounts_dict[cls.account]["all_enemies"]
     setting.all_locations = cls.accounts_dict[cls.account]["all_locations"]
Ejemplo n.º 14
0
    def heal(self, percentage_to_heal):
        if isinstance(self, Player):
            entity = "You"
            possessive_pronoun = "your"
        else:
            entity = self.name_string
            possessive_pronoun = "its"

        value_to_heal = System.calculate_percentage(percentage_to_heal,
                                                    total=self.max_health)

        self.current_health += value_to_heal

        if self.current_health > self.max_health:
            self.current_health = self.max_health

        self.current_health = round(self.current_health)

        clear()
        print(
            f"{Colours.fg.cyan}{entity} {Colours.fg.cyan}regained {Colours.fg.red + Colours.underline}{percentage_to_heal}%{Colours.reset + Colours.fg.cyan} of {possessive_pronoun} {Colours.fg.green}health{Colours.fg.cyan}."
        )
        sleep_and_clear(2)
Ejemplo n.º 15
0
    def travel(self):
        if self.can_travel:
            player_choice = ''
            locations_copy = setting.all_locations.copy()
            del locations_copy['gd']

            while player_choice not in locations_copy and player_choice != 'back':
                clear()
                print(f"{Colours.fg.orange}Where Would You Like To Travel?" +
                      '\n')

                for key in locations_copy:
                    location = setting.all_locations[key]

                    if location != self.current_location:
                        print(f"{Colours.tag(key)} {location.name_string}")

                print('\n' +
                      f"{Colours.tag('back')} {Colours.fg.orange}Go Back" +
                      '\n')
                player_choice = input(f"{Colours.fg.orange}> ")

            if player_choice in setting.all_locations:
                self.current_location = setting.all_locations[player_choice]
                clear()
                print(
                    f"{Colours.fg.orange}You travelled to {self.current_location.name_string}{Colours.fg.orange}."
                )
                sleep_and_clear(2)

        else:
            clear()
            print(
                f"{Colours.fg.orange}You are not allowed to travel anymore because you have arrived at the Final Boss' location. {Colours.fg.red + Colours.bold}Prepare to fight him.{Colours.reset}"
            )
            sleep_and_clear(4)
Ejemplo n.º 16
0
    def attack(self):
        clear()
        rdm_int = random.randint(1, self.weapon.accuracy)

        #Player missed attack
        if rdm_int == 1:
            rdm_int = random.randint(1, 2)
            if rdm_int == 1:
                print(
                    f"{self.current_enemy.name_string}{Colours.fg.cyan} dodged your attack."
                )
            else:
                print(f"{Colours.fg.lightblue}You missed your attack.")
            sleep_and_clear(1.5)

        #Player hit attack
        else:
            multiplier = 1
            damage_range = self.weapon.damage
            raw_damage = random.randint(damage_range[0], damage_range[1])

            rdm_int = random.randint(1, self.weapon.crit_chance)

            #Player hit a critical hit (double damage)
            if rdm_int == 1:
                print(
                    f"{Colours.fg.orange + Colours.bold + Colours.underline}It's a critical hit!!!{Colours.reset}"
                )
                multiplier *= 2
                sleep_and_clear(1)

            damage_dealt = self.current_enemy.take_damage(
                raw_damage, multiplier)

            print(
                f"{Colours.fg.cyan}You attacked {self.current_enemy.name_string} {Colours.fg.cyan} and dealt {Colours.fg.orange}{damage_dealt} damage{Colours.fg.cyan}."
            )
            sleep_and_clear(1.5)