Picross Programming Project Help

I am attempting to create a program to play picross. The game is untimed and on a 10 by 10 grid. It is console-based, so the user will have to enter coordinates to specify which locations s/he wishes to uncover instead of clicking on squares. I must create one class to represent an individual cell in the grid and a second class to represent the game grid as a whole. The cell class will be a simple class that stores two boolean variables indicating (1) whether the cell is supposed to be black (represented as a yellow ‘x’) or white (represented as a grey dot) and (2) whether or not the cell has been uncovered by the user. The grid class will contain a 10x10 array of Cell objects representing the game board. It will also need to store two 4x10 arrays of integers representing the length of the different segments of x’s in each row/column. I have the following code and I am getting lots of errors due to my Cell class default constructor and my Cell object within my grid class. I made these changes on a recommendation and I am not sure what needs to be fixed with the rest of my code so that these changes will work to allow me to read in a file and update my 2d array correctly.


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

const int ROWS = 10;
const int COLS = 10;

class Cell {
private:
char value;
bool covered;
public:
Cell(char c, bool a);
Cell();
};


class Grid {
private:
Cell grid[ROWS][COLS];
public:
char getGrid();
void setGrid(char g);
Grid();
void printGrid();
void randomPicture();
};

Cell::Cell() {
value = '*';
covered = true;

}
Cell::Cell(char c, bool a) {
value = c;
covered = a;
}

Grid::Grid() { // default consturctor
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
grid[i][j] = '*';
}
}
}

void Grid::printGrid() {
cout << " A B C D E F G H I J" << endl;
cout << " --------------------------------" << endl;
for (int i = 0; i < ROWS; i++) {
cout << i << "|";
for (int j = 0; j < COLS; j++) {
if (j == 9 && grid[i][j] == '*') {
cout << " " << grid[i][j] << " |";
}
else if (j < 9 && grid[i][j] == '*') {
cout << " " << grid[i][j];
}
else {
cout << " ";
}
}
cout << endl;
}
cout << " ------------------------------" << endl;
}

void Grid::randomPicture() {
ifstream in;
// count number of lines in the file
string line;
string tempChar;
string tempString;
bool cover;
char numberPix;
int count = 0;
in.open("pics.txt");
if (in.fail()) {
in.clear();
cout << "I'm sorry. You do not have the necessary file to play this game." << endl;
}

in >> numberPix;

while (getline(in, line)) {
count++;
}
in.close();
// choose a random picture for picross
int randNum = rand() % numberPix + 1;

//read the right picture into the game
in.open("pics.txt");
ostringstream str1;
str1 << randNum;
string rNum = str1.str();
string gameLine = " ";
cout << rNum << endl;
string startPoint;

while (numberPix != randNum) {
in >> numberPix;
for(int i = 0; i < 11; i++) {
in >> tempString;
}
}

for(int i = 0; i < ROWS; i++) {
for (int j = 0; j < COLS; j++) {
in >> tempChar;
grid[i][j] = Cell(tempChar, cover); // constructor
}
}

}

void Grid::setGrid(char g) {

}


int main() {
srand((unsigned)time(0));
Grid a;
a.printGrid();
a.randomPicture();
a.printGrid();
system("PAUSE");
}
I’m trying to understand what your function randomPicture() should do, but it tricks me.
Do you want your grid to be created randomly or read from a file? What’s the purpose of having random numbers?
Could you please provide an example of the file to be read?

And, please, could you use code-tags in your posts?
Topic archived. No new replies allowed.