Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this assignment, we will be mimicking the Wordle game with a simpler version, using the C++ techniques and tools that we have learned so

In this assignment, we will be mimicking the Wordle game with a simpler version, using the C++ techniques and tools that we have learned so far, especially functions. Specifications: Your C++ program (still a single file) should be designed to be played by two players instead of one. The main objective is to have one of the players guess the five-letter word correctly. The program should first prompt Player 1 to enter the word for Player 2 to guess, after asking for their names of course. At the start of the program, it should also ask Player 1 to enter the friendship level, a higher value means a closer friendship bond with Player 2. Friendship level should have a range of value between 0 and 100, inclusive. If Player 1 inputs something outside of the acceptable range, then the program should keep prompting the player until a proper value is entered.

Player 2 will have a maximum of six attempts to guess the word correctly. In each attempt, the program should prompt Player 2 to enter their word, and then see if the entered word matches with the key. If its an exact match, then the program should output a congratulations message. However, if its not a perfect match, then the program should provide some useful feedback as in the original game using the following notations:

Notation @.@ should be used if an input letter is not a part of the key

Notation ^-^ should be used if an input letter is a part of the key but is not in the right position

Notation ^o^ should be used if an input letter is a part of the key and is at the right position

For example, if the key word is beard and Player 2 entered bound as the first attempt, then the feedback provided should be:

You entered BOUND. Nice try, keep going!

B: ^o^

O: @.@

U: @.@

N: @.@

D: ^o^

The completion of all six attempts concludes a round. If Player 2 guessed the key word correctly, then the friendship level value should be correspondingly increased by the number of attempts Player 2 took to get to the correct word. Note that the maximum value friendship level can reach is 100. Next, the program should ask Player 1 if they want to begin a new round. If no, then the program will then keep asking Player 1 if they want to start a new round with a different Player 2. If Player 1 inputs no, then the program will exit smoothly. Make sure to have proper input validations for these prompts too.

Functional requirement 1: The greet() function

This functions only purpose is to greet the users when the program is first run. It should not need any parameters or return anything. Also, it should only be called once throughout the program. A sample greet message that would be appropriate is provided as followed:

Welcome to Wordle For Friends!

Functional requirement 2: The validateWord(word) function

This function should have one parameter being the word entered by the players. It takes the input word and checks whether it is a valid 5-letter word with only alphabetical characters. If the word is not valid, it should prompt the user to enter the word again until a valid word is entered. At the end, this function should return the validated word back to the caller.

Functional requirement 3: The displayFeedback(key, guess) function

This function takes the key word and the current guess word as parameters and outputs the corresponding feedback for the guess, as described in the assignment description. It should not return anything.

Functional requirement 4: The printGameSummary(player1, player2, oldLevel, newLevel) function

The purpose of this function is to output the game summary at the end of each round. This function should have four parameters: one for the name of Player 1, one for the name of Player 2, one for the original friendship level before the round begins, and one for the current friendship level at the end of the round. A sample output from this function is provided below. Again, it does not have a return type.

End-of-Round Game Summary

Player 1: Frank

Player 2: Fiona

Initial friendship level: 10

Current friendship level: 13

Notes

If the parameters and return type of a function is not specified, then it is your responsibility to determine the most appropriate function signatures for them.

You may create additional custom functions for this assignment as you see fit.

You may use functions from other C++ libraries if 1) they are explicitly stated in the assignment or 2) the usage of the library functions has been thoroughly introduced in class. Otherwise, the usage of other functions is prohibited without the permission of your instructor.

DO include input/range validations as long as they are appropriate. While input data type validation is not required for this assignment, it is good practice to validate the data values for range.

This program should trust no one. When prompting Player 1 for the key word, we need to check a couple things.

First, we need to ensure that the key word is a valid five-letter word (you may find this string function to be useful). If this constraint is violated, then the program should keep prompting Player 1 for the proper key word until one is entered.

Second, besides checking for the proper length of the key word, we also need to make sure that the key word is valid, i.e. each letter of the word is an alphabet. How do you do that? Well maybe this function can help you (depending on your C++ compiler, you may need to include the library).

The same set of rules applies to Player 2 too when promoting for the attempted word.

