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
c8fad9fb
Commit
c8fad9fb
authored
2 years ago
by
Harry Wyatt
Browse files
Options
Downloads
Patches
Plain Diff
Increased the variety of names of keys and chests
parent
37a7218f
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
-2
1 addition, 2 deletions
game.py
item_dist.py
+28
-6
28 additions, 6 deletions
item_dist.py
items.py
+2
-1
2 additions, 1 deletion
items.py
player.py
+6
-3
6 additions, 3 deletions
player.py
with
37 additions
and
12 deletions
game.py
+
1
−
2
View file @
c8fad9fb
...
...
@@ -594,7 +594,6 @@ def loadingbar():
# This is the entry point of our program
def
main
():
# Generate random items in each room before we start the game
clear
()
loading
=
[
'
Loading -
'
,
'
Loading
\\
'
,
'
Loading |
'
,
'
Loading /
'
]
for
i
in
range
(
10
):
...
...
@@ -630,7 +629,7 @@ def main():
if
player
.
current_room
.
cleared
==
False
:
# filler, for now
for
enemy
in
player
.
current_room
.
enemies
:
combat
(
enemy
)
#
combat(enemy)
if
player
.
alive
==
False
:
break
...
...
This diff is collapsed.
Click to expand it.
item_dist.py
+
28
−
6
View file @
c8fad9fb
...
...
@@ -7,13 +7,26 @@ import random
import
json
# Global vars to edit how chests may spawn in the game
NO_CHESTS
=
range
(
1
,
4
)
# 1-
3
chests can spawn in the entire game
NO_CHESTS
=
range
(
1
,
5
)
# 1-
4
chests can spawn in the entire game
NEED_ITEM_PAIRING
=
0.6
# 60% of chests will need a key or other to be opened
ALLOW_MULTICHESTS
=
False
# Can one room have more than one chest in it?
CHANCE_NOTHING
=
15
# The numbers of entries in the raffle that result in nothing being place into the chest
EXCLUDE_CHESTS
=
[
spawn_room
]
# The rooms in which no chests can spawn - ever!
CHEST_NAMES
=
[]
KEY_NAMES
=
[]
# This list goes [["id", "name"], ... ]
CHEST_NAMES
=
[
[
"
chest
"
,
"
old chest
"
],
[
"
chest
"
,
"
treasure chest
"
],
[
"
chest
"
,
"
coffin chest
"
],
[
"
chest
"
,
"
brown chest
"
],
[
"
chest
"
,
"
metal chest
"
],
[
"
chest
"
,
"
modern chest
"
],
[
"
suitcase
"
,
"
black suitcase
"
],
[
"
box
"
,
"
jewelry box
"
],
[
"
case
"
,
"
business case
"
],
[
"
crate
"
,
"
woodern crate
"
],
[
"
safe
"
,
"
money safe
"
]
]
KEY_NAMES
=
[
"
rusty key
"
,
"
old key
"
,
"
trusty key
"
,
"
antique key
"
,
"
burned key
"
,
"
tubular key
"
,
"
paracentric key
"
]
# Item spawn probability file
PROBABILITIES_FILE
=
"
probabilities.json
"
...
...
@@ -37,6 +50,7 @@ def read_probabilities():
f
=
open
(
PROBABILITIES_FILE
,
"
r
"
)
data
=
json
.
load
(
f
)
f
.
close
()
# Close the data file to avoid memory leaking
return
data
...
...
@@ -50,6 +64,8 @@ def create_chests():
global
EXCLUDE_CHESTS
global
rooms
global
ALLOW_MULTICHESTS
global
CHEST_NAMES
global
KEY_NAMES
chests
=
[]
chest_no
=
random
.
choice
(
NO_CHESTS
)
# As it is a range, we must dedicate ourselves to a number (of chests)
...
...
@@ -60,9 +76,12 @@ def create_chests():
for
i
in
range
(
0
,
chest_no
+
1
):
needs_key
=
random
.
random
()
<
NEED_ITEM_PAIRING
# Choose a name and id for the chest
info
=
random
.
choice
(
CHEST_NAMES
)
new_chest
=
Chest
(
id
=
"
chest
"
,
name
=
"
chest
"
,
id
=
info
[
0
]
,
name
=
info
[
1
]
,
description
=
"
chest
"
,
contains
=
None
)
...
...
@@ -91,9 +110,12 @@ def create_chests():
room_to_put
.
items
.
append
(
new_chest
)
if
needs_key
is
True
:
# Get a key name
name
=
random
.
choice
(
KEY_NAMES
)
new_key
=
Unlocks
(
id
=
"
key
"
,
name
=
"
old key
"
,
name
=
name
,
description
=
f
"
It
'
s hard to read, but the tag seems to say
\"
{
new_chest
.
id
.
upper
()
}
IN
{
room_to_put
.
name
.
upper
()
}
\"
"
,
perish_on_open
=
True
)
...
...
This diff is collapsed.
Click to expand it.
items.py
+
2
−
1
View file @
c8fad9fb
...
...
@@ -237,13 +237,14 @@ class Chest(GameObject):
contains
=
None
# contains is expected to be a subclass of GameObject, a list or a NoneType
requires
=
None
# None means no key or anything is needed, else this should be set to Unlocks class
opened
=
False
on_interaction_description
=
"
to open the
chest
"
on_interaction_description
=
"
to open the
{0}
"
def
__init__
(
self
,
id
,
name
,
description
,
contains
,
requires
=
None
,
pickup
=
False
,
place
=
False
):
super
().
__init__
(
id
,
name
,
description
,
pickup
,
place
)
self
.
contains
=
contains
self
.
requires
=
requires
self
.
on_interaction_description
.
format
(
self
.
id
)
def
_interaction
(
self
,
player
):
# Upon interacting with a chest item, the player should be awarded the items inside
...
...
This diff is collapsed.
Click to expand it.
player.py
+
6
−
3
View file @
c8fad9fb
...
...
@@ -100,9 +100,12 @@ class Player:
for
category
in
self
.
equipped
:
item
=
self
.
equipped
[
category
]
if
item
.
id
==
item_id
:
item
.
inspect
()
return
# We must check is it a valid object, as we can also expect NoneType here
if
issubclass
(
type
(
item
),
GameObject
):
if
item
.
id
==
item_id
:
item
.
inspect
()
return
print
(
"
Could not find that item to inspect.
"
)
...
...
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