## CS 115 Lab 3 Conditionals and Test Cases (Team)

### 80 Points

Educational goals of this lab - verify that every student can

• understand the testing process
• write a program to use some conditional operations
• nest if statements

### Submit your files with this link. Use the Lab 3 menu choice, and "Code" for the design/program and "Other" for the test plan text file.

INSTRUCTIONS:

• (80 points) Team Problem: Let the user go on an adventure
• The program presents the user with some choices and shows them the results.
• You will need to use boolean variables (flags) to know whether the player lived or died, to know whether the player got the gold or not and whether they got the magic ring or not.

Sample run

```Let's go on an adventure

You are in a dark cave.  You see two exits in front of you
1. a door
2. a tunnel
> 2

You see a big troll holding a club
You can choose to:
1. say Hello
2. attack it
> 1

The troll is friendly and gives you a magic ring

Game over!

You got out alive
Inventory:
You have a magic ring
```

Another sample run

```Let's go on an adventure

You are in a dark cave.  You see two exits in front of you
1. a door
2. a tunnel
> 1

You see a big sack tied at the top.
You can choose to:
1. pick it up
2. open it
> 1

It grows a big set of teeth and eats you!

Game over!

You died
```
• The other possible actions are:
• You attack the troll- you get flattened.
• You open the bag- you get 500 pieces of gold.

If you entered an invalid choice at any point, the message should be "Invalid choice".

You must then show the message "Game over!".

The possible outcomes at the end of the game are:

1. You got out alive. Inventory: (Either "you have 500 pieces of gold" or "you have a magic ring")
2. You died. (This happens if you attack the troll, pick up the bag or give an invalid choice)

If you died in the game, the Inventory is NOT mentioned.

• (14 points) Test Plan In a text file, put what should go in each of the lettered blanks. Please label each answer. Some blanks have lots of possible answers.
NOTE: You get HALF of these points for filling out the blanks correctly. You get the other HALF of the points when your program actually runs and gets the correct expected output.
DescriptionInputs Expected Output(s)
First Second
Door, pick up sack1 1 It grows teeth and eats you, Game over!, You died
Door, open sack1 2 You get 500 gp, Game over!, You got out alive, Inventory: you have 500 pieces of gold
__A.__ 2 __B.__ __C.__
__D.__ 2 __E.__ __F.__
Integer input, invalid choices__G.__ doesn't matter Invalid choice, Game over! You died.
• Submit your Test Plan with the link above and Lab 3 and Other menu choices. You can call the text file testcases3.txt.
• (22 points) Take the design given below, paste it into a file called adventure3.py and finish the DESIGN. If statements have their bodies/blocks indented in the design too. All lines should be comments. Note that the messages shown must be in the order given. Do not rearrange them.
```#Team x, Section x, Members present
#Purpose - to take the user on an adventure
#Pre-conditions:  user inputs 2 integers, both are either 1 or 2.
#Post-conditions:  prompts, results of actions, ending message and Inventory are displayed

# initialize gold flag, living flag and ring flag
# display first prompt  Door / Tunnel
# get user's first choice
# if user chooses 1
#display sack prompt pick up/open
#get user's second choice
#if chooses pickup
#output sack eats you
#adjust flags as needed
#otherwise if choose open sack
#output you got 500 gp
#adjust flags as needed
#
#   more design (YOU fill in)

# note that this output happens only ONE time in the design, here!
# output a blank line
# output Game Over!
# output a blank line

# if lived flag has value True
#   output You got out alive and display inventory
#
#  more design (YOU fill in)
```
• (44 points) Implement the program starting with the adventure3.py file you have written the design in. The design steps are the comments. Make sure you try all the test cases.
• Submit your Python file (adventure3.py) using the link above and the menu choices Lab 3 and Code.

Log off properly - you don't want your account misused by someone else!

Remember NOT to leave files on the local hard drives in a lab or anywhere else on campus! Make sure you save your projects on a portable storage device you take with you!