void InitializeBoard(Grid<string> &board) { //assign each location a letter for (int i = 0; i < board.numRows(); i++) { for (int j = 0; j < board.numCols(); j++) { int RandNum = RandomInteger(0,5); //change if big board board(i,j) = StandardCubes[i * board.numCols() + j][RandNum]; //pick a random letter from each of the 16 cubes } } //swap letters randomly so that each letter is swapped at least once for (int i = 0; i < board.numRows(); i++) { for (int j = 0; j < board.numCols(); j++) { int RandRow = RandomInteger(0, board.numRows() - 1); int RandCol = RandomInteger(0, board.numCols() - 1); string s1 = board(i,j); string s2 = board(RandRow, RandCol); board(i,j) = s2; board(RandRow, RandCol) = s1; } } //update graphics for (int i = 0; i < board.numRows(); i++) { for (int j = 0; j < board.numCols(); j++) { LabelCube(i, j, board(i,j)[0]); } } }
/* * Function: DrawBoggleBoard * --------------------------- * Draws the graphic display of the boggle board, reflecting the char configuration of the boggleBoard. */ void DrawBoggleBoard(Grid<char> boggleBoard) { int row = 0, col = 0; while (true) { LabelCube(row, col, boggleBoard.getAt(row, col)); if (!AdjacentPoint(boggleBoard.numRows(), boggleBoard.numCols(), row, col)) break; } }
void UserConfigureBoard(Grid<string> &board) { string config; while (true) { cout << "Please enter your configuration. It must be 16 letters: " << endl; config = ConvertToUpperCase(GetLine()); if (config.length() > 15) break; cout << "String too short. Enter another string" << endl; } if (config.length() > 16) { //truncate string to 16 letters config = config.substr(0, 16); } for (int i = 0; i < board.numRows(); i++) { //assign each letter to proper space in board for (int j = 0; j < board.numCols(); j++) { board(i,j) = config[i * board.numCols() + j]; } } for (int i = 0; i < board.numRows(); i++) { //update display for (int j = 0; j < board.numCols(); j++) { LabelCube(i, j, board(i,j)[0]); } } }
void addLetters(Grid<char> &board) { for (int i = 0; i < board.numRows() *board.numCols(); i++) { int row = i/board.numRows(); int col = i % board.numRows(); LabelCube(row, col, board.getAt(row,col)); } }