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
d2f5ced6
Commit
d2f5ced6
authored
2 years ago
by
Ryan Tresman
Browse files
Options
Downloads
Plain Diff
Merge branch 'main' of
https://git.cardiff.ac.uk/c22033329/cm1101-team-project
parents
58b360a9
037af001
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
README.md
+1
-1
1 addition, 1 deletion
README.md
game.py
+4
-0
4 additions, 0 deletions
game.py
item_dist.py
+35
-3
35 additions, 3 deletions
item_dist.py
with
40 additions
and
4 deletions
README.md
+
1
−
1
View file @
d2f5ced6
...
...
@@ -12,7 +12,7 @@ You suddenly wake up in an ancient abandoned manner house. Every window boarded,
Matthew Aked, Ahmed El Ghazali, Thomas Glasper, Joshua Lewis, Evan Morgan, Haroon Raza, Ryan Tresman and Harry Wyatt.
## To Do
-
Upgrade items to classes and randomly generate items in each room - Harry Wyatt -
in progress
-
Upgrade items to classes and randomly generate items in each room - Harry Wyatt -
done
-
Convert player to class - Thomas Glasper - done
-
Equipping and unequipping items - Thomas Glasper - done
-
Inventory menu (including inspecting items) - Thomas Glasper - done
...
...
This diff is collapsed.
Click to expand it.
game.py
+
4
−
0
View file @
d2f5ced6
...
...
@@ -5,6 +5,7 @@ from player import *
from
items
import
*
from
gameparser
import
*
from
enemies
import
*
from
item_dist
import
*
import
random
def
display_inventory
():
...
...
@@ -477,6 +478,9 @@ def move(exits, direction):
# This is the entry point of our program
def
main
():
# Generate random items in each room before we start the game
populate_rooms
()
print
(
"
You suddenly wake up in an ancient abandoned manner house. Every window boarded, every door to the real world locked...
"
)
print
(
"
The old house finds itself inhabited by a plethora of strange monsters, of which many seem violent. It is up to you...
"
)
print
(
"
to trek forward and find a way out with what little you have - avoiding death as if it were around every corner.
"
)
...
...
This diff is collapsed.
Click to expand it.
item_dist.py
+
35
−
3
View file @
d2f5ced6
...
...
@@ -3,6 +3,8 @@ This file is designed to distribute items around the map, so the player can have
each time they play the game
'''
from
map
import
*
import
random
import
copy
# HINT: Use ALL_ROOMS string keyword in spawnable to allow the item to spawn in all rooms at that base percentage
...
...
@@ -209,12 +211,42 @@ spawnable_items = {
}
def
evaluate_spawn
(
obj
,
room
,
probability
):
'''
evaluate_spawn will see if an object should be copied into a room based on the
probably of the item spawning in there. If it should spawn in there,
it performs this action
'''
will_spawn
=
random
.
random
()
<
probability
if
will_spawn
is
True
:
new_item
=
copy
.
deepcopy
(
obj
)
room
.
items
.
append
(
new_item
)
def
populate_rooms
():
'''
This function is designed to populate the rooms
This function is designed to populate the rooms with items so that the user
can experience a unique experience
'''
global
rooms
for
room
in
rooms
:
pass
'''
In the final implementation of this code, a file will be read with a pickled
version of this variable.
'''
global
spawnable_items
for
category
in
spawnable_items
:
for
item
in
spawnable_items
[
category
]:
# Check what rooms this item can spawn in
for
room
in
item
.
spawnable
:
# We can have either Room or the keyword ALL_ROOMS
if
type
(
room
)
==
Room
:
evaluate_spawn
(
item
,
room
,
item
.
spawnable
[
room
])
else
:
if
room
==
"
ALL_ROOMS
"
:
for
r
in
rooms
:
# We don't wanna evaluate the spawn rate twice if there's an override
if
not
rooms
[
r
]
in
item
.
spawnable
:
evaluate_spawn
(
item
,
rooms
[
r
],
item
.
spawnable
[
room
])
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