#include "gameboar.h" #include #include const char* DIRECTIONS = "\ DarkGrayBox is a puzzle game. The board consists of an N x M rectangle\n\ in which are hidden a number of objects. Your task is to figure out which\n\ objects are where by sending rays of light into one of the slots around\n\ the edge of the board, and seeing where they come out. Rays going in are\n\ marked with a capital letter, and rays coming out are marked with the\n\ matching lowercase letter. If the ray does not emerge from the box, only\n\ the capital letter will appear, and if it emerges from the same slot into\n\ which it was sent, only the lowercase letter is printed. Each object b\n\ affects the ray of light in a different way. The objects available in the\n\ current game are:\n\ / A mirror slanted bottom-left to top-right\n\ \\ A mirror slanted top-left to bottom-right\n\ You specify the values of N and M, as well as the number of objects in the\n\ box, the number of tries you get (26 is the maximum you should provide for\n\ this), and a random seed. A good set of values is 7 7 26 7 , where\n\ is some integer seed."; const char* HELP_MESSAGE = "\ Available commands are:\n\ h: display this message\n\ s : shoot a ray in direction in slot \n\ q: quit the program"; bool doCommand(istream& is, ostream& os, Gameboard& gb) { char cmd, dirc, sym; Dir d; char slotc, rowc, colc; int slot, row, col, errors; is >> cmd; switch(cmd) { case 'h': os << HELP_MESSAGE << endl; gb.printNoSolution(os) << endl << endl; while(is.get(dirc) && dirc != '\n'); return true; case 's': is >> dirc >> slotc; d = charToDir(dirc); if(d == none) { os << "Direction '" << dirc << "' not understood" << endl; while(is.get(dirc) && dirc != '\n'); return true; } slot = slotc - '0'; gb.fireRay(d, slot); gb.printNoSolution(os) << endl << endl; while(is.get(dirc) && dirc != '\n'); return true; case 'q': gb.printSolution(os); while(is.get(dirc) && dirc != '\n'); return false; default: os << "Command '" << cmd << "' not understood" << endl; while(is.get(dirc) && dirc != '\n'); return true; } } void main() { Gizmogrifier gm; int r, c, t, g, s; char ch; cout << DIRECTIONS << endl << endl; cout << "Enter: rows cols tries gizmos seed" << endl; cin >> r >> c >> t >> g >> s; while(cin.get(ch) && ch != '\n'); srand(s); Gameboard gb(r, c, t, g, gm); cout << "\nType 'h' for a list of available commands" << endl; gb.printNoSolution(cout); while(true) { cout << "Enter command: "; if(doCommand(cin, cout, gb) == false) { break; } } cout << "Hit enter to dismiss window" << flush; cin.get(); }