Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CM1101 Team Project
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Harry Wyatt
CM1101 Team Project
Commits
8b6f5df6
Commit
8b6f5df6
authored
2 years ago
by
Thomas Glasper
Browse files
Options
Downloads
Patches
Plain Diff
Add player levelling and xp system
parent
c07cf3d0
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
game.py
+1
-0
1 addition, 0 deletions
game.py
gameparser.py
+0
-2
0 additions, 2 deletions
gameparser.py
items.py
+3
-3
3 additions, 3 deletions
items.py
player.py
+54
-1
54 additions, 1 deletion
player.py
with
58 additions
and
6 deletions
game.py
+
1
−
0
View file @
8b6f5df6
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
gameparser.py
+
0
−
2
View file @
8b6f5df6
...
...
@@ -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
This diff is collapsed.
Click to expand it.
items.py
+
3
−
3
View file @
8b6f5df6
...
...
@@ -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!
'
)
...
...
This diff is collapsed.
Click to expand it.
player.py
+
54
−
1
View file @
8b6f5df6
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
"
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment