Hi guys, our goal is to try to create a c++ rendition of the same game. I have coded all the way up to the first real part of the program, trying to remove cells based off of what the user inputs.
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void chooseNumber(int& gameRow, int& gameColumn)
{
cout << "Please enter two values, the row and column of the cell "
<< "you would like to pull from the gameboard." << endl;
cin >> gameRow;
cin >> gameColumn;
while( gameRow < 1 && gameRow > 9)
{
cout << "Please enter a number between 1 and 9 for the "
<< "row." <<endl;
cin >> gameRow;
}
while ( gameColumn < 1 && gameColumn > 9)
{
cout << "Please enter a number between 1 and 9 for the "
<< "column." << endl;
cin >> gameColumn;
}
}
void displayBoard(int gameBoard[15][12])
{
cout << "Here is the board. \n" << endl;
for(int i= 0; i < 15; i++)
{
for(int column= 0; column < 12; column++)
{
cout << gameBoard[i][column];
}
cout << endl;
}
}
void deleteCell(int gameBoard[15][12], int gameRow, int gameColumn, int&
tempCounter)
{
bool changeMade = false;
int tempNum = gameBoard[gameRow][gameColumn];
gameBoard[gameRow][gameColumn] = 0;
cout << tempNum;
do
{
for(int i = 0; i <15 ; i++)
{
for(int column = 0; column <12 ; column++)
{
if( gameBoard[i][column] == tempNum &&
(gameBoard[i+1][column] == 0 || gameBoard[i-1][column] == 0 ||
gameBoard[i][column-1] == 0 || gameBoard[i][column+1] == 0))
{
gameBoard[i][column] = 0;
changeMade = true;
}
else
{
cout << "Didn't work!";
}
}
}
}
while(changeMade);
chooseNumber(gameRow,gameColumn);
}
int main()
{
int gameBoard[15][12];
int gameRow = 0;
int gameColumn = 0;
int tempCounter =1;
srand ( time(NULL) );
cout << "Welcome to the Same Game. The rules are as follows: "
<< endl << "You will be given a 15x12 grid filled with "
<< "random integers spanning from 1 to 9. The object of "
<< "the game is to eliminate 'cells', or two or more "
<< "similar integers connected together vertically or "
<< " horizontally until the entire board is clear. If "
<< "you run out of moves, then it's game over. \n" << endl;
for(int i= 0; i < 15; i++)
{
for(int column= 0; column < 12; column++)
{
gameBoard[i][column] = rand() % 9 + 1;
}
cout << endl;
}
displayBoard(gameBoard);
chooseNumber(gameRow, gameColumn);
deleteCell(gameBoard, gameRow, gameColumn, tempCounter);
}
For the life of me, I can't understand why my delete cell function won't work. Any help would be appreciated, whether it be pointing me to some other source or whatnot :)