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

Hi, I would like to get an answer for this assignment. SUDOKU game. Find an onli

ID: 3692110 • Letter: H

Question

Hi, I would like to get an answer for this assignment.

SUDOKU game.

Find an online game book and code up 40 possible Sudoku games. ( use a file to store the 40 possible games)

10 very easy

10 easy

10 medium

10 hard

Have the user pick the level (very easy, easy, medium, hard) and then have the computer randomly pick one(1) of the ten(10) games for that level.

Print out the game board ( 9 by 9 ), and load it with the initial values for the game, in other words pre-populate the game board with those initial values and make them a certain color like BLUE.

The cells where the user is to input values will be blank.

Next, have an easy to use method where a user can select an EMPTY cell and enter a number (Color Green), between 1 and 9.

Be sure to validate that the user is only entering values into an EMPTY cell..

Have the computer check if the user input is a valid value…

Inform the user if the number entered by them is not the correct number for the cell.. by placing the incorrect number in the chosen cell for 5 seconds FLASHING, then erase/blank the cell…

Keep track of the number of errors the user makes.

Possible scoring… 100 points if game complete successfully with no errors… subtract 5 points per error.

Show current score on screen.

Code for the following winning conditions with these messages.

At end of game if score == 100 then ‘Excellent Player, should try next level’

If score > = 80 and < 100 then ‘ Good player, keep practicing on this level’

If score >= 60 and < 80 then ‘OK player… keep practicing on this level if you dare’

If score >= 40 and < 60 ‘Well.. suggest trying a easier level’

If score < 40 then ‘Watch this video on how to play’….

Have a quit game option available while playing

Have a new game option while playing

Keep track of the number of games played at each level and average of score at that level. (hint files)

Have option to allow user see average for all levels.

THIS GAME IS to be written using C++ Classes…

The main function must look like this:

Int main() {

     SUDOKU S1;    // instantiate game.

     S1.startGame(); // start game..

}

All classes are to be written using separate .h interface file and the .cpp implementation file.

There will be NO global variables.

This is a character based application, not a GUI.

What to hand in

A description of your program and its features.

A description of the main data structures your program uses.

A discussion of the current status of your program, what works and what doesn't, etc.

Your program's source code.

Your plan that you used to write your code (See below)

Screen prints of the successful execution of your code.

Explanation / Answer

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <fstream>
#include <iomanip>
#include <string>
#include <sstream>
using namespace std;

