#include <iostream>#include <iomanip>#include <time.h>#include <conio.h>#include "HiddenSquaresHeader.h"using namespace std;//Extern Int command used to call in global varible to be used in functions from main.cppextern int hiddensquarex, hiddensquarey;extern int LastGuess[26][26];extern int lives;//Function for creating the hidden square with random X and Y coordinatesint CreateHiddenSquare(){ //Begin random number generator srand((unsigned)time(NULL)); //Choose random numbers for x and y coords out of 26 hiddensquarex = rand()%25; hiddensquarey = rand()%25; //Clear the screen system("CLS"); //For testing purposes show X and Y value //cout << hiddensquarex << " " << hiddensquarey; return 0;}//Function for entering coordinates and validation checking : also contains code that displays the//Direction of the hidden square from the last values enteredint EnterCoordinates(){ //Declare varibles for the coordinates that will be inputted by the user //CheckedColumn is char because the vertical line is alphabetic. int CheckedRow = 0; char CheckedColumn = 0; //Show player how many attempts he has to guess the coordinates of the hidden square. cout << "You have " << lives << " lives remaining" << endl; //Validation code - only lets the user input a value between 1 and 26 while (CheckedRow < 1 || CheckedRow > 26) { cout << "Please Enter which number you would like to check 1 => 26" << endl; cin >> CheckedRow; //Code to ensure correct datatype is entered, there was previously a bug where incorrect datatype would cause and infinite loop. if (cin.fail()) { //If the input was not valid, clear last input and ignore first 1000 characters cin.clear(); cin.ignore(1000,'\n'); } } //Validation code - only lets the user input a value between 65 and 90 (The ascii values of A - Z) while (CheckedColumn < 65 || CheckedColumn > 90) { cout << "Please Enter Which letter you would like to check A => Z (Case Sensitive)" << endl; cin >> CheckedColumn; //Check if input was valid if (cin.fail()) { //If the input was not valid, clear last input and ignore first 1000 characters cin.clear(); cin.ignore(1000,'\n'); } } //Inform the user of the coordinates he has entered cout << "You have checked " << CheckedRow << " " << CheckedColumn << " and the result is..." << endl;// Debug Line // cout << "DEBUG: if(" <<CheckedRow << " == " << (hiddensquarex + 1) << " &&" << (CheckedColumn - 64) << " == " << (hiddensquarey + 1) <<")" << endl; //Check if the Coordinates entered are those of the hidden squares. if(CheckedRow == (hiddensquarex + 1) && (CheckedColumn - 64) == hiddensquarey + 1) { //Inform player he has won the game - also info him where the sqaure was. cout << "Congratulations! You have won the game!" << endl; cout << endl; cout << "The Hidden square was at " << CheckedRow << " " << CheckedColumn << " !!!!!" << endl; return 0; } else { //If the player did not enter the correct coordinates - check if the coordinates have already been entered and //prevent the player from making a mistake. if(LastGuess[CheckedRow - 1][(CheckedColumn - 65)] == 1) { cout << "You have already checked this square! However you will not lose a life!" << endl; lives ++; } else { //If the player made an incorrect guess - inform him that he has lost a life and add his guessed coordinates to the grid. cout << "Your Guess is incorrect! you will lose a life!" << endl; LastGuess[(CheckedColumn - 65 )][CheckedRow - 1] = 1; } }// Begin the testing to inform the player of the direction he should guess in next. // Check if we are good on east/west if (CheckedRow - 1 == hiddensquarex) { //We know we arent east/west, we are only north south if (CheckedColumn - 65 < hiddensquarey) { cout << "GO SOUTH" << endl; } else { cout << "GO NORTH" << endl; } } // Check if we are ok on north/south else if (CheckedColumn - 65 == hiddensquarey) { // We know we arent north/south, we are only east/west if (CheckedRow - 1 < hiddensquarex) { cout << "GO EAST" << endl; } else { cout << "GO WEST" << endl; } } //Check if we must head east else if (CheckedRow - 1 < hiddensquarex) { // We know we must head east, check if we need to go north south if (CheckedColumn - 65 < hiddensquarey) { cout << "GO SOUTHEAST" << endl; } else { cout << "GO NORTHEAST" << endl; } } //We must be either north or south else { //We know we must head west - check if we must head north or south if (CheckedColumn - 65 < hiddensquarey) { cout << "SOUTHWEST" << endl; } else { cout << "NORTHWEST" << endl; } } return 0;}//Function to draw the grid onto the screenint DisplayGrid(){ //Declare the varibles needed - including a large 2d Array int coords[26][26] = {0}; int columnNumber = 0; int columnNumber2 = 0; //Take a new line cout << endl; cout << " "; //Show the top value of the column headings for(int columnheading = 0; columnheading <9; columnheading ++) { cout << setw(2) << columnNumber2; } columnNumber2++; for(int columnheading2 = 0; columnheading2 <10; columnheading2 ++) { cout << setw(2) << columnNumber2; } columnNumber2++; for(int columnheading3 = 0; columnheading3 <7; columnheading3 ++) { cout << setw(2) << columnNumber2; } //Take a new line and take a space for the purposes of arrangement cout << endl; cout << " "; //Show the second line of the headings for(int columnheading4 = 0; columnheading4 <26; columnheading4 ++) { if (columnNumber > 8) { columnNumber = 0; cout << setw(2) << columnNumber; } else { columnNumber++; cout << setw(2) << columnNumber; } } //Show a dividing line to make it easier to distinguish between the headings and the grid cout << endl; cout << "-------------------------------------------------------------------------------" << endl; //begin to draw out the 26x26 grid for (int i = 0; i < 26; i++) { //Put the letters at the left of the grid char column = i+65; cout << column; for (int j = 0; j < 26; j++) { //If the coordinate has already been guessed, display that fact. if (LastGuess[i][j] > 0) { cout << setw(2) << "X"; } else { //If the coordinate has not been guessed - show a 0 cout << setw(2) << coords[i][j]; } } cout << endl; } //Show another dividing line for to outline the grid better. cout << "-------------------------------------------------------------------------------" << endl; cout << endl; return 0;}