Skip to content
Snippets Groups Projects
Commit 8b6f5df6 authored by Thomas Glasper's avatar Thomas Glasper
Browse files

Add player levelling and xp system

parent c07cf3d0
No related branches found
No related tags found
No related merge requests found
......@@ -302,6 +302,7 @@ def combat(enemy):
# check if you killed enemy
if enemy.alive == False:
print("You defeated the " + enemy.name + "!\n")
player.gain_xp(enemy.level * 5)
player.current_room.cleared = True
break
......
......@@ -26,11 +26,9 @@ def remove_punct(text):
return no_punct
def normalise_input(user_input):
user_input = remove_punct(user_input).lower()
user_input = user_input.strip()
user_input = list(user_input.split(" "))
user_input = filter_words(user_input, skip_words)
return user_input
......@@ -211,15 +211,15 @@ class HealthItem(GameObject):
def _interaction(self, player):
# We don't need to heal if the player's health is more than 100
if player.hp >= 100:
if player.hp >= player.base_hp:
print(f"You can't use {self.name} - your health is already at 100 HP!")
else:
player.hp += self.health
# Don't allow the player's health to get higher than 100
if player.hp >= 100:
player.hp = 100
if player.hp >= player.base_hp:
player.hp = player.base_hp
print(f'Success, your health is now {player.hp} HP!')
......
from items import *
from map import rooms
from gameparser import normalise_input
class Player:
def __init__(self):
......@@ -8,8 +9,12 @@ class Player:
self.alive = True
# stats
self.hp = 100
self.level = 1
self.xp = 0
# stats
self.base_hp = 100
self.base_attack = 10
self.base_defense = 10
self.base_luck = 10
......@@ -21,6 +26,54 @@ class Player:
"magic": None,
}
def gain_xp(self, xp):
# calculate required xp for next level
required_xp = self.level * 10
self.xp += xp
print("You gained", str(xp), "xp.")
if self.xp >= required_xp:
self.xp -= required_xp
self.level += 1
print("You levelled up to level", str(self.level) + "!")
while True:
print("")
print("You can now select a base stat to make stronger.")
print("You can use the following commands:")
print("HP to increase your base HP.")
print("ATTACK to increase your base attack.")
print("DEFENSE to increase your base defense.")
print("LUCK to increase your base luck.")
user_input = input("> ")
user_input = normalise_input(user_input)
if user_input[0] == "hp":
print("You increased your base HP!\n")
self.base_hp += 5
break
elif user_input[0] == "attack":
print("You increased your base attack!\n")
self.base_attack += 5
break
elif user_input[0] == "defense":
print("You increased your base defense!\n")
self.base_defense += 5
break
elif user_input[0] == "luck":
print("You increased your base luck!\n")
self.base_luck += 5
break
else:
print("Did not recognise that category.")
def get_equipped_name(self, category):
if self.equipped[category] == None:
return "none"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment