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

题意: 

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

解析: 

游戏主要涉及4个类,Loaction、Item、Creatures、Goosechasers;Location描述玩家当前位置及周围9个结点的信息;Items描述每个装备的名字、介绍及威胁性信息;Creations描述所有生物名字、威胁性信息;Goosechasers描述天敌行为信息。游戏交互命令:QUIT,退出游戏;HELP,打印提示信息;INV,打印玩家当前装备信息;TAKE<ITEM>拾起装备,DROP<ITEM>丢弃装备,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.

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 205,236评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 87,867评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 151,715评论 0 340
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,899评论 1 278
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,895评论 5 368
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,733评论 1 283
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,085评论 3 399
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,722评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 43,025评论 1 300
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,696评论 2 323
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,816评论 1 333
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,447评论 4 322
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,057评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,009评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,254评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,204评论 2 352
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,561评论 2 343

推荐阅读更多精彩内容