ICT112 - 2023 - Module 7 - Workshop Instructions
ICT112 - 2023 - Module 7 - Workshop Instructions
ICT112 - 2023 - Module 7 - Workshop Instructions
Learning Objectives
In this Workshop you will:
1. use string methods to make a game more robust;
2. use the string format(...) method to get nice output;
3. use Lists to store flexible collections of data
Task 1
Each week (week 1 to 8) you will be required to submit into Canvas your solution. Each submission
will be marked out of 5. Task 1 will be the total of your best 6 submissions (30 marks possible).
Before you do that, you might like to spend a few minutes playing one or two of the existing
games to see how they work:
1. All user input is converted to lowercase, so that it does not matter if the player has
the CAPS-LOCK key on or types a mixture of uppercase and lowercase letters.
2. Extra spaces ('whitespace') are allowed anywhere in the user input, and the game
still behaves correctly.
Here are some example input commands you should test. These should all behave the
same as "go north"
"go North"
"GO NORTH"
" go north "
These should all behave the same as "take black key" (or any other multi-word object in
your game).
"take Black Key"
" take black key "
Hint: after the input("...") command in the main loop of your game, you should convert the
input result to lowercase, and then split it into words, so that all whitespace is removed.
Then for the commands that can take multi-word objects, you can either pass a list of
words, or turn the list of words back into a single string by using the " ".join(list) method.
ICT112 – Module 7 Workshop
1. You need to have a separate list of movable objects for each location. So up the top
of your program, we will create one global dictionary, called items_in, which maps
each room/location name to a list of items (strings). So, to get the list of items for a
particular room, like the "bedroom", you can just write items_in["bedroom"], or to get the
list of items in the current room, you can just write items_in[state]. And of course,
since this is a list, you can use the append and remove list methods to modify the
items in that room. Here is the code to create this dictionary for the original simple
game. Notice how the movable objects in each room at the beginning of the game
are included in the appropriate list for each room. Copy this code and add it to the
global variables of your program, and modify the rooms and items to be what you
want for your own game:
# global dictionary of the movable objects in each location
items_in = {"bedroom" : ["aquarium", "bats"],
"hallway" : [],
"lounge" : ["stereo"]
}
2. Extend your describe() function so that it displays all the movable objects in the
current location. Hint: loop through the list of items in the current room like this: for
item in items_in[state]: ... and print out each item with a message like "You can see: "+item
3. Update your take_cmd(obj) function so that it gets the list of objects in the current
location and checks that the requested object does really exist in that list, before it
puts the object into the carrying variable. It should also remove the object from the
room, because you have now picked it up. Hint: to update a list (e.g. called contents)
you will find the following methods helpful:
a. s in contents # True if s is already in this location
b. contents.append(s) # adds s to the end of the list
c. contents.remove(s) # removes s from the list
4. Add a 'drop object' command to your game so that the player can drop an object in
the current location. (You could just do a simple 'drop' command at this stage with
no object specified, since the player can only carry one thing. But shortly we will
extend 'carrying' to be a list, and then the drop command will need to specify which
object to drop.)
ICT112 – Module 7 Workshop
Task 1 - Submission
Ensure you submit 3 files. You can continue to add features to your earlier files and submit in the
new file (ie text_game_movable.py can contain Q1 and 2).