Example #1
0
void HelpFormatter::formatText(std::ostream& ostr, const std::string& text, int indent, int firstIndent) const
{
    int pos = firstIndent;
    int maxWordLen = _width - indent;
    std::string word;
    for (std::string::const_iterator it = text.begin(); it != text.end(); ++it)
    {
        if (*it == '\n')
        {
            clearWord(ostr, pos, word, indent);
            ostr << '\n';
            pos = 0;
            while (pos < indent) {
                ostr << ' ';
                ++pos;
            }
        }
        else if (*it == '\t')
        {
            clearWord(ostr, pos, word, indent);
            if (pos < _width) ++pos;
            while (pos < _width && pos % TAB_WIDTH != 0)
            {
                ostr << ' ';
                ++pos;
            }
        }
        else if (*it == ' ')
        {
            clearWord(ostr, pos, word, indent);
            if (pos < _width) {
                ostr << ' ';
                ++pos;
            }
        }
        else
        {
            if (word.length() == maxWordLen)
            {
                clearWord(ostr, pos, word, indent);
            }
            else word += *it;
        }
    }
    clearWord(ostr, pos, word, indent);
}
//--------------------------------------------------------------
void ofxEditorSyntax::clearWord(const std::string &word) {
	clearWord(word);
}
/***********************************************************
synopsis: a big while loop that runs the full length of the
	  game, checks the game events and responds
	  accordingly

	  event		action
	  -------------------------------------------------
	  winGame	stop the clock and solve puzzle
	  timeRemaining update the clock tick
	  timeUp	stop the clock and solve puzzle
	  solvePuzzle	trigger solve puzzle and stop clock
	  updateAnswers trigger update answers
	  startNew      trigger start new
	  updateScore	trigger update score
	  shuffle	trigger shuffle
	  clear		trigger clear answer
	  quit		end loop
	  poll events   check for keyboard/mouse and quit

	  finally, move the sprites -this is always called
	  so the sprites are always considered to be moving
	  no "move sprites" event exists - sprites x&y just
	  needs to be updated and they will always be moved

inputs: head - first node in the answers list (in/out)
        dblHead - first node in the dictionary list
	screen - the SDL_Surface to display the image
	letters - first node in the letter sprites (in/out)

outputs: n/a
***********************************************************/
static void
gameLoop(struct node **head, struct dlb_node *dlbHead, 
         SDL_Surface *screen, struct sprite **letters)
{
	int j,k;
    int done=0;
	int numofwords=1;
    SDL_Event event;
    time_t timeNow;
    SDL_TimerID timer;
    int timer_delay = 20;
    char buffer[512];

	#ifdef demo
	
	if (conf.totalgames < 0){
		conf.totalgames=8;
	}
	conf.totalgames +=1;//demo tags
	sprintf(buffer,"globaldata/agdemo.cfg");
	saveCFG(buffer,&conf);
	#endif

    timer = SDL_AddTimer(timer_delay, TimerCallback, NULL);
	/* main game loop */
	while (!done) {

		if (winGame) {
			stopTheClock = 1;
			solvePuzzle = 1;
		}

		if ((gameTime < AVAILABLE_TIME) && !stopTheClock) {
			timeNow = time(0) - gameStart;
			if (timeNow != gameTime){
				gameTime = timeNow;
				updateTime(screen);
			}
		} else {
			if (!stopTheClock){
				stopTheClock = 1;
				solvePuzzle = 1;
			}
		}

		/* check messages */
		if (solvePuzzle) {
			/* walk the list, setting everything to found */
			solveIt(*head);
			clearWord(letters);
			strcpy(shuffle, SPACE_FILLED_STRING);
			strcpy(answer, rootWord);
			/*displayLetters(screen);*/
			displayAnswerBoxes(*head, screen);
			gamePaused = 1;
			if (!stopTheClock){
				stopTheClock = 1;
			}
			solvePuzzle = 0;
		}

		if (updateAnswers){
			/* move letters back down again */
			clearWord(letters);
			/* displayLetters(screen);*/
			displayAnswerBoxes(*head, screen);

			updateAnswers = 0;
		}


		if ((stopTheClock && !gotBigWord && !checkScore)||(startNewGame&&!gotBigWord& !checkScore)){
			//Error("inside highscore\n");
			for(j=9;j>=0 && hiscore[j].score<totalScore;j--);
				//Error("score position: %i\n",j);
			/* the player will be in the hall of fame? */
			if(j<9) {
				for(k=8;k>j;k--)
					hiscore[k+1]=hiscore[k];

				/* put the new score */
				hiscore[j+1].score=totalScore;
				hiscore[j+1].stage=numofwords;
				
				 //hiscore[j+1].name[0]=0;
				//if(!getName(hiscore[j+1].name, j+2,i+1))
				//	break; /* probably a problem if the user closes the window */

				/* show the hall of fame */
				//hiscores();

				/* save hi-scores */
				#ifdef demo
				sprintf(buffer,"/media/internal/appdata/com.cribme.aghddemo/ag-hiscore");
				#else
				sprintf(buffer,"/media/internal/appdata/com.cribme.aghd/ag-hiscore");
				#endif
				//sprintf(buffer,"globaldata/ag-hiscore");
				if(!saveScore(buffer,hiscore))
				fprintf(stderr,"unable to save hi-scores\ndo you have permissions to write into %s?\n" ,buffer);
				
			}
			checkScore=1;
		}

		if (startNewGame) {
			/* move letters back down again */
			if (!gotBigWord){
				totalScore = 0;
				numofwords=0;
			}
			newGame(head, dlbHead, screen, letters);

			#ifdef demo
			conf.totalgames +=1;//demo tags
			char buffer[512];
			sprintf(buffer,"globaldata/agdemo.cfg");
			//Error("Buffer :%s\n",buffer);
			//Error("TotalGames Written to file :%i\n",conf.totalgames);
			saveCFG(buffer,&conf);
			#endif

			numofwords+=1;
			checkScore = 0;
			startNewGame = 0;
		}

		if (updateTheScore) {
			updateScore(screen);
			updateTheScore = 0;
		}

		if (shuffleRemaining) {
			/* shuffle up the shuffle box */
			char shuffler[8];
			strcpy(shuffler, shuffle);
			shuffleAvailableLetters(shuffler, letters);
			strcpy(shuffle, shuffler);
			shuffleRemaining = 0;
		}

		if (clearGuess) {
			/* clear the guess; */
			if (clearWord(letters) > 0) {
				Mix_PlayChannel(-1, getSound("clear"),0);
            }
			clearGuess = 0;
		}
		#ifdef demo
		//Error("TotalGames:%i\n",conf.totalgames);//conf.totalgames
		if (conf.totalgames > 8){//conf.totalgames
		    destroyLetters(letters);
			strcpy(txt, language);
			ShowBMP(strcat(txt,"images/demo.bmp"),screen, 100,75);
			done=1;
		}

		#endif

		if (quitGame) {
			done = 1;
		}
		if (inactive){
			SDL_WaitEvent(&event);
				if (event.type == SDL_ACTIVEEVENT && event.active.gain == 1) {
				inactive = 0;
				timer = SDL_AddTimer(timer_delay, TimerCallback, NULL);
				}
		}
		else {
		while (SDL_WaitEvent(&event)) {
			if (event.type == SDL_ACTIVEEVENT && event.active.gain == 0) {
				inactive = 1;
				break;
			}
			if (event.type == SDL_USEREVENT) {
                timer_delay = anySpritesMoving(letters) ? 10 : 100;
                moveSprites(&screen, letters, letterSpeed);
                timer = SDL_AddTimer(timer_delay, TimerCallback, NULL);
                break;
            } else if (event.type == SDL_MOUSEBUTTONDOWN) {
                clickDetect(event.button.button, event.button.x,
                            event.button.y, screen, *head, letters);
				moveSprites(&screen, letters, letterSpeed);//added by me
            } else if (event.type == SDL_KEYUP) {
                handleKeyboardEvent(&event, *head, letters);
            } else if (event.type == SDL_QUIT) {
                done = 1;
                break;	
			} 
				
		}
		}
    }
	#ifdef demo
	while(conf.totalgames > 8){//conf.totalgames
		while(SDL_WaitEvent(&event)){
				if (event.type == SDL_MOUSEBUTTONDOWN) {
				PDL_ServiceCall("palm://com.palm.applicationManager/open", "{\"target\":\"http://developer.palm.com/appredirect/?packageid=com.cribme.aghd\"}");
					//PDL_LaunchBrowser("http://developer.palm.com/appredirect/?packageid=com.cribme.aghd");
				}
		}
	}
	#endif

	
}