Beispiel #1
0
/*
 * Function: InputGuesses
 * -------------------------
 * Allows the user to input guesses. Runs checks on user guess to see if it meets all boggle requirements.
 */
void InputGuesses(Grid<char> boggleBoard, Lexicon wordList, Lexicon &usedWords, Grid<bool> usedDice)
{	
	cout << endl << "Ok, take all the time you want and find all the words you can!" << endl;
	cout << "Signal that you're finished by entering an empty line." << endl << endl;
	while (true) {
		int row= 0, col = 0;
		string userGuess = CheckUserGuess(wordList, usedWords); //checks if format rules are met
		if (userGuess == "") break; //checks if sentinel of user hitting return has been occured
		while (true) {
			if (FindUserGuessOnBoard(boggleBoard, row, col, "", userGuess, usedDice)) { 
                //checks if user guess can be created from boggleBoard
				usedWords.add(userGuess); //records user guess in lexicon of used words
				RecordWordForPlayer(userGuess, Human);
				UnhighlightBoard(boggleBoard);
				PlayNamedSound("excellent.wav");
				break;
			}
			if (!AdjacentPoint(boggleBoard.numRows(), boggleBoard.numCols(), row, col)) { 
                //checks if end of board has been reached without finding appropriate dice config
				cout << "You can't make that word! " << RandomizeResponse() << endl;
				PlayNamedSound("whoops.wav");
				break;
			}
		}
	}
}
Beispiel #2
0
/*
 * Function: main
 * -----------------
 * Serves as entry point of program. Takes in all user inputs to determine specific boggle configuration.
 * Then, it gives the user a chance to find words in the boggleBoard. Then, the computer takes over
 * to find any remaining words. Finally, gives user option to play another round.
 *
 *@return 0 if program completed successfully.
 */
int main()
{
	Randomize(); //initializes random constructor
	SetWindowSize(8, 5);
	InitGraphics();
	Welcome();
	GiveInstructions();
	Lexicon wordList("lexicon.dat"); //generates list of all possible words
	while (true) {
		Lexicon usedWords; //generates a list that stores all words found by the player and computer
		InitGraphics();
		SoundFeature();
		int boardDimension = BoggleBoardSize();
		DrawBoard(boardDimension, boardDimension);
		Grid<char> boggleBoard(boardDimension, boardDimension);
		if (!UserBoardConfiguration()) {
			InitializeRandomBoard(boggleBoard); //if user chooses not to specify board configuration, a random one is generated
		} else {
			string diceConfig = GetDiceConfiguration(boardDimension);
			SetDiceConfiguration(boggleBoard, diceConfig);
		}
		DrawBoggleBoard(boggleBoard);
		Grid<bool> usedDice(boggleBoard.numRows(), boggleBoard.numCols());
		CreateMarker(usedDice);
		InputGuesses(boggleBoard, wordList, usedWords, usedDice); //player's turn
		FindRemainingWords(boggleBoard, wordList, usedWords, usedDice); //computer's turn
		PlayNamedSound("thats pathetic.wav"); //assumes the player will always lose to the computer
		if (!GameContinue()) break;
	}
	return 0;
}
Beispiel #3
0
void DrawStartingBoard(string choice)
{
	int i;
	string letter[10]={"A","B","C","D","E","F","G","H","I","J"};
	if( StringEqual(choice,"y") ) { PlayNamedSound("Fanfare"); }
	for (i=0;i<=NUM_COLS;i++)
	{
		if (i!=NUM_COLS)
		{
			MovePen((i+1.3)*LG,GetWindowHeight()-LG);
			DrawTextString(IntegerToString(i));
		}
		MovePen((i+1)*LG,GetWindowHeight()-1.3*LG);
		DrawLine(0,(-NUM_ROWS)*LG);
	}
	for (i=0;i<=NUM_ROWS;i++)
	{
		if (i!=NUM_ROWS)
		{
			MovePen(LG/4,GetWindowHeight()-(11.1-i)*LG);
			DrawTextString(letter[9-i]);
		}
		MovePen(LG,GetWindowHeight()-(11.3-i)*LG);
		DrawLine((NUM_COLS)*LG,0);
	}
}
Beispiel #4
0
/*
 * Function: CheckUserGuess
 * ---------------------------
 * Checks if the format of user guess meets all requirements of the boggle rules.
 *
 *@return string userGuess when function has confirmed that all requirements have been met.
 */
