void SceneAchievements::updateAchievements() {
	int i;
	// start by getting rid of all the old achievements
	for(i=0; i<4*5; i++) // 4 element for each of 5 achivments on the page
	  removeChildByTag(AchievementsTagItems+i);

	// figure out what achievements need displaying
	int start = pageNumber*5;
	int end = start+5;
	if(end >= ACHIEVEMENT_NUM)
		end = ACHIEVEMENT_NUM;

	// display them
	int curTag = AchievementsTagItems;
	int curItem = 0;
	for(i=start; i<end; i++) {
		Achievement a = Achievements::getInstance()->getAchievement(i);
		
		// row background
		IGSprite* spriteRowBackground = new IGSprite("achievements_row_background", IGPoint(160,116+68*curItem), 5, curTag);
		this->addChild(spriteRowBackground);
		curTag++;

		// name and description
		IGLabel* labelName = new IGLabel("font_gabriola_16b", a.name.c_str(), IGPoint(196,105+68*curItem), IGRect(232,34), 6, curTag);
		labelName->setColor(255,255,255,255);
		this->addChild(labelName);
		curTag++;
		IGLabel* labelDescription = new IGLabel("font_gabriola_14", a.description.c_str(), IGPoint(196,127+68*curItem), IGRect(232,34), 6, curTag);
		labelDescription->setColor(196,207,226,255);
		this->addChild(labelDescription);
		curTag++;

		// trophy
		if(a.achieved) {
			IGSprite* spriteTrophy = new IGSprite("achievements_trophy", IGPoint(44,116+68*curItem), 6, curTag);
			this->addChild(spriteTrophy);
		} else {
			IGSprite* spriteTrophy = new IGSprite("achievements_locked_trophy", IGPoint(44,116+68*curItem), 6, curTag);
			this->addChild(spriteTrophy);

			// dim everything out
			labelName->setOpacity(128);
			labelDescription->setOpacity(128);
			spriteTrophy->setOpacity(128);
		}
		curTag++;

		curItem++;
	}
}
Beispiel #2
0
void SceneGame::popUpKeyboard() {
	if(keyboardUp == false) {
		keyboardUp = true;
		
		// add black background
		IGSprite* keyboardBlack = new IGSprite("BackgroundBlack", IGPoint(240,160), 4, SceneGameTagKeyboardBlack);
		keyboardBlack->setOpacity(64);
		this->addChild(keyboardBlack);

		// display the selected letter
		IGSprite* selectedLetterBackground = new IGSprite("GameAlphabetSelectedLetterBackground", IGPoint(240,48), 5, SceneGameTagKeyboardLabelSelectedBackground);
		this->addChild(selectedLetterBackground);
		char buffer[200];
		sprintf(buffer, "Selected Letter: %c", selectedChar);
		IGLabel* labelSelectedLetter = new IGLabel("FontCourierNew18", std::string(buffer), IGPoint(240,48), IGRect(480,30), 6, SceneGameTagKeyboardLabelSelectedLetter);
		labelSelectedLetter->setColor(255, 255, 255, 255);
		this->addChild(labelSelectedLetter);

		// add the keys
		for(int i=GameAlphabetA; i<=GameAlphabetESC; i++) {
			GameAlphabetLetter* letterButton = new GameAlphabetLetter(i, isLetterUsed(i));
			this->addChild(letterButton);
		}
	}
}
void SceneLeadersboard::updateLeadersboard() {
	int i;
	// start by getting rid of all the old achievements
	for(i=0; i<4*5; i++) // 4 element for each of 5 achivments on the page
	  removeChildByTag(LeadersboardTagItems+i);

	// figure out what achievements need displaying
	int start = pageNumber*5;
	int end = start+5;
	if(end >= LEADERSBOARD_NUM)
		end = LEADERSBOARD_NUM;

	// display them
	int curTag = LeadersboardTagItems;
	int curItem = 0;
	for(i=start; i<end; i++) {
		LeadersboardScore a = Leadersboard::getInstance()->getLeadersboardScore(i);
		
		// row background
		IGSprite* spriteRowBackground = new IGSprite("achievements_row_background", IGPoint(160,116+68*curItem), 5, curTag);
		this->addChild(spriteRowBackground);
		curTag++;

		// name and description
		IGLabel* labelName = new IGLabel("font_gabriola_16b", a.name.c_str(), IGPoint(196,105+68*curItem), IGRect(232,34), 6, curTag);
		labelName->setColor(255,255,255,255);
		this->addChild(labelName);
		curTag++;
		const char *score = f_ssprintf("level %d (in %d seconds)", a.level, a.sec);
		IGLabel* labelDescription = new IGLabel("font_gabriola_14", score, IGPoint(196,127+68*curItem), IGRect(232,34), 6, curTag);
		labelDescription->setColor(196,207,226,255);
		this->addChild(labelDescription);
		curTag++;

		curItem++;
	}
}
// scene game menu
SceneGameMenu::SceneGameMenu() : IGScene()
{
	IGLog("SceneGameMenu init");
	errorUp = false;

	// load the resources
	IwGetResManager()->LoadGroup("game_menu.group");

	// the background
	IGSprite* spriteBackground = new IGSprite("background_forest_light", IGPoint(160,240), 0);
	this->addChild(spriteBackground);

	// header
	IGSprite* spriteHeader = new IGSprite("game_menu_header", IGPoint(160,60), 1);
	this->addChild(spriteHeader);

	// the menu items
	GameMenuButtonResume* buttonResume = new GameMenuButtonResume();
	GameMenuButtonRestart* buttonRestart = new GameMenuButtonRestart();
	GameMenuButtonNext* buttonNext = new GameMenuButtonNext();
	GameMenuButtonOptions* buttonOptions = new GameMenuButtonOptions();
	GameMenuButtonAbandon* buttonAbandon = new GameMenuButtonAbandon();
	this->addChild(buttonResume);
	this->addChild(buttonRestart);
	this->addChild(buttonNext);
	this->addChild(buttonOptions);
	this->addChild(buttonAbandon);

	// game info
	IGSprite* spriteInfoBackground = new IGSprite("game_menu_info_background", IGPoint(160,145), 2);
	this->addChild(spriteInfoBackground);
	char buffer1[50];
	char buffer2[100];
	switch(GameData::getInstance()->stage) {
		case GameStageForest: sprintf(buffer1, "Forest"); break;
		case GameStageCaves: sprintf(buffer1, "Caves"); break;
		case GameStageBeach: sprintf(buffer1, "Beach"); break;
		case GameStageShip: sprintf(buffer1, "Pirate Ship"); break;
	}
	sprintf(buffer2, "%s * Level: %i", buffer1, GameData::getInstance()->level);
	IGLabel* labelInfo = new IGLabel("font_algerian_16", std::string(buffer2), IGPoint(160,145), IGRect(300,50), 3);
	labelInfo->setColor(147,213,18,255);
	this->addChild(labelInfo);
}
Beispiel #5
0
void SceneGame::updatePhrase() {
	unsigned int i,j;
	
	// create the answer key from the inverse
	strcpy(answerKey, "__________________________");
	for(i=0; i<26; i++) {
		for(j=0; j<26; j++) {
			if(inverseAnswerKey[j] == ('A'+i))
				answerKey[i] = j+'A';
		}
	}
	
	// update the plaintext label
	for(i=0; i<strlen(plaintext); i++) {
		// if it's a letter decrypt it with answerKey
		if(ciphertext[i] >= 'A' && ciphertext[i] <= 'Z') {
			GamePlaintextLabel* label = (GamePlaintextLabel*)this->getChildByTag(SceneGameTagPlaintextLabels+i);

			int index = ciphertext[i]-'A';
			if(inverseAnswerKey[index] != '_')
				label->setString(std::string(1,inverseAnswerKey[index]));
			else
				label->setString(std::string(" "));
		}
	}
	
	/*// check for duplicates
	int count[26] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
	bool duplicates = false;
	
	// set the color of each plaintext label to normal color
	for(i=0; i<strlen(plaintext); i++) {
		if(plaintext[i] >= 'A' && plaintext[i] <= 'Z') {
			GamePlaintextLabel* label = (GamePlaintextLabel*)this->getChildByTag(SceneGameTagPlaintextLabels+i);
			label->setColorNormal();
		}
	}

	// count how many of each letter is used in the answer key
	for(i=0; i<26; i++) {
		if(inverseAnswerKey[i] != '_') {
			count[inverseAnswerKey[i]-'A']++;
			if(count[inverseAnswerKey[i]-'A'] > 1)
				duplicates = true;
		}
	}

	// change duplicate letters to duplicate color
	if(duplicates) {
		for(i=0; i<26; i++) {
			if(count[i] > 1) {
				for(j=0; j<strlen(plaintext); j++) {
					if(inverseAnswerKey[ciphertext[j]-'A'] == i+'A') {
						GamePlaintextLabel* label = (GamePlaintextLabel*)this->getChildByTag(SceneGameTagPlaintextLabels+j);
						label->setColorDuplicate();
					}
				}
			}
		}
	}*/

	// update the key label
	IGLabel* labelAnswerKeyLetters = (IGLabel*)this->getChildByTag(SceneGameTagLabelAnswerKeyLetters);
	labelAnswerKeyLetters->setString(std::string(inverseAnswerKey));

	// check for a win
	bool win = true;
	for(i=0; i<26; i++) {
		if(frequency[i] > 0) {
			if(inverseAnswerKey[i] != inverseKey[i])
				win = false;
		}
	}
	if(win) {
		// stop the timer
		GameTimeLabel* timeLabel = (GameTimeLabel*)this->getChildByTag(SceneGameTagTimeLabel);
		if(timeLabel != NULL)
			timeLabel->stop = true;

		// remove the answer key
		this->removeChildByTag(SceneGameTagLabelAlphabet);
		this->removeChildByTag(SceneGameTagLabelAnswerKey);
		this->removeChildByTag(SceneGameTagLabelAlphabetLetters);
		this->removeChildByTag(SceneGameTagLabelAnswerKeyLetters);

		// remove the buttons
		this->removeChildByTag(SceneGameTagButtonNewPuzzle);
		this->removeChildByTag(SceneGameTagButtonHint);
		this->removeChildByTag(SceneGameTagButtonMenu);
		
		// remove the actual puzzle
		for(i=0; i<strlen(ciphertext); i++) {
			this->removeChildByTag(SceneGameTagSlots+i);
			this->removeChildByTag(SceneGameTagPlaintextLabels+i);
			this->removeChildByTag(SceneGameTagCiphertextLabels+i);
		}

		// add the phrase
		IGLabel* phraseLabel = new IGLabel("FontCourierNew18", std::string(plaintext), IGPoint(240,122), IGRect(380,184), 1);
		switch(Settings::getInstance()->theme) {
		case SettingsThemeHacker:
			phraseLabel->setColor(255, 255, 255, 255);
			break;
		case SettingsThemeDetective:
		case SettingsThemeEspionage:
			phraseLabel->setColor(0, 0, 0, 255);
			break;
		}
		this->addChild(phraseLabel);

		// add complete buttons
		GameCompleteButtonPlayAgain* buttonCompletePlayAgain = new GameCompleteButtonPlayAgain();
		GameCompleteButtonMenu* buttonCompleteMenu = new GameCompleteButtonMenu();
		this->addChild(buttonCompletePlayAgain);
		this->addChild(buttonCompleteMenu);

		// start a new game
		this->newGame();
	}
}
Beispiel #6
0
// game scene
SceneGame::SceneGame() {
	IGScene::IGScene();
	IGLog("SceneGame init");
	unsigned int i, j;

	// load the game
	phraseId = 0;
	savedGameDB = new SQLite3Wrapper("savedGame.db");
	loadGame();

	// init physical keyboard array
	s3eKeys[0]=s3eKeyA; s3eKeys[1]=s3eKeyB; s3eKeys[2]=s3eKeyC; s3eKeys[3]=s3eKeyD; s3eKeys[4]=s3eKeyE; 
	s3eKeys[5]=s3eKeyF; s3eKeys[6]=s3eKeyG; s3eKeys[7]=s3eKeyH; s3eKeys[8]=s3eKeyI; s3eKeys[9]=s3eKeyJ;
	s3eKeys[10]=s3eKeyK; s3eKeys[11]=s3eKeyL; s3eKeys[12]=s3eKeyM; s3eKeys[13]=s3eKeyN; s3eKeys[14]=s3eKeyO;
	s3eKeys[15]=s3eKeyP; s3eKeys[16]=s3eKeyQ; s3eKeys[17]=s3eKeyR; s3eKeys[18]=s3eKeyS; s3eKeys[19]=s3eKeyT;
	s3eKeys[20]=s3eKeyU; s3eKeys[21]=s3eKeyV; s3eKeys[22]=s3eKeyW; s3eKeys[23]=s3eKeyX; s3eKeys[24]=s3eKeyY;
	s3eKeys[25]=s3eKeyZ;

	// load resources, background image
	IGSprite* spriteBackground = NULL;
	switch(Settings::getInstance()->theme) {
		case SettingsThemeHacker:
			IwGetResManager()->LoadGroup("game_hacker.group");
			spriteBackground = new IGSprite("GameHackerBackground", IGPoint(240,160), 0);
			break;
		case SettingsThemeDetective:
			IwGetResManager()->LoadGroup("game_detective.group");
			spriteBackground = new IGSprite("GameDetectiveBackground", IGPoint(240,160), 0);
			break;
		case SettingsThemeEspionage:
			IwGetResManager()->LoadGroup("game_espionage.group");
			spriteBackground = new IGSprite("GameEspionageBackground", IGPoint(240,160), 0);
			break;
	}
	this->addChild(spriteBackground);
	
	// buttons
	GameButtonNewPuzzle* buttonNewPuzzle = new GameButtonNewPuzzle();
	GameButtonHint* buttonHint = new GameButtonHint();
	GameButtonMenu* buttonMenu = new GameButtonMenu();
	this->addChild(buttonNewPuzzle);
	this->addChild(buttonHint);
	this->addChild(buttonMenu);

	// time
	int sec = (int)(time%60);
	int min = (int)(time/60);
	GameTimeLabel* timeLabel = new GameTimeLabel(min,sec);
	this->addChild(timeLabel);
	
	// draw the phrase
	const unsigned int maxCols = 18; // used to be 21
	const unsigned int maxRows = 4;
	int columnCount[4] = {0,0,0,0}; // count number of columns per row
	unsigned int col = 0;
	unsigned int row = 0;
	for(i=0; i<strlen(ciphertext); i++) {
		// if it's a space in the first column, skip this one
		while(col == 0 && ciphertext[i] == ' ')
			i++;
		
		// if it's a word, see if there's enough space in this line
		if(ciphertext[i] != ' ') {
			for(j=i+1; j<strlen(ciphertext); j++) {
				if(ciphertext[j] == ' ' || ciphertext[j] == '\0')
					break;
			}
			if(col + (j-i) >= maxCols) {
				col = 0;
				row++;
			}
		}

		// if it's a letter, draw empty box and an empty plaintext label
		if(ciphertext[i] >= 'A' && ciphertext[i] <= 'Z') {
			GameSlot* slot = new GameSlot(row, col, SceneGameTagSlots+i);
			GamePlaintextLabel* plaintextLabel = new GamePlaintextLabel(' ', row, col, SceneGameTagPlaintextLabels+i);
			this->addChild(slot);
			this->addChild(plaintextLabel);
		}
		// otherwise draw the character
		else {
			if(ciphertext[i] != ' ') {
				GamePlaintextLabel* plaintextLabel = new GamePlaintextLabel(ciphertext[i], row, col, SceneGameTagPlaintextLabels+i);
				this->addChild(plaintextLabel);
			}
		}
		
		// draw the ciphertext
		if(ciphertext[i] != ' ') {
			GameCiphertextLabel* ciphertextLabel = new GameCiphertextLabel(ciphertext[i], row, col, SceneGameTagCiphertextLabels+i);
			this->addChild(ciphertextLabel);
		}

		// count the columns
		columnCount[row]++;
		
		// increment the column
		col++;
		if(col == maxCols) {
			col = 0;
			row++;
		}
	}
	
	// center the text, total width=468, letter width=26
	for(i=0; i<4; i++) {
		int width = columnCount[i];
		int index = -1;
		for(j=0; j<=i; j++) index += columnCount[j];
		if(ciphertext[index] == ' ') width--;
		centerOffset[i] = (468 - (width*26)) / 2;
	}
	row = 0;
	for(i=0; i<strlen(ciphertext); i++) {
		GameSlot* slot = (GameSlot*)this->getChildByTag(SceneGameTagSlots+i);
		if(slot != NULL) {
			row = slot->row;
			slot->position.x += centerOffset[row];
		}

		GamePlaintextLabel* plaintextLabel = (GamePlaintextLabel*)this->getChildByTag(SceneGameTagPlaintextLabels+i);
		if(plaintextLabel != NULL)
			plaintextLabel->position.x += centerOffset[row];

		GameCiphertextLabel* ciphertextLabel = (GameCiphertextLabel*)this->getChildByTag(SceneGameTagCiphertextLabels+i);
		if(ciphertextLabel != NULL)
			ciphertextLabel->position.x += centerOffset[row];
	}
	
	// draw the key
	IGLabel* labelAlphabet = new IGLabel("FontFixedSys14",  "alphabet: ", IGPoint(123,230), IGRect(90,20), 2, SceneGameTagLabelAlphabet);
	IGLabel* labelAnswerKey = new IGLabel("FontFixedSys14", "     key: ", IGPoint(123,250), IGRect(90,20), 2, SceneGameTagLabelAnswerKey);
	IGLabel* labelAlphabetLetter = new IGLabel("FontFixedSys14", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", IGPoint(294,230), IGRect(234,20), 2, SceneGameTagLabelAlphabetLetters);
	IGLabel* labelAnswerKeyLetter = new IGLabel("FontFixedSys14", "__________________________", IGPoint(294,250), IGRect(234,20), 2, SceneGameTagLabelAnswerKeyLetters);
	switch(Settings::getInstance()->theme) {
		case SettingsThemeHacker:
			labelAnswerKey->setColor(140,140,140,255);
			labelAlphabet->setColor(140,140,140,255);
			labelAnswerKeyLetter->setColor(210,220,210,255);
			labelAlphabetLetter->setColor(210,220,210,255);
			break;
		case SettingsThemeDetective:
		case SettingsThemeEspionage:
			labelAnswerKey->setColor(80,80,80,255);
			labelAlphabet->setColor(80,80,80,255);
			labelAnswerKeyLetter->setColor(20,20,20,255);
			labelAlphabetLetter->setColor(20,20,20,255);
			break;
			break;
	}
	this->addChild(labelAnswerKey);
	this->addChild(labelAlphabet);
	this->addChild(labelAnswerKeyLetter);
	this->addChild(labelAlphabetLetter);

	// keyboard
	keyboardUp = false;

	// update the phrase
	updatePhrase();
}