#include "gameboar.h" #include #include "perm.h" #include "ray.h" Gameboard::Gameboard(int r, int c, int t, int gizmos, Gizmogrifier& g) : rows(r), cols(c), tries(t), triesLeft(t), showSolution(false), topList(c, t), bottomList(c, t), leftList(r, t), rightList(r, t) { int size = r * c; assert(gizmos < size); data = new Gizmo*[size]; guesses = new char[size]; int *perm = permList(size); int i; for(i = 0; i < gizmos; i++) { data[perm[i]] = g.randomGizmo(); guesses[i] = ' '; } // i is now equal to gizmos for(; i < size; i++) { data[perm[i]] = new Gizmo; guesses[i] = ' '; } } void Gameboard::guess(int r, int c, char ch) { int p; if((p = atPosition(r, c)) < 0) { // tried to guess out of the board return; } guesses[p] = ch; } ostream& Gameboard::printSolution(ostream& os) { topList.printTop(os, leftList.max()); for(int i = 0; i < rows; i++) { leftList.printLeftRow(i, os, leftList.max()); os << ' ' << i << "| "; for(int j = 0; j < cols; j++) { os << data[atPosition(i, j)]->asChar() << ' '; } os << '|' << i << ' '; rightList.printRightRow(i, os); os << endl; } bottomList.printBottom(os, leftList.max()); return os; } ostream& Gameboard::printNoSolution(ostream& os) { topList.printTop(os, leftList.max()); for(int i = 0; i < rows; i++) { leftList.printLeftRow(i, os, leftList.max()); os << ' ' << i << "| "; for(int j = 0; j < cols; j++) { os << guesses[atPosition(i, j)] << ' '; } os << '|' << i << ' '; rightList.printRightRow(i, os); os << endl; } bottomList.printBottom(os, leftList.max()); return os; }