ENGR 2730: Computers in Engineering
Homework 2: Word Scramble Game (3⇡ Robot) Due: Tuesday, September 25, 2018 at 11:59 p.m.
1 Background
In this homework, your group will be implementing the simple word scramble game (that you implemented
in Homework 1) on the robot. In the Word Scramble Game (WSG), scrambled words are presented to the
user. It is then up to the user to provide guesses until they have provided the correct, unscrambled answer.
The game has three di↵erent “levels” of di�culty available for the user to play: easy (five letter words),
medium (six letter words), and hard (seven letter words).
When the game first begins, the user will select the number of rounds they would like to play of the
WSG. Then, at the start of each round, the user will enter which level they would like to play: 5, 6, or 7
(where 5 corresponds to playing with five letter words, 6 corresponds to six letter words, and 7 corresponds
to seven letter words). A random word is then selected from the appropriate word list and is scrambled
before being presented to the user for guessing. Each round keeps track of how many attempts it took for
the user to guess the correct word. After the user has played as many rounds as they originally specified of
the WSG, the game should end.
This is a group and robot based assignment. Your group should have all of the necessary files to get
started within your GroupXNN folder available on SVN.
2 The 3⇡ Robot Word Scramble Game
The intent of this assignment is to make a hand-held electronic game where the 3⇡ robot is used as the
game console and controller to play the WSG. Due to the small computational resources available, the robot
development environment does not provide some of the normal standard template library features that are
available in a typical C++11 development environment (i.e., std::cout, std::cin, std::vector, std::string are not
available on the robot). You will need to use alternate functions, or write your own functions, to accomplish
tasks that would otherwise use those capabilities. For example, you will have to use character arrays instead
of strings, and you will have to use the robot’s LCD screen to display text instead of cout-ing to the console.
For this hand-held game assignment, a prompt requesting the total number of rounds to be played is
first presented to the user, before game play begins. The options should be to play 2 rounds, 4 rounds, or 6
rounds of the WSG. The user should see these available options and use the robot to make their selection.
Then, for this assignment you need to do at least the following:
• Implement a GameConsole class (in GameConsole.h and GameConsole.cpp) that encapsulates the
necessary manipulations of the 3⇡ robot. The “#include ” directive should only
exist in the GameConsole.cpp file. Any functions that you need from the 3⇡ library must be
wrapped in the GameConsole class interface. Overall, your program should only create a single
GameConsole object (you only have 1 robot!). This object will be used to perform. the updating
of the robot’s display, get and manage user input, and control the robot’s functionalities, in general.
• Write a function called “getNumberOfRoundsFromUser(GameConsole consoleRef)” in WordScram-
bleGame.cpp. This is used before the game begins to prompt for the number of rounds to be played.
• Implement the WSG’s logic using the GameLogic class (comprised of the files GameLogic.h and Game-
Logic.cpp). The GameLogic class definition is given in GameLogic.h. You need to implement the func-
tions of the class within GameLogic.cpp. This class is responsible getting words from the word list,
scrambling, interacting with the user (via the robot), and performing all other necessary computations.
Note that some of the logic of these functions may be similar to your functions in Homework 1.
• Note in GameLogic.h that there is a private GameConsole member attribute, and it is a pointer. This
console should point to the single GameConsole object that was created before gameplay began. You
should implement and use the function “setGameConsole” of the GameLogic class to assign this console
pointer to the single GameConsole object that was created.
• In your GameLogic class implementation, any time you need to use the robot (for input or output),
you should ONLY use the console pointer. DO NOT create a new GameConsole object, as this will
violate several of the above instructions, specifically to only create a single GameConsole object.
1
ENGR 2730: Computers in Engineering
Homework 2: Word Scramble Game (3⇡ Robot) Due: Tuesday, September 25, 2018 at 11:59 p.m.
• The main logic for the game on the robot:
1. Prompt the user for the number of rounds to play: 2, 4, or 6.
2. Each round, prompt the user which level they’d like to play: 5, 6, or 7.
3. Play the appropriate round(s) for as many rounds as the user specified.
4. When game is over, call a function called “showShutdownMessage(????)” that alternates display-
ing “Shutdown/Now” and “Shutdown/Please” once every second. Recall, this function should
NOT create a new GameConsole object in order to print to this message as only one GameCon-
sole object is allowed in your program.
2.1 Demo Program
A binary version of one possible solution to the game play is provided as a special CLion target. If you
flash the robot with the “flash ReferenceSolutionWordScrambleGame” target, one potential solution to this
problem will be deployed and ran on the connected robot. Note that you are not required to make your
program look exactly like the reference solution. You can improve upon this example solution. Also note
that most of the grading is related to the quality of your code and general quality of the result. We do not
provide points for exactly mimicking the reference solution displays.
2.2 Test Files
There are two provided files that may be helpful to test your GameConsole implementation as you try to
complete this homework:
• Step1 testPrinting.cpp – Contains a program to test the printing part of the GameConsole class
• Step2 testButtons.cpp – Contains a program to test the button input part of the GameConsole class
We will not be grading contents of these files for correctness, but you are encouraged to modify and expand
upon these testing files to verify that your classes are performing well before writing the main program in
WordScrambleGame.cpp.
2.3 General Requirements
You have a lot of flexibility in how you will exactly implement this game for this homework assignment, but
the following provides some general requirements:
• The word lists are provided to you in “utilityFunctions.h” and are comprised of three di↵erent character
arrays, one for each of the levels. You will use these constants within your GameLogic.cpp functions.
• In the GameLogic class, you need to implement a function that selects a word from the appropriate
word list. One input to this function is the index of the word to select. For example: if the provided
index is 2, the third word from the list should be returned. The index provided to the function should
be randomly generated so that words are chosen at random. Note that you do NOT have to seed
the random number for this homework. This is already taken care of for you during the battery
check startup operation.
• In the GameLogic class, you need to implement a function that scrambled (i.e., shu✏es) a word by
traversing the character array and swapping each element with a randomly selected element in the
array. This function will be called every round after a word is randomly selected.
• In the GameLogic class, you need to use the pointer to the assigned GameConsole object to display
input options (i.e., letters) and obtain an answer from the user. To enter an answer, users are presented
with a list of letters which they cycle through one at a time. This list of letters should essentially be
the scrambled word. Users can press the C button to advance to the next letter choice or the A button
to go back a letter. The B button selects the current letter as chosen and moves on for the user to
2
ENGR 2730: Computers in Engineering
Homework 2: Word Scramble Game (3⇡ Robot) Due: Tuesday, September 25, 2018 at 11:59 p.m.
select their next letter; this repeats until the user has chosen the appropriate number of letters. For
example: if the word to guess is “hawks,” the scrambled word presented to the user on the first line of
the robot might be “swkha.” Then the second line would show the user the character “s.” If the user
presses the C button, the character would change to “w” or if the pressed the A button it’d be “a,”
etc. The user can use this method to cycle through the characters of the scrambled word until “h” is
properly selected; this is when they’d then press the B button. Then, this would “save” the “h” as
being entered. The user would then do the same to select the second character, where initially, “hs”
would be on the screen. If the C button was pushed, “hw” would be on the screen, or if the A button
was pushed, “ha” would be on the screen. The user would then press B once “ha” was on the screen,
and they’d continue this way until they’d entered the appropriate number of letters. Please flash the
provided demo program to your robot to try out this input functionality for yourselves.
• In the GameLogic class, when you get an answer from the player, you should see if it has been correctly
unscrambled. Keep allowing users to guess solutions until they’ve solved the word correctly. You need
to keep track of how many attempts it took a player to complete each round.
• You must implement the game logic in the GameLogic.h and GameLogic.cpp files.
• You must implement the game console class functions from GameConsole.h within the GameCon-
sole.cpp file. For reference on how to implement these functions for interacting with the robot, please
refer to the robot-based mini-assignments and the examples within your GroupXNN folder.
• In addition to having a standard documentation block and providing comments throughout your pro-
gram, you must provide high-level pseudocode to explain your approach to solving the problem (as
comments in the code) at the level of detail that someone with su�cient C++ knowledge would be
able to implement your program. The pseudocode should provide guidance to understand the approach
taken, and not a description of the code itself.
3 General Grading Guidelines
Documentation and pseudocode (10 points)
• 5 points: including programmer(s), filename, and description aspects of top documentation block (since
you need to also include pseudocode algorithm overviews, the description can be brief here)
• 5 points: Easy to understand code. This includes reasonable pseudocode comments throughout the
program (including having documentation blocks for any functions you may write yourself). Using
good variable names, function names, and indentation style. is an integral part of your documentation
process. Comments that redundantly describe the syntax of code statements are unnecessary. (For
example “int i=3; // set i to 3” has a useless comment.)
Program (90 points)
• 20 points: Correct implementation of the GameConsole functions (in GameConsole.cpp).
• 20 points: Defining and implementing a well constructed GameLogic class.
• 30 points: Implementing the game and game logic correctly as described in this document.
• 5 points: Appropriately ending and displaying the end game message after the specified number of
rounds have been played.
• 15 points: Code organization (not repeating a large amount of code), meaningful variable names, good
whitespace formatting, and ease of use of your program.
3
ENGR 2730: Computers in Engineering
Homework 2: Word Scramble Game (3⇡ Robot) Due: Tuesday, September 25, 2018 at 11:59 p.m.
Extra credit (up to 10 points)
Keep track of which letters the user has already entered and only let them select their next letter from a list
of unchosen letters. Continuing our example given above in the last bullet of Page 2, let’s again consider
the correct word is “hawks” and the user has been presented with the word “swkha” to unscramble. After
entering two letters, the user’s entered “ha.” Now, when going to enter their third letter, the second line
would display “has.” If the user pressed A to go back one letter, in the normal solution, the display would
read “haa,” however, in the extra credit version, since the user has already entered the one “a” character in
“hawks,” the display would read, “hak.” Note that both the “a” and “h” characters were skipped because
they’d already been entered.
One way to think about this is that you have two lists (i.e., arrays). One array is the text that’s already
been chosen by the user. The other array is the letters that are left to be selected by the user. Conceptually,
if both of these lists were combined to form. one list, the resulting list might resemble the scrambled word.
Submission
The final version of your group’s program must be committed to your GroupXNN folder in SVN by Tuesday,
September 25, 2018 at 11:59 p.m.