class SudokuGame{
private:
int gamingBorad[9][9];
int boardOfSolution[9][9];
int openedBoard[9][9];
char difficultyLevel;
int points;
string playFile, solFile, storeLog;
string openedLine, solLine;
int count = 0;

public:
SudokuGame() {
// initialize all boards
for (int i = 0; i < 9; ++i) {
// columns
for (int j = 0; j < 9; ++j) {
// 1 - 9 per row
this->openedBoard[i][j] = 0; //starting number board
this->gamingBorad[i][j] = 0; // gaming board
this->boardOfSolution[i][j] = j + 1; //board for hidden solutions
}
}
}

void SudokuGame::startPlaying() {
int coloumn, row, number;
char game;
cout << booleanAlpha;

sayWelcomeToPlayer();

this->points = 100;

this->chooseDifficultyLevel();
this->gameInit(this->playFile, this->solFile);

// display the game
this->displayBoard();

// Start playing
while (true) {
// column input
coloumn = this->validColumn();
// break if new game or quit
if (coloumn == 13 || coloumn == 16) {
break;
}

// input a row
row = this->validRow();
// quit if it is a new game
if (row == 29 || row == 61 || row == 32 || row == 64) {
break;
}

// check if it is an open tile,
if (this->openATile(coloumn, row)) {
// input a number
number = this->validNumber();
// break if new game or quit
if (number == 30 || number == 62 || number == 33 || number == 65) {
break;
}
cout << endl;
// make a game move
this->move(coloumn, row, number);
}
// otherwise, display not open
else {
cout << "Input open tile.";
}

// if game the is over then quit else continue
if (this->playEnd()) {
//this->saveGame(); // save completed game
//this->displayScore(); // displays stats
game = this->playGameAgain();
if (game == 'Y') {
this->startPlaying();
}
else {
cout << "Thanks for playing";
}
break;
}
}

// create a new game
if (coloumn == 13 || row == 29 || row == 61 || number == 30 || number == 62) {
cout << endl;
this->startPlaying();
}

// end the game early
if (coloumn==16 || row == 32 || row == 64 || number == 33 || number == 65) {
cout << "Game ended early";
}
}

void displayBoard() {
  
cout << "N: Play New Game Q: Quit Game S: Display Stats ";

cout << " A B C D E F G H I ";
cout << "=============================================== ";
//select a row for displaying
for (int i = 0; i < 9; ++i) {
cout << i + 1 << " ||";
// print the columns in the row
for (int j = 0; j < 9; ++j) {
// blank if not solved yet
if (this->gamingBorad[i][j] == 0) {
// border
if ((j + 1) % 3 == 0) {
cout << " ||";
}
// within border
else {
cout << " || ";
}
}
// otherwise, print number
else {
// if opening number, print in blue
if (this->gamingBorad[i][j] == this->openedBoard[i][j] && this->openedBoard[i][j] != 0) {
cout << " " << " " << this->gamingBorad[i][j] << " ";
}
// otherwise
else {
// if correct space, print in green
if (this->gamingBorad[i][j] == this->boardOfSolution[i][j]) {
cout << " " << " " << this->gamingBorad[i][j] << " ";
}
// else, print in red
else {
cout << " " << " " << this->gamingBorad[i][j] << " ";
}
}

if ((j + 1) % 3 == 0) {
cout << " ||";
}
  
else {
cout << " || ";
}
}
}
if ((i + 1) % 3 == 0) {
// check if it's bottom row
if (i == 8) {
cout << " =============================================== ";
}

else {
cout << " ||=============||=============||=============|| ";
}
}
else {
cout << " =============||=============" <<
"||=============|| ";
}
}
cout << endl;
cout << "points: " << this->points << endl << endl;
}

// choosing difficultyLevel

// choosing difficultyLevel

void SudokuGame::chooseDifficultyLevel() {
// ch
cout << "Pick a difficultyLevel: " << "1.Very Easy 2.Easy 3.Medium 4.Hard ";
cout << "difficultyLevel: ";
cin >> this->difficultyLevel;
while (cin.get() != ' ') {}
cout << endl;

// set files
while (true) {
if (this->difficultyLevel == '1') {
this->playFile = "veryEasy.txt";
this->solFile = "veryEasySolutions.txt";
break;
}
else if (this->difficultyLevel == '2') {
this->playFile = "easy.txt";
this->solFile = "easySolutions.txt";
break;
}
else if (this->difficultyLevel == '3') {
this->playFile = "medium.txt";
this->solFile = "mediumSolutions.txt";
break;
}
else if (this->difficultyLevel == '4') {
this->playFile = "hard.txt";
this->solFile = "hardSolutions.txt";
break;
}
else {
cout << "Sorry that isn't an answer. ";
this->chooseDifficultyLevel();
}
}
}

// reading SudokuGame boards into arrays
void gameInit(string openFile, string solFile) {
int randomLine = randomize(); // randomizes a number (0-9) for which SudokuGame board
ifstream openGame(openFile.c_str()); // c.str turns a string a readable format for reading in files
ifstream openSolution(solFile.c_str());
for (int lines = 0; lines <= randomLine; ++lines) { // this loops throug every line until the random line is reached - then stores line it's stopped on it
getline(openGame, openedLine);
getline(openSolution, solLine);
}

for (int row = 0; row < 9; ++row) {
for (int coloumn = 0; coloumn < 9; ++coloumn) {
openedBoard[row][coloumn] = convertChar(openedLine[count]);
gamingBorad[row][coloumn] = convertChar(openedLine[count]);
boardOfSolution[row][coloumn] = convertChar(solLine[count]);
++count;
}
}
}


int convertChar(char c) {
return int(c) - 48;
}

int validRow() {
char row; // local variable
while (true) {
// input
cout << "row (1 - 9): ";
cin >> row;
while (cin.get() != ' ') {} // flush

// convert to int equivalent
row = charConvert(row) - 1;

// check if valid row, if so, break
if ((row >= 0 && row < 9) || row == 29 || row == 61 || row == 32 || row == 64) {
return row;
}
//else if (row == 34 || row == 66) {
//this->printStats();
//}
else {
cout << "Please enter a valid row (1 - 9). ";
}
}
}

int validColumn() {
char coloumn; // local variable
while (true) {
// input
cout << "column (A - I): ";
cin >> coloumn;
while (cin.get() != ' ') {} // flush

// convert to int equivalent
coloumn = int(toupper(coloumn)) - 65;

// check if valid column, if so, break
if ((coloumn >= 0 && coloumn < 9) || coloumn == 13 || coloumn == 16) {
return coloumn;
}
//else if (coloumn == 18) {
//this->printStats();
//}
else {
cout << "Please enter a valid column (A - I). ";
}
}
}

int validNumber() {
char number; // local variable
while (true) {
// input
cout << "Number to enter (1 - 9): ";
cin >> number;
while (cin.get() != ' ') {} // flush

// convert to int equivalent
number = charConvert(number);

// check if valid number, if so, break
if ((number > 0 && number <= 9) || number == 30 || number == 62 || number == 33 || number == 65) {
return number;
}
//else if (number == 35 || number == 67) {
//this->printStats();
//}
else {
cout << "Please enter a valid number (1 - 9). ";
}
}
}

bool openATile(int coloumn, int row) {
// if open tile, return true
if (this->gamingBorad[row][coloumn] == 0) {
return true;
}
// otherwise, return false
else {
return false;
}
}

bool correctTile(int coloumn, int row, int number) {
// if number entered for move correct for tile, return true
if (number == this->boardOfSolution[row][coloumn]) {
return true;
}
// otherwise return false
return false;
}

void move(int coloumn, int row, int number) {
// if correct tile,
if (this->correctTile(coloumn, row, number)) {
// clear screen
for (int i = 0; i < 50; ++i) {
cout << endl;
}

cout << "Correct! ";
// change game board tile to the number specified
this->gamingBorad[row][coloumn] = number;
this->displayBoard();
}
  
else {
// deduct 5 points for error
this->points -= 5;
  
for (int i = 0; i < 50; ++i) {
cout << endl;
}
cout << "incorrect move";
  
int temp = this->gamingBorad[row][coloumn];
this->gamingBorad[row][coloumn] = number;
this->displayBoard();
  
Sleep(4000);
  
for (int i = 0; i < 50; ++i) {
cout << endl;
}

// display current board
this->gamingBorad[row][coloumn] = temp;
this->displayBoard();
}
}

void pauseTime(int seconds) {
clock_t temp;
temp = clock() + seconds * CLOCKS_PER_SEC;
while (clock() < temp) {}
}

bool playEnd() {
// rows
for (int i = 0; i < 9; ++i) {
// columns
for (int j = 0; j < 9; ++j) {
if (this->gamingBorad[i][j] == this->boardOfSolution[i][j]) {
continue;
}
else {
return false;
}
}
}
return true;
}

int randomize() {
srand(time(NULL));
int number = rand() % 10;
return number;
}

void sayWelcomeToPlayer(){
cout << "WELCOME!";
}

char playGameAgain() {
char ch;
while (true) {
cout << "play Again ? ([Y]es or [N]o): ";
cin >> ch;
ch = toupper(ch);
if (ch == 'Y' || ch == 'N') {
return ch;
}
else {
cout << "Invalid choice";
}
}
}

}; //end the SudokuGame class

int main(){
SudokuGame S1;
S1.startPlaying();

system("pause");
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