patterncppMinor
Text-based RPG (WIP)
Viewed 0 times
wiptextbasedrpg
Problem
I wanted to see how this code looks, what can be improved and how those improvements can be implemented. I'm still new to C++ so I hope it isn't too sloppy.
```
#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)
{
```
#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)
{
Solution
Right off the bat, I would suggest learning about Object Oriented Programming. Each character type should be a separate class, each with its own set of attributes, probably inherited from a main character class.
All that code in main, should be pared down to a bunch of functions. right now everything is so intricately dependant, that any changes you try to make will be nightmare
All that code in main, should be pared down to a bunch of functions. right now everything is so intricately dependant, that any changes you try to make will be nightmare
Context
StackExchange Code Review Q#155805, answer score: 3
Revisions (0)
No revisions yet.