Gettysburg College

CS 111
Computer Science I

Fall 2025

Assignment 5

Due: Thu, Oct 2, by 11:59pm

General Description

The goal of this assignment is to create an app for the popular word guessing game. The player is presented with a secret word, from which some letters are missing (initially all letters are missing) and the player is given a fixed number of attempts to guess all letters in the secret word.

The focus of this assignment is on for-loops and string processing.

Here is a summary of how the app works. The app waits for the player to guess a letter. For each guess there are three cases to consider (not necessarily in this order): In each of the above cases the app also plays the relevant ringtone.

The game terminates after one of the following situations:

As soon as the game is over the app displays an appropriate message, reveals the secret word on the canvas, and plays the corresponding ringtone.

Preliminaries (New DrJava)

Download the new version of DrJava:

This DrJava version includes:

General Expectations

Required Methods

As part of your solution you are asked to implement and utilize the following methods:

App Stages

Make sure to implement the above methods first and test them thoroughly. Submit your test cases as a commented section in your program. Make sure to test each method with (a) the empty string; (b) one-letter string; (c) two-letter string; (d) at least of couple of examples of multi-letter string.

Each stage represents a simpler version of the app. Your submission should only include the final version (last stage).

Eventually, the player should be able to select a letter by tapping on the corresponding circle. However, in the beginning it might be easier to show a box in which the player types the letter:

char varName = canvas.readChar( "Pick a letter" )
When everything works use the code from CoinsGameApp to get the index of the tapped circle -- then you can look up the letter in the alphabet at that index. You won't need to use Y-coordinate or number of taps.

Stage 1

For this stage assume that:

For this stage assume that the player always guesses correctly. This means that on each turn:

Here is a possible starting point for method playGame. For this stage the game should stop when the player guesses all letters correctly:

Hint: If you are having trouble with method equalStrings, you can use hasLetter to determine if the player guessed the secret word, since the letter/symbol '*' will not be in the guessed word. However, the final version should use equalStrings where appropriate.

void playGame()
{
    // String secretWord = canvas.getRandomColor().toUpperCase();
    String secretWord  = "SEASHELL";
    String guessWord = makeBlankString( 8 );
    String alphabet = "ABC...Z";
    double radius = 13.5;

    //
    // any other variables you need
    //

    while ( ???? )
    {  
         //.................................................................
	 //... the rest of the code goes here: .............................
	 //... * clear screen, draw game, wait for input, update strings ...
	 //.................................................................
	 //
	 //... see the notes above in replaceLetter and revealLetter .......
	 //... on how to overwrite/change a string with a new string .......
    }

    // ... 
}

Note: You need to keep track of the letters that have been guessed so far so that white circles start to appear. To accomplish this, for each new guess replace in the alphabet the guessed letter with '*' (you have a method for this). For the later stages you will know whether a particular letter has been used previously, by checking if it is in the alphabet.

Stage 2

This stage can be skipped and completed later at any point.

Modify playGame so that letter is selected via touch on the screen. Adapt the touch selection code (minor change necessary) from CoinsGameApp. Note that the y coordinate and number of taps are not used here.

Stage 3

Modify playGame so that the player is allowed 6 incorrect attempts. Play the game with a mix of correct and wrong guesses and see if it stops when (i) there are no attempts left, (ii) the word was guessed. Tell the player whether the game was won or lost.

Stage 4

Modify playGame so that the correct emoji is displayed as the player accumulates errors.

Save the following images (right-click, save as...) in folder    SecretWordApp/res/raw:


errors0.png

errors1.png

errors2.png

errors3.png

errors4.png

errors5.png

errors6.png

Write the following method:

Stage 5

Modify playGame so that the correct ringtone is played on each move and also at the end of the game.

Save the following ringtones (right-click, save as...) in folder    SecretWordApp/res/raw:

correct.wavplayed on correct guess
wrong.wavplayed on incorrect guess
used.wavplayed on repeated guess (covered circle)
won.wavplayed on successful game
lost.wavplayed on unsuccessful game

To play a ringtone use:

canvas.playAudio( "audio-name.wav" );

Stage 6

Modify playGame so that the secret word is a randomly chosen color in upper-case letters. What else needs to change now that the secret word is no longer the 8-letter "SEASHELL"?

Currently the radius is computed for 26-letter alphabet. Make the necessary modifications, so that the game can be played in other languages that have a different number of letters.

Write the following method:


What to turn in

Turn in the Java code for the app in the Assignment 5 dropbox:

Make sure your code is saved. If when you close DrJava it warns you that the file is not saved, save it and re-upload the code.