On this page:
Setting the scene
9.1 Tasks
9.1.1 Part1:   Creating and rendering the board
9.1.2 Part 2:   Gameplay and resetting the game
9.2 Extra credit
8.5

Assignment 9: Flood It

Goals: Design a game with mutable world state, ArrayLists, mutable linked data structures, and loops.

You will be using the Impworld library — short for imperative, in this case meaning uses mutation. Make sure that you include the javalib library in your project in addition to the tester library. At the top of your file, include
import java.util.ArrayList;
import tester.Tester;
import javalib.impworld.*;
import java.awt.Color;
import javalib.worldimages.*;

You will submit this project in two parts. For Part 1 you must have completed the task of Creating the board which includes connecting cells and rendering the game.

For Part 2 you must complete all of the tasks, Rendering the game plus Gameplay and Resetting the game.

Part 1 Due: Thursday March 30th at 9:00pm

Part 2 Due: Thursday April 6th at 9:00pm

Setting the scene

In this game players are trying to manipulate a grid of colors so that all of the cells are the same color. The player starts in the upper left corner and by clicking various colors they can change the color of that corner which can increase the size of the area they control.

An example of this game is available for you to play here.

9.1 Tasks

Here is a list of tasks you will need to complete to implement this game.

9.1.1 Part1: Creating and rendering the board

Your primary data structures may look like the following (you are free to add to, remove from or change this although you must use ArrayLists):
// Represents a single square of the game area class Cell {
// In logical coordinates, with the origin at the top-left corner of the screen int x;
int y;
Color color;
boolean flooded;
// the four adjacent cells to this one Cell left;
Cell top;
Cell right;
Cell bottom;
}
 
class FloodItWorld extends World {
// All the cells of the game ArrayList<Cell> board;
}

You will need to create a two-dimensional grid of these Cells to represent the board.

Since the game should be easily configurable, you should have a constructor that takes in two numbers: the size of the board and the number of colors.

Because the size of your board is determined by this constructor, you cannot simply hard-code lists of data, because they may be of the wrong size. Instead, you’ll need to use loops and ArrayLists.

You will need to implement the makeScene method in the FloodItWorld class to be able to render the game state. Note that although makeScene returns a WorldScene in the impworld library, the placeImageXY method is now a void method. (The other event handlers, which you will need to use in Part 2, are also void methods now.)

For Part 1, as always, your code should be well-designed and well-tested.

9.1.2 Part 2: Gameplay and resetting the game

Player mechanics: The player should be able to click on each square to change the color. Players win if all of the squares are the same color before they run out of steps. You should make the game challenging enough so that it is not too easy to win but also not impossible.

It will be useful to think of the game as having two world states, one which allows you to click on a tile and begin flooding, and the other which is in the process of flooding. Here are some details you will need to implement:

9.2 Extra credit

If you want to earn extra credit on this assignment, you can complete any number of enhancements.

Enhancements will only count towards extra credit if they are convincingly and thoroughly tested. Moreover, the rest of the game must be at least as well tested — you will not receive extra credit if the required parts of the game are not designed properly or do not work properly.

Here are some examples:

You are welcome to think of other enhancements to the game. Have fun!