CS 115 Program 3 Adventure Game Spring 2018


Due Dates:
Individual Design: Wednesday, April 18 midnight
Source: Sunday April 22, midnight "officially"
actually due by Wednesday April 25 midnight
and accepted until Friday April 27 midnight with some penalty

NOT accepted during Finals Week at all!

Assignment total points = Design (25 points) + Runs test cases (20 points) + Implementation (70 points) + Style and documentation (15 points) = 130 points

Submit all program materials (.py files) with the link here.

Use Program 3 and either Code or Design for type.

   _____       .___                    __                      ._.
  /  _  \    __| _/__  __ ____   _____/  |_ __ _________   ____| |
 /  /_\  \  / __ |\  \/ // __ \ /    \   __\  |  \_  __ \_/ __ \ |
/    |    \/ /_/ | \   /\  ___/|   |  \  | |  |  /|  | \/\  ___/\|
\____|__  /\____ |  \_/  \___  >___|  /__| |____/ |__|    \___  >_
        \/      \/           \/     \/                        \/\/

Educational Goals: the student should use the concepts of

Your program is going to play a simple Adventure game. This is done in plain text. The story starts as you are standing outside the entrance to a cave. Do you go in or not? (well, if you don't there's no story!:)

The data that represents the rooms in the cave are represented in a data file ("maze.dat" for now).

Example maze file: (maze.dat)

0,front of entrance, 1:2:4:5, torch:bag
1,back of entrance, 0:2:3:6, a gold piece:sword
2,round room, 1:0:4,  gem
3,bat cave, 4:5:6, food ration:water flask
4,library, 1:2, book:scroll
5,dark pit, 3:0, water bucket
6,exit, 3:1, 5 gold pieces

The first number on the line is the room number, a short description, connections (rooms that the current room are connected to, separated by colons, then objects that are in the room and can be picked up, separated by colons.

The last line of the file is always the exit room. If you end up there, you will be asked if you want to leave the cave, Y or N. It is assumed there is some path from the exit room that takes you back to the cave.

The first line in the file is assumed to be the starting point.

There can be as many rooms as you want in this file. Each room can have as many connections as you want. Not all connections have to be two-way; if room 2 goes to room 3, room 3 does not have to go back to room 2. You can have as many objects in the room as you want, including none. Just end the line after the last comma in that case.

You also want a file of longer descriptions which correspond to the rooms, "descriptions.dat" for now.

0:You see an entrance to a large cave.  This is pretty well lit but it gets darker farther back.
1:You are deep in a large cave.  There is hardly any light.  The floor is rough.
2:You see a round room with round doors.  The floor is smooth.
3:This is a rough cave with thick stalactites hanging down.  There is evidence of bats on the floor, though none are visible.
4:This is a room having bookshelves on all the walls between the doors and a small table in the middle.
5:This room has very little floor, having a deep dark pit in the middle of it. Don't fall in!
6:Here is a sign that says 'EXIT'.  You can see strong light streaming through a large door.

Another data structure is a list of strings which represents the adventurer's inventory. That is, what the adventurer is carrying with them.

The number is the room number, same as in the maze.dat file. The rest of the line (and it's as long as you want) is the longer description of the room. It should be consistent with the short description in the mazes.dat file.

Here are a couple more sample runs: winning and demo of go command

Example interaction with the user:

Adventure!

What's your name? Victor
You are in front of entrance cave

I know how to do these things:

Look - to see objects in the room
Take - pick up an object in the room
Drop - drop an object in inventory
Go   - go to a different room
Say  - say some words
Status - what are you holding
Quit - to end the game
which? look

You can see:
-------------------
1 torch
2 bag
-------------------
Press Enter

You are in front of entrance cave

I know how to do these things:

Look - to see objects in the room
Take - pick up an object in the room
Drop - drop an object in inventory
Go   - go to a different room
Say  - say some words
Status - what are you holding
Quit - to end the game
which?  take


Choose from:
1 torch
2 bag
which one? 1
torch picked up


You are in front of entrance cave

I know how to do these things:

Look - to see objects in the room
Take - pick up an object in the room
Drop - drop an object in inventory
Go   - go to a different room
Say  - say some words
Status - what are you holding
Quit - to end the game
which?
Command not understood
which? Status


Inventory
-------------------
1 a flashlight
2 torch
-------------------
Press Enter

(more of the game play)

you are in back of entrance cave

I know how to do these things:

Look - to see objects in the room
Take - pick up an object in the room
Drop - drop an object in inventory
Go   - go to a different room
Say  - say some words
Status - what are you holding
Quit - to end the game
which?  quit


Congratulations, Victor you made it through alive

You left the game with
-------------------
1 a flashlight
2 torch
-------------------
Press Enter

The long descriptions are used when you go to a room you have not been in before. This means that the maze rows (rooms) will need a flag that tells you whether you have visited that room or not. Just set every room to False to start with, except for the starting room. If the player goes to a room where the flag is False, the long description is displayed and the flag is set to True. The next time the player goes to that room, the flag is True and only the short description (name of room) is displayed.

There is a SECRET to winning the game. You have to pick up the Key to Programming, an object which can be placed at random in any room except the starting room. Once it's placed there, it doesn't move though. AND you have to use the command to say "Python is fun!". If you have said the words and have the Key in your inventory when you leave the game, you win 50000 gold pieces!

You can end the game by choosing the Quit command. Whatever you had in inventory when you left is displayed. If you met the conditions for winning the game (words and object) you are informed you won the game.

You can also end the game by going into the Exit room and saying you want to leave the cave. If you fulfilled the conditions above for winning, you'll be informed you won the game.

Great news! In this game, you never die!

You can assume that all inputs from the user should be validated. Don't let a function return a value that will cause the rest of the program to crash. Just reject it and let them try again.

Test Cases

Test Cases

Read three pages, about testing loops, testing files, and about testing ifs.

Design


Decide on what steps you will need to perform to solve this problem. Save this Python file as "design3.py" and submit it using the link above.

For each function described below, you need to write the three P's. This page gives some examples of writing function designs. Besides the prolog (3 P's) you need to design the function body just as we've always done. State what control structures you're using and how. What loops do you need? what if statements? How do you get the return value if any?

Now that you have more complicated data structures like lists and strings, describe what they look like. How are they constructed?

Design Notes

You MUST write and call these functions. You can also provide others that you think would be useful. Yes, you will have to figure out what parameters some functions need.

Some notes on the commands