Skip to article frontmatterSkip to article content

Project 02: Falling Sand Simulator

Step 0. Prepare

  1. Click the link and then “Accept this assignment”.
    • Wait a few seconds and refresh the page. Refresh until the page says “You’re ready to go!”. The page has a link to a github repo.
    • Click the link to see your new repo on github.com.
    • Click the green Code button and copy the SSH link it shows.
  2. In a terminal,
    • cd to the directory where you are putting all your CS112 assignments.
    • type git clone paste-the-contents-of-the-link-you-copied
  3. cd to the new directory containing your repo.
    • type code . to start up Visual Studio Code in that directory.
    • Inspect the code you got in the assignment.
    • In the terminal, type make
    • The code should compile and give you an executable called FallingSand.
  4. Run the program: type
./FallingSand <YourBridgesName> <YourBridgesId> 

Step 0.1. Setting Up Your Bridges Account

You will need to make yourself a Bridges Account here.

Please use your Calvin information, and do fill in the optional fields correctly. Use “CS112” as the Course number.

To get your username and id, login to the bridges project, and go to the Profile page where you will see your “User Name” and “API Sha1 Key”. That second thing is your unique id.

Step 0.2. Instructions

In this simulation, you can move your cursor around a two-dimensional “board” and create or delete one of 3 different “elements” — a square of sand, a drop of water, or a block of metal. Here is what happens when each element is created:

Falling Sand Simulator.

Figure 1:Falling Sand Simulator.

In the image above you can see how Sand stacks on top of Sand and Metal. The Water will fill in any area that is a “cup”. If one were to move the Cursor (the 6-point star) over above the Water that is in the cup in the middle and drop a Sand, it would slide down the board, falling through the Water, leaving a Water up above the level of the Sand. The Water would then randomly move back and forth until falling down to the bottom.

The user interface for the “game” is a little strange, IMO. You use arrow keys to move the cursor around — this should all work. Then, you choose W, A, S, or D to choose whether you are in Water mode, Metal mode, Sand mode, or Delete mode. When you hit the space bar, a Water, Metal, or Sand is created, or whatever the cursor on is deleted, if in Delete mode.

Note that if you move the Cursor on top of a Metal and go into Sand mode, you can replace a metal with a sand — a little strange, but don’t worry about that — it isn’t a bug.

Step 1. What you need to do

Look at the code in the file FallingSand.cpp and search for the word TODO. You need to follow the instructions and implement code below each TODO comment. There are 5 places where you have to implement the code.

In each place, you’ll get practice with looping over a 2-dimensional grid, using the switch statement, using many if statements, and calling functions from the Bridges API. For those API calls, there are other examples in the code already which you should refer to.

Submit

In VS Code, click on the Source Control icon on the upper left and type in a commit message, then click the checkmark icon to submit your code. Go through the various pop-up boxes to commit and sync your changes to your repo.

Grading Rubric

This project is worth 20 pts: