void Player::attack(Actor* monster){ //check if the function input is acually a monster through dynamic cast Monster* temp = dynamic_cast<Monster*>(monster); string monsterName; char c = temp->getType(); //check the monsters type and based on that, assign monsterName a specific name switch (c) { case 'S': monsterName = " a Snakewoman"; break; case 'B': monsterName = " a Boogeyman"; break; case 'D': monsterName = " a Dragon"; break; case 'G': monsterName = " a Goblin"; break; default: break; } //check if the players attackerPoints are greater than the monsters defenderPoints if (randInt(dexterity() + equiped->dex_bonus) >= randInt(monster->dexterity() + monster->armor())) { //subtract the inflicted damage from the monster monster->setHealth(monster->health() - randInt(strength() + equiped->str_bonus)); //if the user is using MagicFangs and probablilty is greater than 1/3 then put the monster to sleep if (equiped->m_name == "Magic fangs of sleep") { if(trueWithProbability(.3)){ monster->setSleep(2+randInt(5)); //add an action to action vector dungeon()->action_vector.push_back("Player" + equiped->action() + monsterName+" and puts him to sleep."); } else //add an action saying that the player hit but did not put to sleep dungeon()->action_vector.push_back("Player" + equiped->action() +monsterName + " and hits."); } else //add an action saying that the player hit dungeon()->action_vector.push_back("Player" + equiped->action() +monsterName + " and hits."); } else //add an action saying that the player missed dungeon()->action_vector.push_back("Player" + equiped->action() + monsterName+ " and misses."); }
int main() { //Set the file stream std::ofstream out("Output/dungeon.txt"); if(out.fail()){ perror("dungeon.txt"); return 1; } //Generate dungeon const int Y = 59; const int X = 221; std::unique_ptr<Dungeon> dungeon(new Dungeon(Y, X)); dungeon->setMax(Y/5, X/9); dungeon->setMinRoomNum(60); dungeon->setChars('#','.',' '); dungeon->generate(); //Print dungeon to stream for (int y = 0; y < Y; y++){ for (int x = 0; x < X; x++){ out << (*dungeon)[y][x]; } out << "\n"; } return 0; }
string SoTeleportation::read() { if (!canRead()) return string(); dungeon()->player()->initializeSpot(); setAsRead(); return "You read the scroll called scroll of enhance dexterity\nYou feel like less of a klutz.\n"; }
string SoEnhanceDexterity::read() { if (!canRead()) return string(); dungeon()->player()->raiseDexterity(); setAsRead(); return "You read the scroll called scroll of enhance dexterity\nYou feel like less of a klutz.\n"; }
string SoRaiseStrength::read() { if (!canRead()) return string(); dungeon()->player()->addStengthPoints(1 + randInt(3)); setAsRead(); return "You read the scroll called scroll of raise strength\nYou feel like less of a klutz.\n"; }
void Monsters::dropItem(){ if (!dungeon()->isGameObject(position()) && trueWithProbability(dropProbability())) { dungeon()->addGameObject(itemToDrop(),position()); _itemToDrop = nullptr; } }
void Player::move(char c){ //heal the player if(trueWithProbability(.1)){ if( health() < max_health) setHealth(health()+1); } //check if the player is asleep if( asleep() < 1){ switch (c) { case 'h': //if there is a monster above the player attack it if(checkForMonster("UP")) attack(dungeon()->returnMonster(row(), col()-1)); //if the next space is something the player can move onto(empty space or item) then move else if(dungeon()->gameGrid[row()][col()-1] == ' '|| dungeon()->gameGrid[row()][col()-1] == '>' || dungeon()->gameGrid[row()][col()-1] == '&') setCol(col()-1); break; case 'l': //if there is a monster below the player attack it if(checkForMonster("DOWN")) attack(dungeon()->returnMonster(row(), col()+1)); else if(dungeon()->gameGrid[row()][col()+1] == ' ' || dungeon()->gameGrid[row()][col()+1] == '>'|| dungeon()->gameGrid[row()][col()-1] == '&') setCol(col()+1); break; case 'k': //if there is a monster to the left of the player attack it if(checkForMonster("LEFT")) attack(dungeon()->returnMonster(row()-1, col())); else if(dungeon()->gameGrid[row()-1][col()] == ' '|| dungeon()->gameGrid[row()-1][col()] == '>'|| dungeon()->gameGrid[row()][col()-1] == '&') setRow(row()-1); break; case 'j': //if there is a monster to the right of the player attack it if(checkForMonster("RIGHT")) attack(dungeon()->returnMonster(row()+1, col())); else if(dungeon()->gameGrid[row()+1][col()] == ' '|| dungeon()->gameGrid[row()+1][col()] == '>'|| dungeon()->gameGrid[row()][col()-1] == '&') setRow(row() +1); break; default: break; } } else{ //if the player is asleep then each move reduce his sleepTime by 1 point setSleep(asleep()-1); dungeon()->action_vector.push_back("Player is asleep"); } }
//A helper function that just checksif there is a monster around the player bool Player::checkForMonster(string dir){ bool b = false; if (dir == "UP") { b = dungeon()->gameGrid[row()][col()-1] == 'G' || dungeon()->gameGrid[row()][col()-1] == 'S' || dungeon()->gameGrid[row()][col()-1] == 'B'|| dungeon()->gameGrid[row()][col()-1] == 'D'; } if (dir == "DOWN") { b = dungeon()->gameGrid[row()][col()+1] == 'G' || dungeon()->gameGrid[row()][col()+1] == 'S' || dungeon()->gameGrid[row()][col()+1] == 'B'|| dungeon()->gameGrid[row()][col()+1] == 'D'; } if (dir == "LEFT") { b = dungeon()->gameGrid[row()-1][col()] == 'G' || dungeon()->gameGrid[row()-1][col()] == 'S' || dungeon()->gameGrid[row()-1][col()] == 'B'|| dungeon()->gameGrid[row()-1][col()] == 'D'; } if (dir == "RIGHT") { b = dungeon()->gameGrid[row()+1][col()] == 'G' || dungeon()->gameGrid[row()+1][col()] == 'S' || dungeon()->gameGrid[row()+1][col()] == 'B'|| dungeon()->gameGrid[row()+1][col()] == 'D'; } return b; }