Answered Essay: Your Simon game must have the equivalent of three "buttons." We recommend using integers (e.g., 0, 1, 2) for this so that each roun

Code in C++ !!

Your Simon game must have the equivalent of three buttons. We recommend using integers (e.g., 0, 1, 2) for this so that each round involves printing a sequence of numbers and having the user repeat this sequence, one number at a time, and then having the user type an additional number, but if to use characters (e.g., r, ‘g, ‘b), you miay use them instead. To make your button equivalences more clear to a user, please have your program start with a message similar to the following: Welcome to the Simon game. Sequences wl be made up of numbers 0,1, and 2. you prefer The first round of your game must present only one number (or character) for the user to repeat. The user should be asked to repeat this sequence and to add an additional number. Each subsequent round must present the same sequence to the user as that in the prior round with two additional numbers (or characters) at the end: (1) the number/character that the user added to the end of the sequence in the prior round and (2) a randomly generated new number/character. Note that at the beginning of round n, the sequence that will be presented to the user should be of length 2n and at the end of the round (when the user types a sequence back), the sequence length should be 2n (as the user has added a number to the sequence) . The game must end as soon as a number (or character) in the sequence is incorrect. For example, if the user needs to repeat a sequence of length 5, but enters an incorrect number in the middle of the sequence, the game should end at that point rather than waiting until the user enters all numbers The game must also end if the user selects an ineligible number to be added to the end of the sequence (i.e., trying to repeat the last number or adding a number that doesnt exist in the game) Your Simon game must be able to last for at least 6 rounds. After 6 rounds, it is okay to directly say that the user wins rather than requiring the game to continue until the user fails. Hint: this means that you can specify the maximum length of any given sequence in advance. Use this to your advantage in designing your program (e.g., by declaring an initial maximum-length array before the rounds begin) Each time you run the program, the user should be presented with a different sequence (so you will need to be able to randomly generate the numbers to be filled into the computer-generated portions of the sequence)

Your Simon game must have the equivalent of three “buttons.” We recommend using integers (e.g., 0, 1, 2) for this so that each round involves printing a sequence of numbers and having the user repeat this sequence, one number at a time, and then having the user type an additional number, but if you prepare to use characters (e.g., ‘r’, ‘g’, ‘b’), you may use them instead. To make your button equivalences more clear to a user, please have your program start with a message similar to the following: “Welcome to the Simon game. Sequences will be made up of numbers 0, 1, and 2.” The first round of your game must present only one number (or character) for the user to repeat. The user should be asked to repeat this ‘sequence’ and to add an additional number. Each subsequent round must present the same sequence to the user as that in the prior round with two additional numbers (or characters) at the end: (1) the number/character that the user added to the end of the sequence in the prior round and (2) a randomly generated new number/character. Note that at the beginning of round n, the sequence that will be presented to the user should be of length 2n-1 and at the end of the round (when the user types a sequence back), the sequence length should be 2n (as the user has added a number to the sequence). The game must end as soon as a number (or character) in the sequence is incorrect. For example, if the user needs to repeat a sequence of length 5, but enters an incorrect number in the middle of the sequence, the game should end at that point rather than waiting until the user enters all numbers. The game must also end if the user selects an ineligible number to be added to the end of the sequence (i.e., trying to repeat the last number or adding a number that doesn’t exist in the game). Your Simon game must be able to last for at least 6 rounds. After 6 rounds, it is okay to directly say that the user wins rather than requiring the game to continue until the user fails. Use this to your advantage in designing your program (e.g., by declaring an initial maximum-length array before the rounds begin). Each time you run the program, the user should be presented with a different sequence (so you will need to be able to randomly generate the numbers to be filled into the computer-generated portions of the sequence).

Expert Answer

 

#include <iostream>

#include <time.h>

#include <stdlib.h>

#include <string>

#include <ctime>

#include <cerrno>

using namespace std;

/**

* Custom sleep funtion for linux.

* @param msec Number of milliseconds to sleep.

*/

void my_sleep(unsigned msec)

{

struct timespec req, rem;

int err;

req.tv_sec = msec / 1000;

req.tv_nsec = (msec % 1000) * 1000000;

while ((req.tv_sec != 0) || (req.tv_nsec != 0)) {

if (nanosleep(&req, &rem) == 0)

break;

err = errno;

// Interrupted; continue

if (err == EINTR) {

req.tv_sec = rem.tv_sec;

req.tv_nsec = rem.tv_nsec;

}

// Unhandleable error (EFAULT (bad pointer), EINVAL (bad timeval in tv_nsec), or ENOSYS (function not supported))

break;

}

}

int main ()

{

// variable declarations

string my_seq = “”;

string user_seq = “”;

char colors[4];

int round_now;

// Initialization

round_now = 1;

srand(time(NULL));

colors[0]=’R’;

colors[1]=’G’;

colors[2]=’B’;

colors[3]=’Y’;

// loop of 15 round_nows

while (round_now < 16) {

// Displays and erases my_sequence

my_seq += colors[rand()%4];

cout << my_seq << flush;

my_sleep (5);

cout << “10.” << flush <<‘n’;

// user input of my_sequence

cout << “Please enter ” << round_now << ” characters to match:”;

cin >> user_seq;

// if match continue with next round_now otherwise quit the loop

if (user_seq != my_seq) {

cout << “Sorry, you lose. The correct my_sequence was: ” << my_seq

<< endl;

break;

}

if (round_now == 15){

cout << “Congratulations! you win!” << endl;

break;

}

round_now++;

}

return 0;

}

Output:

Buy Essay
Calculate your paper price
Pages (550 words)
Approximate price: -

Help Me Write My Essay - Reasons:

Best Online Essay Writing Service

We strive to give our customers the best online essay writing experience. We Make sure essays are submitted on time and all the instructions are followed.

Our Writers are Experienced and Professional

Our essay writing service is founded on professional writers who are on stand by to help you any time.

Free Revision Fo all Essays

Sometimes you may require our writers to add on a point to make your essay as customised as possible, we will give you unlimited times to do this. And we will do it for free.

Timely Essay(s)

We understand the frustrations that comes with late essays and our writers are extra careful to not violate this term. Our support team is always engauging our writers to help you have your essay ahead of time.

Customised Essays &100% Confidential

Our Online writing Service has zero torelance for plagiarised papers. We have plagiarism checking tool that generate plagiarism reports just to make sure you are satisfied.

24/7 Customer Support

Our agents are ready to help you around the clock. Please feel free to reach out and enquire about anything.

Try it now!

Calculate the price of your order

Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

HOW OUR ONLINE ESSAY WRITING SERVICE WORKS

Let us write that nagging essay.

STEP 1

Submit Your Essay/Homework Instructions

By clicking on the "PLACE ORDER" button, tell us your requires. Be precise for an accurate customised essay. You may also upload any reading materials where applicable.

STEP 2

Pick A & Writer

Our ordering form will provide you with a list of writers and their feedbacks. At step 2, its time select a writer. Our online agents are on stand by to help you just in case.

STEP 3

Editing (OUR PART)

At this stage, our editor will go through your essay and make sure your writer did meet all the instructions.

STEP 4

Receive your Paper

After Editing, your paper will be sent to you via email.