悉尼大学INFO1110/COMP9001 Assignment 2 课业解析

题意: 

用python做一个名为野鹅逃亡(wild goose chase)的命令行游戏,野鹅必须吓跑地图上所有生物或者逃到安全位置才能获得胜利,被其他生物抓住游戏失败。

解析: 

游戏主要涉及4个类,Loaction、Item、Creatures、Goosechasers;Location描述玩家当前位置及周围9个结点的信息;Items描述每个装备的名字、介绍及威胁性信息;Creations描述所有生物名字、威胁性信息;Goosechasers描述天敌行为信息。游戏交互命令:QUIT,退出游戏;HELP,打印提示信息;INV,打印玩家当前装备信息;TAKE拾起装备,DROP丢弃装备,FLEE成功逃离(只在安全地有效);HONK威吓,比较野鹅自身和目标生物的威胁性(装备威胁性叠加),高的话成功,否则失败;WAIT,什么都不做;LOOK,显示当前位置信息……

游戏进程:


涉及知识点:

python、数组、类和对象、信息处理 

更多可加微信讨论 

微信号:tiamo-0620

pdf

INFO1110 / COMP9001 Assignment 2

Goosechasers: A Titled Goose Game

Milestone Deadline: 11:59 PM Monday, 28th October 2019 AEST (Week 12)

Final Deadline: 11:59 PM Monday, 4th November 2019 AEST (Week 13)

Weighting: 10% of the final assessment mark.

You are a goose. Beautiful. Majestic. Unstoppable. In the wake of your majesty, even the most

intense of human passions are but fleeting whispers in comparison - for not only are you a

goose, you are the Goose: Her Excellency, Duchess Hilda von Goosensmirch the Red, Countess of

Loch Lanore and Grandmaster of the Order of the Silver Leek. There are those, however, that

claim to see you for what you truly are: a terror to society; an agent of chaos - an avatar of

destruction.

The Goosechasers, as they call themselves, belong to a nefarious order of humans (and humanadjacent creatures) dedicated to your capture and suppression. Thanks to an unfortunate series

of events, you, Duchess Hilda von Goosensmirch the Red, Countess of Loch Lanore and

Grandmaster of the Order of the Silver Leek, have been cornered by one or more of these

Goosechasers - a scenario most sub-optimal for you and yours.

You are, of course, a goose, and in all your wisdom and majesty, are privy to many a means of

response to this situation. Perhaps you are feeling merciful, and simply wish to evade the

Goosechasers until they are no longer a problem - or perhaps you have suffered their existence

long enough, and must remind them that they have no right to encroach upon your domain.

Picture Credits: Pixabay, Uploaded by Alexas_Fotos on June 20th, 2018.

Overview

Description

For this assignment, you will write a game that simulates a wild goose chase. The player will

control a goose - a creature - that moves from one location to another, while avoiding other

creatures that wish to harm it. The goose may attempt to frighten other creatures into running

away (permanently) by honking at them, though some creatures will be more difficult to frighten

than others. If the goose is caught by another creature that it cannot frighten, the player loses. If

the goose successfully navigates to a location that allows it to flee from the other creatures, or

successfully frightens away all other creatures on the map, the player wins.

Implementation details

Your program will be written in Python 3. The only Python module that you are allowed to import

is sys . To help you begin, a scaffold has been provided. This scaffold consists of the following

files:

game.py , which should contain the main body of your program.

preprocessing.py

creature.py

location.py

item.py

creature_test.py (only relevant to final submission; see page 29 for details)

Your entire program must be contained in these files. It is recommended that you implement the

functions in these files to the best of your ability, and use them to help you complete the

assignment. You may create new functions as you see fit.

Additionally, a few sample configuration files have been given to help you start up your program.

Help and feedback

You are encouraged to ask questions about the assignment on the discussion board, on Ed.

Please ensure your code is comprehensible before requesting feedback. We recommend that

your code adheres to the PEP 8 style guide, and is commented appropriately.

Staff may make announcements on Ed regarding any updates or clarifications to the assignment.

You can ask questions on Ed using the assignments category. Please read this assignment

description carefully before asking questions. Please ensure that your work is your own and you

do not share any code or solutions with other students.

Submission

You will submit your code on two separate assignment pages on Edstem - one for your Milestone

submission and one for your Final submission. You are encouraged to submit multiple times. After

each submission, the marking system will automatically check your code against public test

cases.

These public tests do not cover all parts of the specification and your code. The complete test

suite contains both public and hidden test cases, and your code will not be run through this suite

until after the assignment deadline.

Please ensure you carefully follow the assignment specification. Your program output must

exactly match the output shown in the examples.

Warning: Any attempts to deceive or disrupt the marking system will result in an immediate zero

for the entire assignment. Negative marks can be assigned if you do not properly follow the

assignment specifications, or your code is unnecessarily or deliberately obfuscated.

Milestone

To ensure you are making regular progress on this assignment, you must have achieved a

minimum level of functionality in your submission by October 28th, 11:59 PM AEST (Week 12

Monday) to receive a portion of the marks. See the Milestone Submission section at the end of this

document for further details.

Configuration Files

The program will be given 4 extra command line arguments when it is run:

These arguments (let's call them configuration files) will be used to generate Location , Item ,

and Creature objects that you will need to run your program. The Location , Item , and Creature

classes are to be defined in the location.py , item.py , and creature.py files, respectively, and

the specification for these are available in the Classes section on page 6 onwards.

Examples of these configuration files are available in the provided scaffold; check for the files

sample_paths.txt , sample_items.txt , sample_chasers.txt , and sample_exits.txt Empty lines

encountered in any configuration file can be safely skipped and ignored.

If fewer than 4 arguments are supplied, print: "Usage: python3 game.py

" and exit the program.

Of the given arguments, you can expect that they will all be paths to a file (and/or the name of a

file). If any one of the files specified by the arguments do not exist, print: "You have

specified an invalid configuration file." and exit the program.

The first argument, , should be the name of a file containing a list of all connections

between Locations in the program. You can use this file to generate Location objects as defined

on page 6. Each line is of the form:

Where START and DIRECTION are the names of Location objects, and DIRECTION indicates a

direction on the compass (northwest, north, northeast, east, southeast, south, southwest, west)

that a creature must travel towards in order to move between START and DIRECTION . For

example:

If a Creature is currently at the Lake , it can move NORTHEAST to arrive at the Trail . Similarly, if a

Creature is currently on the Trail , it can travel SOUTH in order to arrive at the Gazebo .

$ python3 game.py

START > DIRECTION > DESTINATION

Lake > northeast > Trail

Trail > SOUTH > Gazebo

Paths do not need to be reflective - going north in location A and immediately going back south

does not have to lead you back to location A. This is a game, so some paths might not make

sense, and that's ok! For example:

Location names are case sensitive, but DIRECTION s are not.

When the program starts, the player will begin in the FIRST room specified by this file. If an

empty file is given, print: "The game cannot run without any rooms :(" and exit the

program.

You can reasonably expect that any file we will give you will contain valid input (i.e. no

weird lines like "Grass > Fence > More Grass" or "Not enough > arrows" .)

The second argument, , should be the name of a file defining all the Item objects that

are available in-game. Each line is of the form:

Most of these are explained in the description of the Item class on page 9.

full_desc is a long description of the item which is written to a Location 's description if the

item exists at that location, but has not been picked up by a Creature . More information on

this in can be found in the Location description on page 6.

location - as it implies - specifies the name of a Location that the Item object will appear

in when the game begins. You can expect that this is name will also appear somewhere in

the configuration file.

For example:

It is possible for the game to start and end with no items, so it is possible that the file specified by

is empty. Should this be the case, the game should run as normal.

Lake > NORTH > Gazebo

Gazebo > South > Gazebo

short_name | item_name | full_desc | terror_rating | location

rake | battered, old rake | A battered, old rake lies here, dreaming of lakes. | 2 |

Garden

The third argument, , should be the name of a file defining all Creature objects in the

game that are not controlled by the player. Each line of this file is of the form:

The name of a Creature is a unique name that the program (and the user) can use to refer

to the Creature object.

A description of the Creature will be written to a Location 's description if the Creature is

in the same Location as the player.

terror_rating describes the terror_rating that a Creature begins with at the start of the

game. This number represents how terrifying something is - or how difficult a Creature is to

frighten. More details about this can be found in the Creature description on page 10.

location - as it implies - specifies the name of a Location that the Creature object will

appear in when the game begins. You can expect that this is name will also appear

somewhere in the configuration file.

direction describes a movement pattern that a Creature will engage in if it is not

controlled by the player. More on this on pages 10-12.

An example:

As the premise of the game is not possible without any creatures to chase the player, the

file cannot be empty! If an empty file is provided, print: "There is

nothing chasing you!" and exit the program.

The fourth argument, , should be the name of a file that contains a list of Location

names. Each of these Location objects will allow the player to use the FLEE command (page 16)

to win the game. If a line specifies a name that does not correspond to a Location , ignore it and

move on to the next one.

It is possible for the configuration file to be empty - in that case, the player has no

choice but to scare off all other Creatures to win!

name | description | terror_rating | location | direction

dog | A dog is barking at you! | 4 | Park | North

Classes

Locations

Each location in the game is represented by an object of the Location class, which you can define

in the given location.py scaffold. A Location object is characterised by:

A name attribute - this is unique to each Location ; no two Location objects should have the

same name !

The ability to store Item objects. When the game begins, a Location may already contain

one or more Item objects (as dictated by the configuration file.)

The player may also choose to DROP an object at their current location.

For each Location loc , you will also want to:

Store all other locations that a Creature can reach by moving in a compass direction away

from loc . (These are defined by the configuration file, written on page 3.)

Know whether or not using the FLEE command when the player is at Location loc will end

the game. (These are defined by the configuration file, written on page 5.)

At the start of the game, and whenever the player enters a new Location or whenever the

LOOK command is invoked, a display representing their current Location is printed to standard

output. Such a display consists of:

A visualisation of the room and its possible exits. This visualisation is always 5 lines long,

and is populated by boxes [ ] to indicate locations reachable from the player's position.

There are nine possible boxes total: one for each point of the compass, and one for the

player's current location. The rstrip() method may be useful here.

The current location, [x] , is always in the middle of the third line (about four

spaces/character widths from the left edge).

[x]

You are now at: A Room With No Paths.

There is nothing here.

>>

If it is possible for the player to reach another Location by moving northwest of their

current position, another box [ ] will appear on the top left corner of the display, with a

line leading to it from the current location [x] - like so:

Likewise, if it is possible for the player to reach another Location by moving north of their

current position, another box will appear in the middle of the top row of the display - also

with a line leading from the current location.

Similarly for the northeast/top right corner:

... and so on for all the points of the compass. Be aware that a Location can have

multiple paths!

[ ]

\

[x]

You are now at: A Room With One Path.

There is nothing here.

>>

[ ]

|

[x]

You are now at: A Different Room.

There is nothing here.

>>

[ ]

/

[x]

You are now at: New Room.

There is nothing here.

>>

[ ]

|

[x]-[ ]

/

[ ]

You are now at: A Room With Three Paths.

There is nothing here.

>>

So a room with all possible paths leading out will look as follows:

Additionally, adjacent Locations that have one or more non-player Creature s inside of them

will be represented with [C] instead.

A line indicating the name of the player's current location. It follows the form: "You are now

at: ."

A paragraph of variable length, derived from the full_desc attributes of all Item objects in

the current Location , followed by the description attributes of all Creature objects in the

current Location that are not controlled by the player (such Creatures will be described in

more detail on page 10.)

[ ] [ ]

\ /

[ ]-[x]

|

[ ]

You are now at: A Room With Many Paths.

There is nothing here.

>>

[ ] [ ] [ ]

\ | /

[ ]-[x]-[ ]

/ | \

[ ] [ ] [ ]

You are now at: A Crossroads.

There is nothing here.

>>

[C] [C] [ ]

\ | /

[ ]-[x]-[ ]

/ | \

[C] [ ] [C]

You are now at: A Crossroads.

There is nothing here.

>>

[ ]-[x]

|

[ ]

You are now at: The Den.

There is an abandoned hot dog here. Goosechaser Alice is trying to slow you down by

scattering breadcrumbs at your feet.

>>

If there are multiple Item objects at a Location , the full_desc of the first item to be

present in the Location will be printed first.

e.g. If the Garden contains a knife, then the player drops a donut in the Garden , the

full_desc of the knife will be printed first, then the donut.

If there is no way to tell which Item arrived at the location first (i.e. they both

started in the same room), this priority instead goes to the first Item to be defined

in the configuration file.

If two or more Creature s not controlled by the player are in the same Location when

this happens, the first Creature to appear in the configuration file will have

its description printed first.

If no Items or non-player Creatures are at the player's current Location , this line will

instead say, "There is nothing here."

If it is possible for the player to successfully use the FLEE command at a location (this is a

win condition! Check the FLEE command on page 16 for more details), the following line is

added to the end of the display: "The path to freedom is clear. You can FLEE this place."

Items

Every item in the game is represented by an object of the Item class, which you can define in the

given item.py scaffold. An Item object has the following attributes:

A short_name is an abbreviation of the item's full name, which the user can use to refer to

the item when entering commands. To avoid confusion, short_name s are unique and caseinsensitive.

item_name is the item's name in full, usually a short description of what it is. item_name s are

also unique and case-insensitive.

full_desc is a long description of the item which is written to a Location 's description if the

Item exists at that location but has not been picked up by a Creature .

terror_rating describes how much more terrifying a Creature will look if it is carrying an

item. This should be a number, and can be negative or positive. Whenever a creature picks

up an item, the item's terror_rating is immediately added to the creature's. Whenever a

creature drops an item, the item's terror_rating is immediately subtracted from the

creature's.

[ ]-[x]

|

[ ]

You are now at: The Den.

There is an abandoned hot dog here. Goosechaser Alice is trying to slow you down by

scattering breadcrumbs at your feet.

The path to freedom is clear. You can FLEE this place.

>>

Creatures

An object of the Creature class represents an entity in your game - you can define this class in

the given creature.py scaffold. It could represent the goose that the player is trying to lead to

safety, or any number of Goosechasers that are attempting to corner it. All non-player Creature

objects should be defined in the configuration file (page 5). Creatures are

characterised by the following properties:

A name - a unique and case-insensitive name that the program (and the user) can use to

refer to the Creature object.

A terror_rating . This number represents how terrifying something is - or how difficult a

Creature is to frighten.

At the start of the game, the player's (goose's) terror_rating is 5.

Every other Creature object's initial terror_rating is defined by the file.

ALL Creatures , including those not controlled by the player, can obtain and carry Item

objects that can modify its terror_rating .

Some way of keeping track of the Item objects being carried by the Creature .

Some way of keeping track of where the creature is - possibly by tying it to a Location . Be

aware that all Creature objects should be able to move from one Location to another - and

that more than one Creature can exist at the same Location at a time.

Goosechasers (Non-Player Creatures)

On top of the above, non-player Creatures (let's call them Goosechasers) might have a

description - a short description of this entity that is written to a Location 's display when the

player is in the same room as the Creature .

Goosechasers are also special because of how they move and interact with the rest of the game!

Each Goosechaser has a direction property that tells them what direction they'll attempt to

move in if they have to move. This property is defined for each Goosechaser in the

configuration file.

Every time the player moves to a new location, uses the WAIT or HONK commands, drops an

item, or picks up an item, all Goosechasers in the game will "take their turn" - starting with the

Goosechaser that appears first in the configuration file, then the one that appears

second, and so on. The player's (goose's) action - moving, waiting, or interacting with items - will

always resolve before any Goosechasers can take their turn. A diagram has been provided on the

next page to better illustrate how Goosechasers react to specific commands.

Player's "Turn"

Player enters commands.

你可能感兴趣的:(悉尼大学INFO1110/COMP9001 Assignment 2 课业解析)