I'm making a simple text RPG game that I will later (once i get the code running well in the text version) put it to graphics and so on.
Basically what this code is doing is, there's a monster that the user just killed.
based on that monsters level that's how much experience it gives you.
this seems to work fine for me but i was wondering how i can make it so that at the main menu i can have something that says:
you are ____ experience away from leveling up.
but since I'm just using the: int lvl;
im not sure how i can do this.
also another problem i have is that every time that i kill a monster the random experience it gives me increases to over the amount that i want it to.
for example the first time i kill the goblin (level 1) it gives me say... 5 exp.
the second time it gives me say... 8 exp.
but then the third + time it gives me over 20 exp per. how do i avoid this?
if (goblin <= 0){
expe = expe + rand() % 10 + 1;
expe = expe * glvl;
texp = texp + expe;
cin.ignore();
loot = rand() % 100 + 1;
loot = loot * glvl;
cout << "You have killed a Goblin!\n";
cout << "\nYour loot is: ";
cout << loot << " Gold\n\n";
cout << "You also got: " << expe << " experience.\n\n";
cout << "Your total experience is: " << texp << "\n\n";
cout << "\nPress Enter to continue.\n\n";
money = money + loot;
cin.get();
if (texp >= 50){
system ("cls");
lvl = lvl + 1;
points = points + 3;
cout << "Congratulations " << name << "\n\n";
cout << "You have Leveled up!\n\n";
cout << "You are now level: " << lvl << "\n\n";
cin.ignore();
cout << "\nPress Enter to continue.\n\n";
cin.get();
}
else if (texp >=100){
system ("cls");
lvl = lvl + 1;
points = points + 3;
cout << "Congratulations " << name << "\n\n";
cout << "You have Leveled up!\n\n";
cout << "You are now level: " << lvl << "\n\n";
cin.ignore();
cout << "\nPress Enter to continue.\n\n";
cin.get();
}
else if (texp >=150){
system ("cls");
lvl = lvl + 1;
points = points + 3;
cout << "Congratulations " << name << "\n\n";
cout << "You have Leveled up!\n\n";
cout << "You are now level: " << lvl << "\n\n";
cin.ignore();
cout << "\nPress Enter to continue.\n\n";
cin.get();
}
else if (texp >=200){
system ("cls");
lvl = lvl + 1;
points = points + 3;
cout << "Congratulations " << name << "\n\n";
cout << "You have Leveled up!\n\n";
cout << "You are now level: " << lvl << "\n\n";
cin.ignore();
cout << "\nPress Enter to continue.\n\n";
cin.get();
}
else if (texp >=300){
system ("cls");
lvl = lvl + 1;
points = points + 3;
cout << "Congratulations " << name << "\n\n";
cout << "You have Leveled up!\n\n";
cout << "You are now level: " << lvl << "\n\n";
cin.ignore();
cout << "\nPress Enter to continue.\n\n";
cin.get();
}
else if (texp >=400){
system ("cls");
lvl = lvl + 1;
points = points + 3;
cout << "Congratulations " << name << "\n\n";
cout << "You have Leveled up!\n\n";
cout << "You are now level: " << lvl << "\n\n";
cin.ignore();
cout << "\nPress Enter to continue.\n\n";
cin.get();
}
}
I have attached a file of the game so that you wouldn't have to compile it, the leveling is only functional on the "Goblin" monster so if you want to test it out you would have to fight that one.