string CheckUserGuess(Lexicon wordList, Lexicon usedWords)
{
	while (true) { //prompts until appropriate guess is received
		cout << "Enter a word: ";
		string userGuess = ConvertToUpperCase(GetLine());
		if (userGuess == "") return "";
		if (userGuess.length() < minWordLength) { //checks if minimum word length is met
			cout << "I'm sorry, but we have our standards." << endl;
			cout << "That word doesn't meet the minimum word length of 4." << endl;
			PlayNamedSound("whoops.wav");
		} else if (!wordList.containsWord(userGuess)) { //checks if the guess is actually a word
			cout << "That's not a word! " << RandomizeResponse() << endl;
			PlayNamedSound("whoops.wav");
		} else if (usedWords.containsWord(userGuess)) { //checks if the guess has already been used
			cout << "You've already guessed that! " << RandomizeResponse() << endl;
			PlayNamedSound("whoops.wav");
		} else {
			return userGuess;
		}
	}
}
Beispiel #5
0
/*
 * Function: InitializeRandomBoard
 * ----------------------------------
 * Randomly initializes boggleBoard and picks a random side of the dice to face up by randomly selecting
 * a char from the const dice configuration. Then, calls on ShuffleDice to randomize the positions of the dice.
 */
void InitializeRandomBoard (Grid<char> &boggleBoard)
{
	PlayNamedSound("dice rattle.wav");
	int diceCount = 0, row = 0, col = 0;
	char randomChar;
	while (true) {
		if (boggleBoard.numRows() == 4) { //distinguishes between the 5x5 and 4x4 dice configs
			randomChar = StandardCubes[diceCount].at(RandomInteger(0, 5));
		} else {
			randomChar = BigBoggleCubes[diceCount].at(RandomInteger(0, 5));
		}
		boggleBoard.setAt(row, col, randomChar);
		diceCount++;
		if (!AdjacentPoint(boggleBoard.numRows(), boggleBoard.numCols(), row, col)) break;
	}
	ShuffleDice(boggleBoard);
}
Beispiel #6
0
void PlayGame(coord history[],ship_p cell[][NUM_COLS],class_p clas,ship_p ship,int ship_num,string choice)
{
	int num,hit=0,total=0,sum,length,q,sink=0,sink_this_time;
	string message;
	coord location;
	ship_p boat;
	DrawScore(100,ship_num,0,1);
	for (num=0;num<=99;num++)
	{
		do
		{
			location=GetLocationChosenByUser();
			if ( IsInHistory(location,history) )
			{;}
			else 
			{
				history[num].col=location.col;
				history[num].row=location.row;
				break;
			}
		}
		while(TRUE);
		
		total++;
		sink_this_time=0;
		if ( cell[location.row][location.col]==NULL )
		{			
			MarkMiss(location);
			DrawPrintfMessage("Miss!");
			if ( StringEqual("y",choice) ) { PlayNamedSound("Missile"); }
		}
		else
		{
			hit++;
			boat=cell[location.row][location.col];
			cell[location.row][location.col]=NULL;
			sum=0;
			length=clas[boat->clas].length;
			if( StringEqual(choice,"y") ) { PlayNamedSound( clas[boat->clas].sound ); }
			for (q=0;q<=length-1;q++)
			{
				if (cell[ (boat->contain)[q].row ][ (boat->contain)[q].col ]==NULL)
				{
					sum++;
				}
			}
			if (sum==length)
			{
				sink_this_time=1;
				sink++;
				clas[boat->clas].num--;
				MarkLineAsSunk( boat->contain,length,"White" );
				MarkLineAsSunk( boat->contain,length,clas[boat->clas].color );
				message="You sank the ";
				message=Concat(message,clas[boat->clas].name);
				message=Concat(message," ");
				message=Concat(message,boat->name);
				message=Concat(message," ! ");
				message=Concat(message,"There are ");
				message=Concat( message , IntegerToString(clas[boat->clas].num) );
				message=Concat(message," ");
				message=Concat(message,clas[boat->clas].name);
				message=Concat(message,"s left.");
				DrawPrintfMessage(message);
				if( StringEqual(choice,"y") ) { PlayNamedSound("You Sank My Battleship"); }
			}
			if (sink_this_time==0)
			{
				MarkHit(location,clas[boat->clas].color,0.85);
				DrawPrintfMessage("Direct hit!");
			}
		}
		DrawScore(99-num,ship_num-sink,hit,total);
		if (sink==ship_num)
		{
			break;
		}
	}
	if (sink==ship_num ) { DrawPrintfMessage("You win!"); }
	else { DrawPrintfMessage("I win!"); }
	if( StringEqual(choice,"y") )
	{
		if (sink==ship_num ) { PlayNamedSound("Song of Joy"); }
		else { PlayNamedSound("That's Pathetic"); }
	}
}