-
Notifications
You must be signed in to change notification settings - Fork 0
A project that displays the contents of a Boggle Board.
Stefandasbach/Boggle
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
// StefanDasbachBoggle.cpp : Defines the entry point for the console application. // /* First I create 16 cubes with 6 letters in each. Next, I create my primary functions: **selectLetter** and **__gotoxy**. The first function, **selectLetter**, takes in an integer as a parameter (1-16). This number determines which cube is accessed. After determining the cube, a letter is randomly selected from the cube. The second function, **__gotoxy**, uses the coordinate system and breaks it down to x & y which is input in the main function. Then, I create a number array: **randNumArray**. I allocate 16 unique, random integers from 1-16 to random spots in the array. I iterate through **randNumArray** 16 times using each random number as a parameter for the **selectLetter** function. This selects a random letter from a random cube. I then, using **if** & **else** statements and **__gotoxy**, place the letters in a 4x4 grid to make it look like a real Boggle Board. I originally wrote this project after playing Boggle in English class one day and thought this would be a great challenge. I'm currently working on implementing a search algorithm to find all possible word combinations. Eventually, multiple users can play the game as if it is Boggle in real life! Don't know what Boggle is? http://en.wikipedia.org/wiki/Boggle /* // #include "stdafx.h" #include <iostream> #include <iomanip> #include <Windows.h> #include <cmath> #include <string> #include <string.h> #include <stdio.h> #include <stdlib.h> #include <fstream> #include <ctype.h> using namespace std; const char ONE[6] = {'C', 'O', 'T', 'A', 'I', 'A'}; //ONE-SIXTEEN are the cubes of Boggle each containing 6 letters const char TWO[6] = {'O', 'S', 'E', 'W', 'D', 'N'}; const char THREE[6] = {'L', 'E', 'R', 'A', 'S', 'C'}; const char FOUR[6] = {'V', 'G', 'T', 'Z', 'E', 'I'}; const char FIVE[6] = {'E', 'Y', 'U', 'G', 'K', 'L'}; const char SIX[6] = {'D', 'U', 'N', 'O', 'K', 'T'}; const char SEVEN[6] = {'H', 'Y', 'F', 'E', 'I', 'E'}; const char EIGHT[6] = {'D', 'V', 'N', 'Z', 'A', 'E'}; const char NINE[6] = {'O', 'U', 'A', 'M', 'J', 'B'}; const char TEN[6] = {'L', 'E', 'P', 'U', 'T', 'S'}; const char ELEVEN[6] = {'N', 'E', 'P', 'I', 'H', 'S'}; const char TWELVE[6] = {'L', 'U', 'W', 'I', 'G', 'R'}; const char THIRTEEN[6] = {'X', 'I', 'B', 'O', 'F', 'R'}; const char FOURTEEN[6] = {'A', 'L', 'I', 'B', 'T', 'Y'}; const char FIFTEEN[6] = {'O', 'M', 'A', 'R', 'S', 'H'}; const char SIXTEEN[6] = {'D', 'C', 'E', 'A', 'P', 'M'}; char selectLetter (int randNum); //Function Prototype void __gotoxy( int, int ); //Function Prototype int _tmain(int argc, _TCHAR* argv[]) { srand(unsigned(time(0))); //Allows rand to be random int randNum; int temp; int randNumArr[20] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}; char letter; int x, y; for (int j = 0; j < 16; j++) //Allocates numbers to random positions in randNumArr { randNum = j + (rand() % (16-j)); temp = randNumArr[j]; randNumArr[j] = randNumArr[randNum]; randNumArr[randNum] = temp; } for (int i = 0; i < 16; i++) { letter = selectLetter ( randNumArr[i] ); //SelectLetter uses RandNumArr to pick random cubes if (i < 4) //The following if/else if statements determine the position of & display each letter { x = i*4 + 35; y = 0; __gotoxy( x, y ); cout << letter << endl; } else if (i < 8) { x = (i%4) * 4 + 35; y = 5; __gotoxy( x, y ); cout << letter << endl; } else if (i < 12) { x = (i%4) * 4 + 35; y = 10; __gotoxy( x, y ); cout << letter << endl; } else if (i < 16) { x = (i%4) * 4 + 35; y = 15; __gotoxy( x, y ); cout << letter << endl; } } return 0; } char selectLetter (int randNum) //Determines which letter from which cube will be used { int x; char temp; switch (randNum) { case 1: x = ((rand() % 5) + 0); temp = ONE[x]; return temp; break; case 2: x = ((rand() % 5) + 0); temp = TWO[x]; return temp; break; case 3: x = ((rand() % 5) + 0); temp = THREE[x]; return temp; break; case 4: x = ((rand() % 5) + 0); temp = FOUR[x]; return temp; break; case 5: x = ((rand() % 5) + 0); temp = FIVE[x]; return temp; break; case 6: x = ((rand() % 5) + 0); temp = SIX[x]; return temp; break; case 7: x = ((rand() % 5) + 0); temp = SEVEN[x]; return temp; break; case 8: x = ((rand() % 5) + 0); temp = EIGHT[x]; return temp; break; case 9: x = ((rand() % 5) + 0); temp = NINE[x]; return temp; break; case 10: x = ((rand() % 5) + 0); temp = TEN[x]; return temp; break; case 11: x = ((rand() % 5) + 0); temp = ELEVEN[x]; return temp; break; case 12: x = ((rand() % 5) + 0); temp = TWELVE[x]; return temp; break; case 13: x = ((rand() % 5) + 0); temp = THIRTEEN[x]; return temp; break; case 14: x = ((rand() % 5) + 0); temp = FOURTEEN[x]; return temp; break; case 15: x = ((rand() % 5) + 0); temp = FIFTEEN[x]; return temp; break; case 16: x = ((rand() % 5) + 0); temp = SIXTEEN[x]; return temp; break; default: cout << "Did not work" << endl; break; } } void __gotoxy(int x, int y) //Allows output to point (x,y) on the screen { HANDLE hnd = GetStdHandle(STD_OUTPUT_HANDLE); COORD c; c.X = x; c.Y = y; SetConsoleCursorPosition(hnd, c); }
About
A project that displays the contents of a Boggle Board.
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published