patterncppMinor
Text-based RPG in C++
Viewed 0 times
textbasedrpg
Problem
It is currently unfinished; only
Please give detailed feedback and/or quality explanations on improvements or fixes; I'm brand new to C++ and don't know a lot.
```
#include
#include
#include
#include
#include
int main()
{
int warrior, mage, rogue, priest;
int class1, classID;
int HP, mana, manaCost, attack, abilitydmg;
int hpPots, manaPots, potionInv;
hpPots = 0;
manaPots = 0;
std::string abilityname;
std::cout > class1;
switch(class1)
{
case 1:
classID=1;
std::cout > hunt;
std::cout > trail;
if(trail==1)
{
std::cout > caveEnter;
if(caveEnter==1)
{
std::cout > fight1;
if(fight1==1)
{
goblinFight:
loot = rand() % 3 + 1;
srand(time(NULL));
std::cout > action1;
std::cout > fight2;
if(fight2==1)
{
skeletonFight:
loot = rand() % 3 + 1;
srand(time(NULL));
std::cout > action2;
std::cout > giantAction;
switch(giantAction)
{
case 1: std::cout > giantFight;
giantHP = giantHP - 7;
if(giantFight==1)
{
giantFight:
std::cout > action3;
std::cout > riddleAnswer;
if(riddleAnswer==2)
{
std::cout << "You have correctly answered my riddle. I shall leave i
case 1 of the switch(hunt) is available for choosing. Please give detailed feedback and/or quality explanations on improvements or fixes; I'm brand new to C++ and don't know a lot.
```
#include
#include
#include
#include
#include
int main()
{
int warrior, mage, rogue, priest;
int class1, classID;
int HP, mana, manaCost, attack, abilitydmg;
int hpPots, manaPots, potionInv;
hpPots = 0;
manaPots = 0;
std::string abilityname;
std::cout > class1;
switch(class1)
{
case 1:
classID=1;
std::cout > hunt;
std::cout > trail;
if(trail==1)
{
std::cout > caveEnter;
if(caveEnter==1)
{
std::cout > fight1;
if(fight1==1)
{
goblinFight:
loot = rand() % 3 + 1;
srand(time(NULL));
std::cout > action1;
std::cout > fight2;
if(fight2==1)
{
skeletonFight:
loot = rand() % 3 + 1;
srand(time(NULL));
std::cout > action2;
std::cout > giantAction;
switch(giantAction)
{
case 1: std::cout > giantFight;
giantHP = giantHP - 7;
if(giantFight==1)
{
giantFight:
std::cout > action3;
std::cout > riddleAnswer;
if(riddleAnswer==2)
{
std::cout << "You have correctly answered my riddle. I shall leave i
Solution
You have a lot to do ;)
Three main problems:
-
Try to divide it to smaller functions - you can start with making every
-
Early declarations of variables. Try to declarate it as late as possible - for example just before first assigment of the value.
-
Very mysterious variable names. What is
And the home excercise for you - think about how can you avoid
Three main problems:
-
main() large as big as blue whale! Try to divide it to smaller functions - you can start with making every
case of top-level swich a separate function! (It will be easy then to introduce classes and make code objective)-
Early declarations of variables. Try to declarate it as late as possible - for example just before first assigment of the value.
-
Very mysterious variable names. What is
class1? I realized it only after reading content of first cout. But what if this content will be in some foreign langue? Name variables more descriptively... even too descriptively! When you will be very experienced programmer, you will know how to make good names. But now, I recommend you to create too long and too descriptive variable names. And the home excercise for you - think about how can you avoid
goto statements!goto itselves are not pure evil. But the usage of them very often is a sign that somewhere in the code, there is something very bad.Context
StackExchange Code Review Q#106383, answer score: 3
Revisions (0)
No revisions yet.