Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You will be creating a game in C++ for your Arduino called \"Time bomb.\" Using

ID: 3875521 • Letter: Y

Question

You will be creating a game in C++ for your Arduino called "Time bomb." Using Arduino DUE R3 The game randomly generates a disarming code and gives the player a 25-second time limit countdown to 0. The countdown is displayed on the 8-segment display from 0025 down to 0000. The disarming code is input by the player using the three pushbuttons (A1, A2, and A3). The disarming code is some random combination of these buttons. For example, if I generate a code of 0, 2, 2, 1, then I must press the left button, the right button twice, and then the middle button to disarm the bomb. If I do not press the correct button, the player must enter the code starting from the beginning.

Every time the user presses the correct button, you will light an LED from bottom to top. If the user presses the wrong button, then clear all LEDs so the user can start over again. The player wins by lighting all four LEDs, meaning they inputted the correct 4-button sequence.

If the user presses the correct four button sequence, display dashes (----) for 3 seconds, and then start the game from the beginning. If the user does not press the correct four button sequence and the time limit counts down to 0, then you will display all zeroes (0000) for 3 seconds. During these 3 seconds, sound the buzzer (pin 3) to simulate a "time bomb" sound. After the 3 seconds, restart the game with a new, random, 4-button disarming code and 25-second time limit.

Explanation / Answer

#include <ctime>

#include <iostream>

#include <string>

#include <sstream>

//-----------------------------------------------------------------------------

// Notes:

// 1) You should make full project rebuild during customer build

// 2) Keep error handling simple: just print message to cout and call exit(-1)

// 3) You can customize the number of days in evaluation period:

const double evaluation_period_in_days = 45.0;

//-----------------------------------------------------------------------------

using namespace std;

time_t time_when_compiled()

{

// from: http://stackoverflow.com/questions/1765014/convert-string-from-date-into-a-time-t

string datestr = __DATE__;

string timestr = __TIME__;

istringstream iss_date(datestr);

string str_month;

int day;

int year;

iss_date >> str_month >> day >> year;

int month;

if (str_month == "Jan") month = 1;

else if (str_month == "Feb") month = 2;

else if (str_month == "Mar") month = 3;

else if (str_month == "Apr") month = 4;

else if (str_month == "May") month = 5;

else if (str_month == "Jun") month = 6;

else if (str_month == "Jul") month = 7;

else if (str_month == "Aug") month = 8;

else if (str_month == "Sep") month = 9;

else if (str_month == "Oct") month = 10;

else if (str_month == "Nov") month = 11;

else if (str_month == "Dec") month = 12;

else exit(-1);

for(string::size_type pos = timestr.find(':'); pos != string::npos; pos = timestr.find(':', pos))

{

timestr[pos] = ' ';

}

istringstream iss_time(timestr);

int hour, min, sec;

iss_time >> hour >> min >> sec;

tm t = {0};

t.tm_mon = month - 1;

t.tm_mday = day;

t.tm_year = year - 1900;

t.tm_hour = hour;

t.tm_min = min;

t.tm_sec = sec;

return mktime(&t);

}

//-----------------------------------------------------------------------------

int main()

{

time_t current_time = time(NULL);

time_t build_time = time_when_compiled();

double diff_time = difftime(current_time, build_time);

const double evaluation_period = evaluation_period_in_days * 24.0 * 60.0 * 60.0; // in seconds

if(diff_time > evaluation_period)

{

cout << "Evaluation period has expired." << endl;

exit(-1);

}

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote