#include "StdAfx.h" #include "resource.h" #include "gameboard.h" GameBoard::GameBoard() { ClearWords(); ClearBoard(); } GameBoard::~GameBoard() { } int GameBoard::GetWordsFound() { int found=0; int x=0; for(x=0;x -1) { x = square/15; y = square - (x*15); SelectSquare(x,y); ans = true; } return(ans); } int GameBoard::CheckLoc(int selx,int sely,int X,int X2,int Y,int Y2,int RTN) { int locx=0; int locy=0; for (locx = X;locx < X2; locx++) { for (locy = Y; locy < Y2; locy++) { if ((locx == selx)&&(locy == sely)) return(RTN); } } return(-1); } void GameBoard::SelectSquare(int x,int y) { board_[x][y].SetSelect(true); //Check if word is found CheckWords(); //On your 10th select clear it selects_++; if (selects_ > 9) { ClearSelected(); } } void GameBoard::CheckWords() { bool found=false; int x=0,y=0,wordnum=0,wordlen=0,sel=0; for(wordnum=0;wordnum MAXROW)) { if ((board_[a][b].GetLetter() == '1')&&(found == 0)) { open = open + 1; a++; b++; if (open == len) { placex = x; placey = y; found = 1; } if (b > MAXCOL-1) { x++; y=0; a = x; b = y; } } else { open = 0; y++; if (y > MAXCOL) { x++; y=0; } a = x; b = y; } } //Put word on gameboard if ((placex > -1)&&(placey > -1)) { char word[MAXLETTERS]; //WordToFind.copy(word,len,0); strcpy(word,WordToFind); int z=0; int position=len; while (position > 0) { board_[placex][placey].SetData(word[z],wordnumber); position--; z++; placex++; placey++; } } } bool GameBoard::HandleDown(int wordnumber) { bool success=true; if (RandomDown(wordnumber) == false) { CreateDown(wordnumber); }; return(success); } bool GameBoard::HandleAcross(int wordnumber) { bool success=true; if (RandomAcross(wordnumber) == false) { CreateAcross(wordnumber); }; return(success); } bool GameBoard::RandomAcross(int wordnumber) { bool ans=false; CString WordToFind = HandleBackward(wordnumber); int len=0,open=0, placey=-1; len = WordToFind.GetLength(); int found = 0; int y=0,boardx=0,boardy=0; boardx=rand() % 15; boardy=rand() % (15 - len); for (y=boardy;y -1)&&(boardy > -1)) { //word.copy(wordtmp,len,0); strcpy(wordtmp,word); for(y=boardy;y -1)&&(boardy > -1)) { strcpy(wordtmp,word); //word.copy(wordtmp,len,0); for(y=boardy;y=0;tmpy--) { tChar = words_[wordnumber].GetAt(tmpy); backwards = backwards + tChar; }; return(backwards); } char GameBoard::RandomLetter() { int n = rand() % 26; char c = (char)(n+65); return(c); } void GameBoard::FillRandom() { //change all 1's to a character int x=0;int y=0; for(x=0;x