Assignment 9: Flood It
Goals: Design a game with mutable world state, ArrayLists, mutable linked data structures, and loops.
import java.util.ArrayList; import tester.*; import javalib.impworld.*; import java.awt.Color; import javalib.worldimages.*;
You will submit this project twice. 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 31st at 9:00pm
Part 2 Due: Tuesday April 12th 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.
When you are in the process of flooding your on-tick function should flood only the squares adjacent to those you have already flooded. This will produce the "waterfall" effect shown in the game.
If a player clicks on a square that is the same color as the area they control you should not flood the area, since it will produce no change.
A player is allotted a certain number of clicks in which they can flood the grid. If they fail to do so in the given number of clicks, they lose. When a player loses (or wins) you should let them know.
The maximum number of steps allowed should be proportional in some way to the size of the board and the number of colors so that the game is challenging enough.
9.1 Tasks
Here is a list of tasks you will need to complete to implement this game.
9.1.1 Creating the board
// 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.
We have not discussed the keyword static in this course, but you will learn more about it in OOD.
class FloodItWorld extends World { // Defines an int constant static int BOARD_SIZE = 22; ... }
Because the size of your board is determined by this constant, 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.
9.1.2 Gameplay
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.
9.1.3 Resetting the game
Use the ‘r’ key to reset the game and create a new board.
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 —
Here are some examples:
Enhancing the graphics.
Keeping score: how many steps does the player take before reaching the goal? Lower scores are better... You’d need to enhance the display to render the score so far somehow.
Keeping time: display a timer to keep track of the time since the beginning of the game.
You are welcome to think of other enhancements to the game. Have fun!