On this page:
9.1 Instructions
The javalib library
Connections
9.2 Extra credit
A note about randomness
Submission notes
8.5

Assignment 9: Connections

Goals: Design the Connections game using mutable worlds, ArrayLists and loops

9.1 Instructions

This is a partner assignment.

Make sure you follow the style guidelines that we enforce. For now the most important ones are: using spaces instead of tabs, indenting by 2 characters, following the naming conventions (data type names start with a capital letter, names of fields and methods start with a lower case letter), and having spaces before curly braces.

You will submit this assignment in two parts by the deadlines using the online submission system. You may submit as many times as you wish. Be aware of the fact that close to the deadline the system may slow down to handle many submissions - so make sure to submit at least a few minutes before the deadline.

As always, be sure to follow the Design Recipe and avoid accessing fields of fields, getters, type-checking and casting. Dynamic dispatch is your friend!

You will submit this project twice. For Part 1, you must have completed the tasks of defining your world class with any auxilary classes needed and rendering the game.

For Part 2, in addition to rendering the game, you must complete the rest of the gameplay, plus being able to reset the game.

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

Part 2 Due: Monday March 31st at 9:00pm

The javalib library

The javalib library provides the support for the design of interactive games and creating images composed by combining geometric shapes as well as image files. See The Image Library for more information.

To use the library, download the javalib file above and add it to your project the same way you have added the tester library.

At the top of the .java file where the library is used, add the following import statements:

import tester.*; // The tester library import javalib.worldimages.*; // images, like RectangleImage or OverlayImages import javalib.impworld.*; // the abstract World class and the big-bang library import java.awt.Color; // general colors (as triples of red,green,blue values) // and predefined colors (Red, Green, Yellow, Blue, Black, White)

Note that you should use impworld which uses mutation in all of the event handlers except for makeScene.

Connections

Implement the game Connections. Connections is a word game where the player must group 16 words into 4 groups that share a common theme. Each group is assigned a color: yellow, green, blue or purple. The yellow category is considered straightforward and the categories increase in difficulty where purple is considered to be the most tricky. Each group has a short label describing what the words had in common.

For instance, a game from last year presented the following words:

The heart with the number 4 indicates that there are 4 tries left. You should also include some indication of the number of tries left, although you are not required to use a heart image.

After an unsuccessful try, the number of tries should decrease by 1 (provided there is more than 1 try left):

If there are no more tries left, the game should end. The player should be able to reset the game by pressing the ’r’ key.

If the player has made a successful guess, the grouped words should be shown with the label and color for the group.

To win this game, the words needed to be grouped in the following 4 groups within 4 tries:

This website holds an archive of past Connections games: https://connectionsplus.io/

For this assignment, you should have at least 5 sets of 16 words to play with. You can take these sets from the archive or you can make up your own. When the game starts, it chooses one of the sets randomly.

Here are some tasks to help you get started:

Part 1:

  1. Review the The Image Library documentation to understand how impworld works.

  2. Decide if you need to define any constants for the game. These are things that do not change throughout the life of the program, such as height and width of the game’s background. Review Lecture 10: Customizing constructors for correctness and convenience about defining constants.

  3. Design the ConnectionsWorld class. This should extend the World class from javalib. What fields should be included in this class? The field(s) of this class will represent what can change in the world program. For this assignment, you should use ArrayLists and loops.

  4. Design and implement the makeScene method which is required in the ConnectionsWorld class. This will draw the current state of the world. Note that the makeScene method is the only one event handler in impworld that is not a void method, however placeImageXY for WorldScene is void.

Part 2:

  1. Decide which events your ConnectionsWorld class should handle.
    • Does the game need to respond to the passage of time? Then you need to override onTick in the ConnectionsWorld class.

    • Does the game need to respond to key presses? Then you will need to override one of the key handler methods.

    • Does the game need to respond to mouse clicks Then you will need to override one of the mouse handler methods.

    • Review the The Image Library to see the documentation for the event handler methods that are available.

  2. Your game should end if all words have been grouped correctly or the player has run out of tries. There should be a final scene indicating whether the player has won or lost the game. Study The Image Library documentation for information about ending world programs.

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!

A note about randomness

There are two ways to generate random numbers in Java. The easiest is to use Math.random(), which generates a double between 0 (inclusive) and 1 (exclusive). You can multiply this number by some integer to make it bigger, then coerce to an int to produce a random integer in the range you wish. However, this is not easily testable: you’ll get different random values every time.

The better way to generate random numbers is: First, import java.util.Random at the top of your file. Next, create a new Random() object, and use its nextInt(int maxVal) method, which will give you a random integer between zero (inclusive) and maxVal (exclusive).

This is known as a "pseudorandom number generator", since the numbers aren’t really random if they can be reliably repeated...

The reason this is better is because there is a second constructor, new Random(int initialSeed), which has the property that every time you create a Random with the same initial seed, it will generate the same "random" numbers in the same order every time your program runs. You should therefore design your world classes with two constructors:

Submission notes

Include an additional file in your submission for part 2:
  • UserGuide.txt should be a short file describing how to play the game. If you did any extra credit, add descriptions of the features you added to make it easier to grade.

Be sure to include all your source files and all your image files (if you have any) in your submission, or else we won’t be able to run your game. If you have multiple files, you should submit the files as a single .zip file. Please only include relevant files in the zip file.