For this assignment, you may also find it to be useful to know how to manipulate (i.e. read/write) each letter in a string variable. One easy way to do that is through the use of the at function for the string data type. A sample usage is provided here:

#include

#include

using namespace std; int main(){

string str = LAUGH;

// note: the first character in a string is

// located at index position 0 (not 1)

for(int index=0; index

cout << str.at(index) << endl;

}

}

To make this assignment a bit easier for when you are checking if two words are an exact match, you can expect all of the input words from the players to be in uppercase. That is, you dont have to perform input validation to check if the words contain any lowercase letters.

Test the program with different inputs. This will help you ensure that the program is functioning as expected and will also help you identify any bugs or errors.

Read the error messages carefully if the program is not working as expected. Understanding the error messages will help you to identify and fix the problem.

Dont forget to use an adequate amount of comments to explain your code and make it easy to understand.

You must use proper indentation (two whitespaces) to make the code more readable and easy to understand.

Finally, don't hesitate to ask for help from the instructor or TA if you are having trouble with the assignment.

Sample Output

A sample output is provided below for your reference. However, your actual program output does not have to match the sample exactly. Make sure that yours is nicely formatted and is readable to anyone.

Welcome to Wordle For Friends!

Player 1, please enter your name: Frank

Welcome, Frank!

Now, Player 2, please enter your name: Fiona

Welcome, Fiona!

Frank, please rate the friendship level you have with Fiona (enter an integer value in [0, 100]): 800

The friendship level you input is invalid!

Please enter the friendship level again (an integer value in [0, 100]): 80

Hooray, thats an admirable friendship between you two!

Let the game begin now!

Wait Frank, I need the key word from you (yes, you may whisper into my ears and remember, it has to be a valid five-letter word all UPPERCASE): FAN

Seriously? Your input word is 3 letters long! Dont make me quit on you right now

Please enter the key word again (remember, it has to be a valid five-letter word all UPPERCASE): A1B2C

Dont make me arrest you! Your input word is contaminated with non-alphabet characters

Please enter the key word again (remember, it has to be a valid five-letter word all UPPERCASE): SOUND

Got it! The key word is now securely processed and saved.

Get ready, Fiona! Its now time to Wordle with Frank!

You will have a total of 6 attempts to guess the word correctly.

This is your attempt #1, Fiona, please enter a valid five-letter word (all UPPERCASE): CAT

Seriously? Your input word is 3 letters long! Dont make me quit on you right now

Please enter your guessing word again (remember, it has to be a valid five-letter word all UPPERCASE): 2CATS

Dont make me arrest you! Your input word is contaminated with non-alphabet characters

Please enter your guessing word again (remember, it has to be a valid five-letter word all UPPERCASE): KITTY

You entered KITTY. Nice try, keep going!

K: @.@

I: @.@

T: @.@

T: @.@

Y: @.@

This is your attempt #2, Fiona, please enter a valid five-letter word (all UPPERCASE): CLOTH

You entered CLOTH. Nice try, keep going!

C: @.@

L: @.@

O: ^-^

T: @.@

H: @.@

This is your attempt #3, Fiona, please enter a valid five-letter word (all UPPERCASE): PONDS

You entered PONDS. Nice try, keep going!

P: @.@

O: ^o^

N: ^-^

D: ^-^

S: ^-^

This is your attempt #4, Fiona, please enter a valid five-letter word (all UPPERCASE): SOUND

You entered SOUND. Congratulations, SOUND it is!

Round 1 Summary

Player 1: Frank

Player 2: Fiona

Friendship Level: 80 -> 84

Frank, do you want to play another round with Fiona (Y/N)? N

OK, Frank. Your final friendship level with Fiona is 84 after 1 round(s) of Wordle.

Remember, a real friend is one who always Wordles with you when the rest of the world wont!

Okay Frank, do you want to start a new game with a different player then (Y/N)? N

OK, good bye, Frank! See you soon, Wordle Wordle!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Progress Monitoring Data Tracking Organizer

Authors: Teacher'S Aid Publications

1st Edition

B0B7QCNRJ1

More Books

Students also viewed these Databases questions

Question

Define ten roles that managers perform in organizations.

Answered: 1 week ago