void story(Player &player) { bool Retry; std::cout << "Welcome to the game. This is a text-based RPG, made by Meraj Ahmed." << std::endl; std::cout << "Press enter to continue..." << std::endl; getchar(); cls(); std::cout << "This tutorial will introduce you to the basics of the game. New features will be unlocked as you progress, and you will learn about them when they are unlocked." << std::endl; std::cout << "Press enter to continue..." << std::endl; getchar(); cls(); std::cout << "There are 3 main battle choices: Hit, Bash, and Heal." << std::endl; std::cout << "Hit is a normal attack." << std::endl; std::cout << "Bash does extra damage to the enemy, but damages you as well." << std::endl; std::cout << "Heal simply heals you for a small amount." << std::endl; std::cout << "Press enter to continue..." << std::endl; getchar(); cls(); savePlayer(player); do { TutorialTroll tutorialTroll; player = loadPlayer(); Retry = battle(player, tutorialTroll); } while (Retry); Retry = false; return; }
void* checkIfClientIsConnected(void* clients_void){ CheckClient* cc = (CheckClient*) clients_void; ListClient* clients = cc->clients; while(true){ ItemList client = clients->firstItem; while(client != NULL){ ClientNetwork* cn = client->client; cn->nbTry++; if(cn->nbTry == NB_MAX_TRY){ printf("Client %s disconnected\n", cn->name); client = client->next; savePlayer(*getPlayerByName(cn->players, cn->name)); removeClient(clients, cn); removePlayerByName(cn->players, cn->name); } else{ #ifdef DEBUG //printf("nbTry : %d\n", cn->nbTry); #endif client = client->next; } } getFileFromMap(cc->map); sleep(1); } pthread_exit(NULL); }
void EnterName::submit() { auto nameField = (TextField* )_rootNode->getChildByName("nameField"); auto playerName = nameField->getString(); Player::getInstance()->setName(playerName); auto settings = GameSettings::getInstance(); settings->savePlayer(Player::getInstance()); settings->markFirstTime(); settings->flush(); Director::getInstance()->replaceScene(MainMenu::createScene()); }
void save(P_HWATOO pilehead, P_HWATOO ahead, P_HWATOO bhead, P_HWATOO chead, P_HWATOO paehead, player_info *aplayer, player_info *bplayer, player_info *cplayer) { char file_name[][30] = {"pile.txt", "paehead.txt", "ahead.txt", "aplayerinfo.txt", "aplayerpae.txt", "ascore.txt", "bhead.txt", "bplayerinfo.txt", "bplayerpae.txt", "bscore.txt", "chead.txt", "cplayerinfo.txt", "cplayerpae.txt", "cscore.txt"}; savePae(file_name[0], pilehead); savePae(file_name[2], ahead); savePae(file_name[6], bhead); savePae(file_name[10], chead); savePae(file_name[1], paehead); puts("save aplayer"); savePlayer(file_name[3], file_name[4], file_name[5], aplayer); // aplater puts("save bplayer"); savePlayer(file_name[7], file_name[8], file_name[9], bplayer); // bplayer puts("save cplayer"); savePlayer(file_name[11], file_name[12], file_name[13], cplayer); // cplayer puts("save winner infomation"); saveWinner("winner.txt"); }
//Upgrades the talent with a matching talentID void upgradeTalent(edict_t *ent, int talentID) { int slot = getTalentSlot(ent, talentID); talent_t *talent; if(slot == -1) return; talent = &ent->myskills.talents.talent[slot]; // check for conflicting talents if (talentID == TALENT_RAPID_ASSEMBLY && getTalentLevel(ent, TALENT_PRECISION_TUNING) > 0) { gi.cprintf(ent, PRINT_HIGH, "Rapid Assembly can't be combined with Precision Tuning.\n"); return; } if (talentID == TALENT_PRECISION_TUNING && getTalentLevel(ent, TALENT_RAPID_ASSEMBLY) > 0) { gi.cprintf(ent, PRINT_HIGH, "Precision Tuning can't be combined with Rapid Assembly.\n"); return; } if (talentID == TALENT_CORPULENCE && getTalentLevel(ent, TALENT_LIFE_TAP) > 0) { gi.cprintf(ent, PRINT_HIGH, "Corpulence can't be combined with Life Tap.\n"); return; } if (talentID == TALENT_LIFE_TAP && getTalentLevel(ent, TALENT_CORPULENCE) > 0) { gi.cprintf(ent, PRINT_HIGH, "Life Tap can't be combined with Corpulence.\n"); return; } if(talent->upgradeLevel == talent->maxLevel) { gi.cprintf(ent, PRINT_HIGH, "You can not upgrade this talent any further.\n"); return; } if(ent->myskills.talents.talentPoints < 1) { gi.cprintf(ent, PRINT_HIGH, "You do not have enough talent points.\n"); return; } //We can upgrade. talent->upgradeLevel++; ent->myskills.talents.talentPoints--; gi.cprintf(ent, PRINT_HIGH, va("%s upgraded to level %d/%d.\n", GetTalentString(talent->id), talent->upgradeLevel, talent->maxLevel)); gi.cprintf(ent, PRINT_HIGH, va("Talent points remaining: %d\n", ent->myskills.talents.talentPoints)); savePlayer(ent); }
void BuyRuneConfirmMenu_handler (edict_t *ent, int option) { //Navigating the menu? if (option > 100) { int page_num = option / 1000; int selection = (option % 1000)-1; item_t *slot = V_FindFreeItemSlot(ent); int cost; armoryRune_t *firstItem; item_t *rune; switch(page_num) { case 1: firstItem = WeaponRunes; break; case 2: firstItem = AbilityRunes; break; case 3: firstItem = ComboRunes; break; default: gi.dprintf("Error in BuyRuneConfirmMenu_handler(). Invalid page number: %d\n", page_num); return; } rune = &((firstItem + selection)->rune); if (rune->itemtype == ITEM_NONE) { gi.cprintf(ent, PRINT_HIGH, "Sorry, someone else has purchased this rune.\n"); closemenu(ent); return; } cost = getBuyValue(rune); //Do we have enough credits? if (ent->myskills.credits < cost) { gi.cprintf(ent, PRINT_HIGH, "You need %d more credits to buy this item.\n", cost - ent->myskills.credits); } //Check for free space else if (slot == NULL) { gi.cprintf(ent, PRINT_HIGH, "Not enough room in inventory.\n"); } else { //log the purchase WriteToLogfile(ent, va("Buying rune for %d credits. [%s]", cost, rune->id)); //Buy it! V_ItemSwap(rune, slot); ent->myskills.credits -= cost; SaveArmory(); savePlayer(ent); gi.cprintf(ent, PRINT_HIGH, "Rune purchased for %d credits.\nYou have %d credits left.\n", cost, ent->myskills.credits); gi.sound(ent, CHAN_ITEM, gi.soundindex("misc/gold.wav"), 1, ATTN_NORM, 0); } //done closemenu(ent); return; } else { int page_num = option / 10; int selection = option % 10; OpenBuyRuneMenu(ent, page_num, selection); return; } }
/** *\fn int main(int argc, char *argv[]) * Main *\param[in,out] argc argc *\param[in,out] argv argv */ int main(int argc, char *argv[]) { SDL_Surface *screen = NULL; int go = 1; int ret,ret1, ret2 = 0, ret3, ret4; char level_name[MAX_SIZE_FILE_NAME]; char player_name[MAX_SIZE_FILE_NAME]; int nb_lvl; /*sound*/ Sound *sound_system; sound_system = createSound(); /*keyboard config*/ SDLKey kc[NB_KEY-1]; /*input*/ Input in; SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_JOYSTICK); Player *current_player; current_player = (Player *)malloc(sizeof(Player)); /*screen initialization*/ screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 32, SDL_HWSURFACE | SDL_DOUBLEBUF); initInput(&in); /*configurations loading */ loadSoundOptions("configuration/sound.conf",sound_system); SDL_WM_SetCaption("Super Martin", NULL); //window name SDL_ShowCursor(SDL_DISABLE); //delete the mouse while (go) //main loop { if(titleMenu(screen,&go,sound_system, &in)) { while( (ret3 = menuPlayers(screen, player_name, &go, sound_system, &in)) != -1 && go) { switch(ret3) { case -1: break; case 2 : ret2 = newPlayer(screen, player_name, sound_system, &go); if(ret2 == 1) { current_player->levelMax = 1; current_player->nbCoins = 0; current_player->nbLifes = 3; current_player->nbProjectile = 5; savePlayer("save/.save", player_name, current_player); loadInputOptions("default",kc,&in); saveInputOptions(player_name, kc, &in); } else break; case 1 : loadPlayer("save/.save", player_name, current_player); loadInputOptions(player_name,kc,&in); while(go && (ret1 = mainMenu(screen,&go,sound_system, player_name, &in)) != -1) { switch(ret1) { case -1: break; case 0: while( (ret4 = menuLevel(screen,level_name,sound_system, player_name, current_player, &go, &nb_lvl, &in)) != -1 && go) { while(play(screen,level_name,sound_system,&go,kc, &in, current_player, player_name, ret4+1, nb_lvl) && go); } break; case 1 : save(screen, "save/.save", player_name, current_player, &go); loadPlayer("save/.save", player_name, current_player); break; case 2 : while((ret = optionMenu(screen,&go,sound_system,kc, &in)) != -1 && go) { switch(ret) { case -1: break; case 0: soundOptions(screen,&go,sound_system, &in); break; case 1: keyBoardOptions(screen,&go,kc,&in,player_name); break; default:; } } break; case 3 : deletePlayer(screen, "save/players", player_name); go = 0; break; default: ; } } go = 1; break; default : ; } } } SDL_FillRect(screen,NULL,SDL_MapRGB(screen->format,255,255,255)); //clear screen SDL_Flip(screen); } freeSound(sound_system); free((void*)current_player); freeInput(&in); SDL_Quit(); return EXIT_SUCCESS; }