2nd Semester Intro to Computer Science

What you will learn

Reading

Project

Using Python, students will use casting, Boolean expressions, lists and while loops to create a text-based adventure game!

Overview

This game takes place in a three story dungeon. The user has to traverse the levels in search of the prize. Along the way they collect items and fight monsters. On each move the user has seven possible commands: left, right, up, down, grab, fight, help. If the input is invalid (not one of these commands,) the game will let the user know. Otherwise, the game will execute the user’s command. The goal of the game is to collect the prize guarded by the boss monster.

Details

Behavior

The game has three floors
At the start of the game, the user is placed in one of the rooms
Movement
Contents of rooms
Monsters guard some rooms

Implementation Details

User Items
Monsters
Movement Implementation
Win/Lose

Design Considerations

Game Board

The game board is the basis of the game. The following is a way to think of a smaller game board as a set of three lists: one for each floor.

floor_1 = ['nothing', 'nothing', 'stairs up']
floor_2 = ['nothing', 'nothing', 'stairs up']
floor_3 = ['prize', 'nothing', 'nothing']

The above code has each floor being its own lists. Feel free to use a different implementation, but this should work for our purposes.

User Position

It will be useful to keep track of the user’s position through a variable.

user_room = 0
user_floor = floor_1

This would put the user at the position of the first room of the first floor.

Validating User Input

You will need to check the input of the user to make sure it is valid for the current game state:

if user_input == "down":
    current_room = user_floor[user_room]
    if current_room != "stairs down":
        print("Can't go downstairs; there are no stairs.")

Extra Credit

Alternate Project

Created By Brian Weinfeld

Using Python, you will create an interactive TODO list that allows users to add and remove tasks from a list.

Overview

One of the most common tasks we use computers for is to store and track data. Perhaps the most simple form of this task is the TODO list. A TODO list is simply a list of information (for example, chores that needs to be done) that the user wants to track. They can add tasks to the list, remove them when they are complete and examine the list as they progress. Have you ever used a notes app on your phone?

Details

Behavior

Welcome to your TODO list
What would you like to do? (add, remove, list, exit) list
[]

What would you like to do? (add, remove, list, exit) add
What would you like to add to your list? go to gym
Successfully added
What would you like to do? (add, remove, list, exit) list
['go to gym']

What would you like to do? (add, remove, list, exit) add
What would you like to add to your list? buy food
Successfully added
What would you like to do? (add, remove, list, exit) list
['go to gym', 'buy food']

What would you like to do? (add, remove, list, exit) add
What would you like to add to your list? go to gym
This is already on your list!
What would you like to do? (add, remove, list, exit) list
['go to gym', 'buy food']

What would you like to do? (add, remove, list, exit) remove
What would you like to remove? go to gym
Successfully removed
What would you like to do? (add, remove, list, exit) list
['buy food']

What would you like to do? (add, remove, list, exit) remove
What would you like to remove? clean bedroom
This is not in the list!
What would you like to do? (add, remove, list, exit) list
['buy food']

What would you like to do? (add, remove, list, exit) exit
Goodbye

Implementation Details

Challenge

This section contains additional components you can add to the project. These should only be attempted after the project has been completed.

Welcome to your TODO list
What would you like to do? (add, remove, undo, list, exit) add go to gym
Successfully added
What would you like to do? (add, remove, undo, list, exit) list
['go to gym']

What would you like to do? (add, remove, undo, list, exit) add clean bedroom
Successfully added
What would you like to do? (add, remove, undo, list, exit) list
['go to gym', 'clean bedroom']

What would you like to do? (add, remove, undo, list, exit) remove bedroom
This is not in the list!
What would you like to do? (add, remove, undo, list, exit) remove clean bedroom
Successfully removed
What would you like to do? (add, remove, undo, list, exit) list
['go to gym']
Welcome to your TODO list
What would you like to do? (add, remove, undo, list, exit) add go to gym
Successfully added
What would you like to do? (add, remove, undo, list, exit) add clean bedroom
Successfully added
What would you like to do? (add, remove, undo, list, exit) list
['go to gym', 'clean bedroom']

What would you like to do? (add, remove, undo, list, exit) undo
Successfully undid last add.
What would you like to do? (add, remove, undo, list, exit) list
['go to gym']

What would you like to do? (add, remove, undo, list, exit) undo
Cannot undo. You already removed this item
What would you like to do? (add, remove, undo, list, exit) list
['go to gym']

Super Challenge

The super challenge will require knowledge that has not been taught yet. You will need to do additional research on your own. Good luck!

It is possible to track enough information so that the undo command can be called repeatedly. Modify the undo command so that it will always work by removing the most recently added element in the TODO list that is still in the list. The only time the command should do nothing is when the TODO list is empty.

Rubric

Student Name: ___________ Date: ______

Student correctly identifies data types (2.01)

Assessed in Unit 3

Student correctly uses conditionals to maintain flow of control (2.02, 2.03)

3 2 1 0 Points
All of the conditionals run as expected Most of the conditionals run as expected Few conditionals run as expected There is no evidence the student can correctly use conditionals  
      Sub Total  

Student correctly uses lists (2.04 & 2.05)

3 2 1 0 Points
Student correctly uses the length function __ Student attempts to use the length function incorrectly No evidence the student can use the length function  
Student can access items from a list using the index Student often can access item from a list using the index Student attempts to access items from a list using the index No evidence the students can access items from a list using the index  
Students can add and remove items to/from a list Students can correctly add OR remove items from a list Student attempts to add and remove items from a list No evidence that the students can add or remove items from a list  
      Sub Total  

Student can correctly use the while loop (2.06)

3 2 1 0 Points
Student correctly uses the while loop Students attempts to use the while loop, but the condition is not correct _____ There is no evidence the student can use the while loop  
      Sub Total  

Student can decompose a problem to create a program from a brief

3 2 1 0 Points
Student program runs without error The students program has a few errors, but it does not impact the program’s functionality Student program has errors that impact the program’s functionality Student program is not functional  
__ Students submitted documentation showing planning for most variables and functions. Students submitted documentation showing planning for a few variables and functions. No evidence of planning  
      Sub Total  

Student uses naming/ syntax conventions and comments to increase readability

2 1 0 Points
Syntax conventions are generally used Sometimes syntax conventions are used No evidence of syntax conventions to aid in code readability  
All variables have clear names Some variables have clear names No evidence of using variable names to aid in code read ability  
__ Student comments aid code readability No evidence of using comments to aid in code readability.  
    Sub Total  

Final Grade

Points Possible Points Earned x Weight Total Points
25 __ X __  

Check your understanding

Pick an answer for each question. You can try again until you get it right.

1. Why is a list a good way to track a player’s items in a game?

  • Lists cannot change while the program runs
  • Lists make the game run faster
  • A list can only hold numbers
  • A list can grow and shrink as items are added and removed

Lists can be changed while a program runs, so items can be added with append and removed as the game goes on.

2. Why would the game use a while loop for the main game play?

  • To run the game exactly once
  • To keep asking for commands until the game is won or lost
  • To store the floors in a list
  • To convert input to integers

A loop keeps the game going turn after turn until an ending condition stops it.

3. Before moving in a direction, why should the program check the room contents or position?

  • To validate that the move is allowed in the current game state
  • Because Python requires an if before every input
  • To make the list longer
  • To clear the screen

Conditionals let the program reject invalid moves, such as going up where there is no staircase.

Downloads