int battle(int monsterspeed, int monsterattack, string enemyType) { int battlerun = 1; //Battle Loop while (battlerun == 1) { madechoice = 0; while (madechoice == 0) { clearScreen(); //Main Battle Menu cout << menuBar; cout << " " << enemyType << "Battle \n\n"; displayEnemy(enemyType); // healthMessage(); // magicMessage(); drunkMessage(); cout << "Your attack is " << playersAttack << "\n"; cout << "Your speed is " << playersSpeed << "\n"; cout << "Your AC is " << playersAC << "\n"; cout << " (1) Attack\n"; cout << " (2) Item Menu\n"; cout << " (3) Run Away\n\n"; cout << menuBar; cin >> playerchoice; if (playerchoice == 2) { itemMenu(); } else if (playerchoice == 3) { return 0; } else { madechoice = 1; } } //Checks if player's alive after player attack function bool stillAlive = playerAttack(playersSpeed, playersAttack, enemyType); if (stillAlive == false) { battlerun = 0; return 0; } //Checks if monster's alive after monster attack function stillAlive = monsterAttack(monsterspeed, monsterattack, enemyType); if (stillAlive == false) { battlerun = 0; return 1; } } }
bool Battle::fight() { bool attack = false, display = true; if (option == INVENTORY) { display = false; } spell = &Weapon(); srand(timeCount + hero->getHealth() + monster.getHealth() + monster.getPrize() + monster.getStrength()); while (option == FIGHT || option == SPELL || option == INVENTORY) { timeCount++; if (option == INVENTORY && !display) { hero->displayInventory(SHOW_ALL); display = true; cout << "\r\n\n\tHP: " << hero->getHealth(); cout << "\tMana: " << hero->getMana(); cout << "\tMonster HP: " << monster.getHealth(); cout << "\r\n1) Fight\r\n2) Cast a Spell\r\n3) Inventory\r\n4) Flee\r\n>>"; cin >> option; if (option != FIGHT && option != SPELL && option != INVENTORY) { cout << "\r\nYou fled the battle!\r\n\n"; return false; } else if (option == 3) { display = false; } } if (timeCount % hMod == 0 && timeCount % mMod != 0) { attack = heroAttack(); } else if (timeCount % mMod == 0 && timeCount % hMod != 0) { spellOngoing(0, 0); attack = monsterAttack(); } else if (timeCount % mMod == 0 && timeCount % hMod == 0) { if (hMod <= mMod) { attack = heroAttack(); if (attack) { spellOngoing(0, 0); attack = monsterAttack(); } } else if (hMod >= mMod) { spellOngoing(0, 0); attack = monsterAttack(); if (attack) { attack = heroAttack(); } } } if (hero->isDead() || monster.isDead()) { return hero->isDead(); } if (attack) { cout << "\r\n\n\tHP: " << hero->getHealth(); cout << "\tMana: " << hero->getMana(); cout << "\tMonster HP: " << monster.getHealth(); cout << "\r\n1) Fight\r\n2) Cast a Spell\r\n3) Inventory\r\n4) Flee\r\n>>"; cin >> option; if (option != FIGHT && option != SPELL && option != INVENTORY) { cout << "\r\nYou fled the battle!\r\n\n"; return false; } else if (option == INVENTORY) { display = false; } } attack = false; }
void adventure(eventList* pEvent, pirateTree*& aTree) { int eventCode, backEvent = 0; eventList *backup = pEvent; myTree = aTree; eventNum = 0; prev11 = 0; while (pEvent != NULL) { eventCode = (pEvent->nEventCode > 0)? pEvent->nEventCode: (pEvent->nEventCode * -1); eventNum++; switch (extractEvent(pEvent->nEventCode)) { case 1: if (!isSoulLand && !isRiverCrossed) addShip(eventCode); break; case 2: if (!isPosiden && !isRiverCrossed) monsterAttack(eventCode); break; case 3: if (!isSoulLand && !isRiverCrossed && ((!isBermuda && !isPosiden) || (isPosiden && isSteeled))) Bermuda(); break; case 4: if (!isSteeled && !isRiverCrossed) Poseiden(); break; case 5: if (isSteeled && !isRiverCrossed && !isSoulLand) monsterAttack2(eventCode); break; case 6: if (isSoulLand || isRiverCrossed) break; if (isSteeled) soulLand(); else deleteMyTree(myTree->root); break; case 7: if (isSoulLand && isJack) deadManNoTell(); break; case 8: if (isSoulLand) strangeWedding(); break; case 9: if (isS9 && !isRiverCrossed) driverGuy(eventCode); break; case 10: if (!isJack && isRiverCrossed && prev11 == 0) { Hades(); prev11 = eventNum; } break; case 11: if (isJack && prev11 > 0) { backEvent = (999 % prev11) + 1; isS12 = 1; eventNum = 0; pEvent = backup; isAVL = 0; isS9 = 0; isRiverCrossed = 0; isSoulLand = 0; isPosiden = 0; isBermuda = 0; isSteeled = 0; isBlackBeard = 1; prev11 = 0; deleteMyTree(myTree->root); continue; } break; } if (myTree->root == NULL) break; if (isHalt) break; if (isS12 && eventNum == backEvent) { if (!isJack) { deleteMyTree(myTree->root); } break; } pEvent = pEvent->pNext; } }