On this page:
Intro
Recall
Imperative Worlds
6.12

Lab 15: State in Worlds

Intro

You’ll work in this lab with your lab partners.

The two of you will work as a team to solve problems. At any time, one of you will be the Head and the other will be the Hands. The Head does the thinking and the Hands does the typing. Hands type only what the Head tells them to, but you’re free to discuss any issues that pop up. You should switch off during the lab to make sure each of you get practice problem solving, dealing with syntax, and getting finger exercises on the keyboard.

You can start this lab with this project skeleton or your own completed implementation of Lab 9: Bouncy Ball™.

Recall

In Lab 9: Bouncy Ball™ we made a simple game with a bouncy ball.

We made that game with the javalib.worldimages and javalib.funworld libraries. The functional worlds provided by javalib.funworld allow us to program much like we did with big-bang from the student languages last semester.

In this lab we’ll use javalib.impworld, where we change the world not by creating new worlds from scratch but by mutating the already present world.

Imperative Worlds

We’ve provided you a working copy of the bouncy ball game. Once you’ve opened the project skeleton (or made a copy of your own lab 9), import the impworld instead of funworld.

import javalib.impworld.*;  // previously: import javalib.funworld.*

Your IDE will highlight a number of errors now present due to the mismatches between the imperative and functional worlds.

The API changes you need to focus on are as follows:

Make sure the order in which operations are performed doesn’t change. Specifically, the bouncy ball should always be drawn on top of all other features in the game (including the score, enemies).