Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
#include "character.h"
Character::Character(int newGame){
string inputName;
int ch;
int position = 0;
if(newGame == 0){
while(1){
erase();
mvprintw(LINES/2,(COLS-strlen("Enter name please(Max 15 characters): "))/2,"%s","Enter name please(Max 15 characters): ");
mvprintw(LINES/2 + 3,(COLS-strlen("Press enter to continue"))/2,"%s", "Press enter to corfirm name");
mvprintw(LINES/2,(COLS-strlen("Enter name please(Max 15 characters): "))/2 + strlen("Enter name please(Max 15 characters): "),"%s",inputName.c_str());
refresh();
ch = getch();
if(ch == 10){
name = inputName;
break;
}
else if(ch == KEY_BACKSPACE){
inputName = inputName.substr(0,inputName.size() - 1);
}
else if(inputName.size() == 15){
continue;
}
else{
inputName.insert(inputName.end(),ch);
}
}
while(1){
erase();
mvprintw(LINES/2,(COLS-strlen("Choose species:"))/2,"%s", "Choose species:");
mvprintw(LINES/2 + 1,(COLS-strlen("Human"))/2,"%s", "Human");
mvprintw(LINES/2 + 2,(COLS-strlen("Dwarf"))/2,"%s", "Dwarf");
refresh();
mvprintw((LINES/2 + position + 1), COLS/2 - 8, ">");
mvprintw((LINES/2 + position + 1), COLS/2 + 7, "<");
refresh();
ch = getch();
if(ch == KEY_UP && position == 1){
position--;
}
if(ch == KEY_DOWN && position == 0){
position++;
}
if(ch == SPACEBAR && position == 0){
species = "human";
break;
}
if (ch == SPACEBAR && position == 1){
species = "dwarf";
break;
}
}
while(1){
erase();
mvprintw(LINES/2,(COLS-strlen("Choose class:"))/2,"%s", "Choose class:");
mvprintw(LINES/2 + 1,(COLS-strlen("Warrior"))/2,"%s", "Warrior");
mvprintw(LINES/2 + 2,(COLS-strlen("Mage"))/2,"%s", "Mage");
refresh();
mvprintw((LINES/2 + position + 1), COLS/2 - 8, ">");
mvprintw((LINES/2 + position + 1), COLS/2 + 7, "<");
refresh();
ch = getch();
if(ch == KEY_UP && position == 1){
position--;
}
if(ch == KEY_DOWN && position == 0){
position++;
}
if(ch == SPACEBAR && position == 0){
classes = "warrior";
break;
}
if (ch == SPACEBAR && position == 1){
classes = "mage";
break;
}
}
erase();
if (species == "human"){
str = str + 2;
dex = dex + 5;
con = con + 2;
intel = intel + 3;
luck = luck + 5;
charisma = charisma;
learnedPassives.push_back(passives[1]);
}
else if (species == "dwarf"){
str = str + 5;
dex = dex + 2;
con = con + 5;
intel = intel + 2;
luck = luck + 2;
charisma = charisma;
learnedPassives.push_back(passives[0]);
}
if (classes == "warrior"){
str = str + 5;
dex = dex + 2;
con = con + 3;
intel = intel + 1;
luck = luck + 0;
charisma = charisma + 5;
for(int i = 0; i <= 3; i++){
learnableSkills.push_back(skills[i]);
}
learnedSkills.push_back(learnableSkills[0]);
}
else if (classes == "mage"){
str = str + 1;
dex = dex + 3;
con = con + 2;
intel = intel + 5;
luck = luck + 0;
charisma = charisma + 5;
for(int i = 4; i <= 7; i++){
learnableSkills.push_back(skills[i]);
}
learnedSkills.push_back(learnableSkills[0]);
}
}
else {
load();
}
update();
mvprintw(LINES/2 - 5,(COLS-strlen("Info:"))/2,"%s", "Info:");
mvprintw(LINES/2 - 4,(COLS-strlen(("Name: " + name).c_str()))/2,"%s", ("Name: " + name).c_str());
mvprintw(LINES/2 - 3,(COLS-strlen(("Species: " + species).c_str()))/2,"%s", ("Species: " + species).c_str());
mvprintw(LINES/2 - 2,(COLS-strlen(("Class: " + classes).c_str()))/2,"%s", ("Class: " + classes).c_str());
mvprintw(LINES/2 - 1,(COLS-strlen(("Health: " + to_string(currentHp) + "/" + to_string(maxHp)).c_str()))/2,"%s", ("Health: " + to_string(currentHp) + "/" + to_string(maxHp)).c_str());
mvprintw(LINES/2,(COLS-strlen(("Mana: " + to_string(currentMana) + "/" + to_string(maxMana)).c_str()))/2,"%s", ("Mana: " + to_string(currentMana) + "/" + to_string(maxMana)).c_str());
mvprintw(LINES/2 + 1,(COLS-strlen(("Physical attack: " + to_string(pAtk)).c_str()))/2,"%s", ("Physical attack: " + to_string(pAtk)).c_str());
mvprintw(LINES/2 + 2,(COLS-strlen(("Magical attack: " + to_string(mAtk)).c_str()))/2,"%s", ("Magical attack: " + to_string(mAtk)).c_str());
mvprintw(LINES/2 + 3,(COLS-strlen(("Strength: " + to_string(str)).c_str()))/2,"%s", ("Strength: " + to_string(str)).c_str());
mvprintw(LINES/2 + 4,(COLS-strlen(("Dexterity: " + to_string(dex)).c_str()))/2,"%s", ("Dexterity: " + to_string(dex)).c_str());
mvprintw(LINES/2 + 5,(COLS-strlen(("Condition: " + to_string(con)).c_str()))/2,"%s", ("Condition: " + to_string(con)).c_str());
mvprintw(LINES/2 + 6,(COLS-strlen(("Intelligence: " + to_string(intel)).c_str()))/2,"%s", ("Intelligence: " + to_string(intel)).c_str());
mvprintw(LINES/2 + 7,(COLS-strlen(("Charisma: " + to_string(charisma)).c_str()))/2,"%s", ("Charisma: " + to_string(charisma)).c_str());
mvprintw(LINES/2 + 8,(COLS-strlen(("Level: " + to_string(lvl)).c_str()))/2,"%s", ("Level: " + to_string(lvl)).c_str());
mvprintw(LINES/2 + 9,(COLS-strlen(("Stat points: " + to_string(statPoints)).c_str()))/2,"%s", ("Stat points: " + to_string(statPoints)).c_str());
mvprintw(LINES/2 + 10,(COLS-strlen(("Experience: " + to_string(exp)).c_str()))/2,"%s", ("Experience: " + to_string(exp)).c_str());
mvprintw(LINES/2 + 11,(COLS-strlen(("Money: " + to_string(money)).c_str()))/2,"%s", ("Money: " + to_string(money)).c_str());
refresh();
getch();
erase();
save();
}
void Character::save(){
ofstream savedFile;
savedFile.open ("combatStats/gameFile.txt");
savedFile << name << endl;
savedFile << species << endl;
savedFile << classes << endl;
savedFile << currentHp << endl;
savedFile << currentMana << endl;
savedFile << str << endl;
savedFile << dex << endl;
savedFile << con << endl;
savedFile << intel << endl;
savedFile << luck << endl;
savedFile << charisma << endl;
savedFile << lvl << endl;
savedFile << statPoints << endl;
savedFile << exp << endl;
savedFile << money << endl;
savedFile.close();
}
void Character::load(){
ifstream savedFile;
savedFile.open ("combatStats/gameFile.txt");
string line;
getline (savedFile,line);
name = line;
getline (savedFile,line);
species = line;
getline (savedFile,line);
classes = line;
getline (savedFile,line);
currentHp = stoi(line);
getline (savedFile,line);
currentMana = stoi(line);
getline (savedFile,line);
str = stoi(line);
getline (savedFile,line);
dex = stoi(line);
getline (savedFile,line);
con = stoi(line);
getline (savedFile,line);
intel = stoi(line);
getline (savedFile,line);
luck = stoi(line);
getline (savedFile,line);
charisma = stoi(line);
getline (savedFile,line);
lvl = stoi(line);
getline (savedFile,line);
statPoints = stoi(line);
getline (savedFile,line);
exp = stoi(line);
getline (savedFile,line);
money = stoi(line);
savedFile.close();
update();
getSpecies();
getClass();
}
void Character::update()
{
maxHp = con * 3 + 10;
if(currentHp == 0){
currentHp = maxHp;
}
pAtk = (str - 1)/2;
mAtk = (intel - 1)/2;
maxMana = intel * 2;
if(currentMana == -1){
currentMana = maxMana;
}
if(currentMana < maxMana){
currentMana += maxMana * 0.1;
if (currentMana > maxMana){
currentMana = maxMana;
}
}
if(cooldownTurns1 > 0){
cooldownTurns1--;
}
if(cooldownTurns2 > 0){
cooldownTurns2--;
}
if(cooldownTurns3 > 0){
cooldownTurns3--;
}
if(cooldownTurns4 > 0){
cooldownTurns4--;
}
}
void Character::getName(string receiveN){
name = receiveN;
}
void Character::getSpecies(){
if (species == "human"){
learnedPassives.push_back(passives[1]);
}
else if (species == "dwarf"){
learnedPassives.push_back(passives[0]);
}
}
void Character::getClass(){
if (classes == "warrior"){
for(int i = 0; i <= 3; i++){
learnableSkills.push_back(skills[i]);
}
learnedSkills.push_back(learnableSkills[0]);
}
else if (classes == "mage"){
for(int i = 4; i <= 7; i++){
learnableSkills.push_back(skills[i]);
}
learnedSkills.push_back(learnableSkills[0]);
}
}
string Character::giveName(){
return name;
}
string Character::giveSpecies(){
return species;
}
string Character::giveClass(){
return classes;
}
array<int, 13> Character::showInfo(){
array<int, 13> statList = {maxHp, currentHp, pAtk, mAtk, str, dex, con, intel, luck, charisma, lvl, statPoints, money};
return statList;
}
void Character::showStats(){
mvprintw(LINES/2 - 6,0,"%s", "Info:");
mvprintw(LINES/2 - 5,0,"%s", ("Name: " + name).c_str());
mvprintw(LINES/2 - 4,0,"%s", ("Species: " + species).c_str());
mvprintw(LINES/2 - 3,0,"%s", ("Class: " + classes).c_str());
mvprintw(LINES/2 - 2,0,"%s", ("Health: " + to_string(currentHp) + "/" + to_string(maxHp)).c_str());
mvprintw(LINES/2 - 1,0,"%s", ("Mana: " + to_string(currentMana) + "/" + to_string(maxMana)).c_str());
mvprintw(LINES/2,0, ("Physical attack: " + to_string(pAtk)).c_str());
mvprintw(LINES/2 + 1,0,"%s", ("Magical attack: " + to_string(mAtk)).c_str());
mvprintw(LINES/2 + 2,0,"%s", ("Strength: " + to_string(str)).c_str());
mvprintw(LINES/2 + 3,0,"%s", ("Dexterity: " + to_string(dex)).c_str());
mvprintw(LINES/2 + 4,0,"%s", ("Condition: " + to_string(con)).c_str());
mvprintw(LINES/2 + 5,0,"%s", ("Intelligence: " + to_string(intel)).c_str());
mvprintw(LINES/2 + 6,0,"%s", ("Charisma: " + to_string(charisma)).c_str());
mvprintw(LINES/2 + 7,0,"%s", ("Level: " + to_string(lvl)).c_str());
mvprintw(LINES/2 + 8,0,"%s", ("Stat points: " + to_string(statPoints)).c_str());
mvprintw(LINES/2 + 9,0,"%s", ("Experience: " + to_string(exp)).c_str());
mvprintw(LINES/2 + 10,0,"%s", ("Money: " + to_string(money)).c_str());
refresh();
}
void Character::levelup(){
lvl++;
statPoints = statPoints + 3;
if (lvl == 7){
learnedSkills.push_back(learnableSkills[1]);
}
else if (lvl == 15){
learnedSkills.push_back(learnableSkills[2]);
}
else if (lvl == 21){
learnedSkills.push_back(learnableSkills[3]);
}
}
void Character::updateExp(float expGiven, int enemyLvl){
float expGained = expGiven*(enemyLvl/lvl);
mvprintw(LINES/2 + 1,(COLS-strlen(("Exp earned " + to_string(expGained)).c_str()))/2,"%s", ("Exp earned " + to_string(expGained)).c_str());
refresh();
getch();
exp = exp + expGained;
if(exp >= 100){
exp = exp - 100;
levelup();
}
}
float Character::showExp(){
return exp;
}
void Character::usePoints(){
int ch;
int position;
if(statPoints == 0){
erase();
mvprintw(LINES/2 + 4,(COLS-strlen("You don't have any points"))/2,"%s", "You don't have any points");
refresh();
getch();
return;
}
while(statPoints > 0){
erase();
mvprintw(LINES/2,(COLS-strlen("Choose Stats to increase one at a time:"))/2,"%s", "Choose Stats to increase one at a time:");
mvprintw(LINES/2 + 1,(COLS-strlen("Strength"))/2,"%s", "Strength");
mvprintw(LINES/2 + 2,(COLS-strlen("Dexterity"))/2,"%s", "Dexterity");
mvprintw(LINES/2 + 3,(COLS-strlen("Condition"))/2,"%s", "Condition");
mvprintw(LINES/2 + 4,(COLS-strlen("Intelligence"))/2,"%s", "Intelligence");
mvprintw(LINES/2 + 5,(COLS-strlen("Luck"))/2,"%s", "Luck");
mvprintw(LINES/2 + 6,(COLS-strlen("Charisma"))/2,"%s", "Charisma");
refresh();
mvprintw((LINES/2 + position + 1), COLS/2 - 8, ">");
mvprintw((LINES/2 + position + 1), COLS/2 + 7, "<");
refresh();
ch = getch();
if(ch == KEY_UP && position <= 5 && position > 0){
position--;
}
if(ch == KEY_DOWN && position < 5 && position >= 0){
position++;
}
if(ch == SPACEBAR && position == 0){
str++;
statPoints--;
break;
}
else if (ch == SPACEBAR && position == 1){
dex++;
statPoints--;
break;
}
else if (ch == SPACEBAR && position == 2){
con++;
statPoints--;
break;
}
else if (ch == SPACEBAR && position == 3){
intel++;
statPoints--;
break;
}
else if (ch == SPACEBAR && position == 4){
luck++;
statPoints--;
break;
}
else if (ch == SPACEBAR && position == 5){
charisma++;
statPoints--;
break;
}
}
}
void Character::addMoney(int acquiredMoney){
money = money + acquiredMoney;
}
void Character::removeMoney(int lostMoney){
money = money - lostMoney;
}
int Character::takeDamage(int damage){
currentHp = currentHp - damage;
if(currentHp <= 0){
currentHp = 0;
}
mvprintw(LINES/2 + 2,(COLS-strlen(("You took " + to_string(damage)).c_str()))/2,"%s", ("You took " + to_string(damage)).c_str());
mvprintw(LINES/2 + 3,(COLS-strlen(("Current hp: " + to_string(currentHp)).c_str()))/2,"%s", ("Current hp: " + to_string(currentHp)).c_str());
refresh();
getch();
if (currentHp <= 0){
gameover();
return 1;
}
return 0;
}
void Character::gameover(){
mvprintw(LINES/2 + 4,(COLS-strlen("You lost"))/2,"%s", "You lost");
mvprintw(LINES/2 + 5,(COLS-strlen("Loading previous save"))/2,"%s", "Loading previous save");
refresh();
getch();
load();
}
void Character::showSkills(){
cout << "Skills:" << endl;
for(int i = 0;i < skills.size(); i++){
cout << skills[i] << endl;
}
}
void Character::showLearnedS(){
cout << "Learned skills:" << endl;
for(int i = 0;i < learnedSkills.size(); i++){
cout << learnedSkills[i] << endl;
}
}
void Character::showLearnableS(){
cout << "Learnable skills(including learned skills):" << endl;
for(int i = 0;i < learnableSkills.size(); i++){
cout << learnableSkills[i] << endl;
}
}
void Character::showPassives(){
cout << "passives: " << endl;
for(int i = 0; i < learnedPassives.size(); i++){
cout << learnedPassives[i] << endl;
}
}
vector<string> Character::getSkills(){
return learnedSkills;
}
vector<string> Character::getPassives(){
return learnedPassives;
}
array<int, 2> Character::slash(){
if(cooldownTurns1 > 0){
erase();
mvprintw(LINES/2,(COLS-strlen("Ability in cooldown"))/2,"%s", "Ability in cooldown");
refresh();
getch();
return {0,0};
}
int damageM = 1;
cooldownTurns1 = 1;
array<int, 2> skillInfo = {damageM, cooldownTurns1};
return skillInfo;
}
array<int, 2> Character::knifeThrow(){
if(cooldownTurns2 > 0){
erase();
mvprintw(LINES/2,(COLS-strlen("Ability in cooldown"))/2,"%s", "Ability in cooldown");
refresh();
getch();
return {0,-1};
}
int damageM = 1.5;
cooldownTurns2 = 2;
array<int, 2> skillInfo = {damageM, cooldownTurns2};
return skillInfo;
}
array<int, 2> Character::block(){
if(cooldownTurns3 > 0){
erase();
mvprintw(LINES/2,(COLS-strlen("Ability in cooldown"))/2,"%s", "Ability in cooldown");
refresh();
getch();
return {0,-1};
}
int damageM = 0;
cooldownTurns3 = 3;
string skillDescription = "Blocks damage by 50% then lower cooldown for other skills by 1";
array<int, 2> skillInfo = {damageM, cooldownTurns3};
return skillInfo;
}
array<int, 2> Character::kick(int hit){
if(cooldownTurns4 > 0){
erase();
mvprintw(LINES/2,(COLS-strlen("Ability in cooldown"))/2,"%s", "Ability in cooldown");
refresh();
getch();
return {0,-1};
}
int damageM = 1.5;
cooldownTurns4;
if(hit == 0){
cooldownTurns4 = 3;
}
else{
cooldownTurns4 = 1;
}
string skillDescription = "When this skill hit cooldown is refunded";
array<int, 2> skillInfo = {damageM, cooldownTurns4};
return skillInfo;
}
array<int, 2> Character::fireball(){
int damageM = 1.5;
int manaConsumption = 5;
if (currentMana < manaConsumption){
erase();
mvprintw(LINES/2,(COLS-strlen("Not enough mana"))/2,"%s", "Not enough mana");
refresh();
getch();
return {0,0};
}
currentMana = currentMana - manaConsumption;
array<int, 2> skillInfo = {damageM, manaConsumption};
return skillInfo;
}
array<int, 2> Character::blizzard(){
int damageM = 2.5;
int manaConsumption = 20;
if (currentMana < manaConsumption){
erase();
mvprintw(LINES/2,(COLS-strlen("Not enough mana"))/2,"%s", "Not enough mana");
refresh();
getch();
return {0,0};
}
currentMana = currentMana - manaConsumption;
array<int, 2> skillInfo = {damageM, manaConsumption};
return skillInfo;
}
array<int, 2> Character::rockWall(){
int damageM = 0;
int manaConsumption = 5;
if (currentMana < manaConsumption){
erase();
mvprintw(LINES/2,(COLS-strlen("Not enough mana"))/2,"%s", "Not enough mana");
refresh();
getch();
return {0,0};
}
currentMana = currentMana - manaConsumption;
string skillDescription = "Completely negate the enemies damage if it is lower than your intelligence";
array<int, 2> skillInfo = {damageM, manaConsumption};
return skillInfo;
}
array<int, 2> Character::selfHeal(){
int damageM = 0;
int manaConsumption = 20;
if (currentMana < manaConsumption){
erase();
mvprintw(LINES/2,(COLS-strlen("Not enough mana"))/2,"%s", "Not enough mana");
refresh();
getch();
return {0,0};
}
currentMana = currentMana - manaConsumption;
string skillDescription = "Heals yourself by 25%";
array<int, 2> skillInfo = {damageM, manaConsumption};
return skillInfo;
}
int main() {
initscr();
keypad(stdscr, TRUE);
cbreak();
noecho();
int ch;
int position = 0;
ifstream savedFile;
savedFile.open ("combatStats/gameFile.txt");
string line;
getline (savedFile,line);
savedFile.close();
if(line == ""){
Character character(0);
array<int, 13> info = character.showInfo();
character = mainCombat(info[8], info[2], info[3], info[6], character, info[5], info[10]);
character.save();
character.showStats();
endwin();
exit(0);
return 0;
}
while(1){
erase();
mvprintw(LINES/2,(COLS-strlen("New game"))/2,"%s", "New game");
mvprintw(LINES/2 + 1,(COLS-strlen("Load game"))/2,"%s", "Load game");
refresh();
mvprintw((LINES/2 + position), COLS/2 - 8, ">");
mvprintw((LINES/2 + position), COLS/2 + 7, "<");
refresh();
ch = getch();
if(ch == KEY_UP && position == 1){
position--;
}
if(ch == KEY_DOWN && position == 0){
position++;
}
if(ch == SPACEBAR && position == 0){
Character character(0);
character.usePoints();
array<int, 13> info = character.showInfo();
character = mainCombat(info[8], info[2], info[3], info[6], character, info[5], info[10]);
character.save();
character.showStats();
break;
}
if (ch == SPACEBAR && position == 1){
Character character(1);
character.usePoints();
array<int, 13> info = character.showInfo();
character = mainCombat(info[8], info[2], info[3], info[6], character, info[5], info[10]);
character.save();
erase();
character.showStats();
getch();
break;
}
}
endwin();
exit(0);
}