Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7029719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:34:33+00:00 2026-05-28T00:34:33+00:00

Please tear this code apart, make it complex and scarcely readable, I’d rather learn

  • 0

Please tear this code apart, make it complex and scarcely readable, I’d rather learn the hard way once than learn the same thing many times the wrong way.

The base class is as follows:

class baseMob{
private:
    int _healthMax;
    int _healthCurrent;
    int _manaMax;
    int _manaCurrent;
    int _experiencePoints;
public:
    //Set max Hp
    void setHealthMax(int);
    //Get max Hp
    int getHealthMax();
    //Set Current Hp
    void setCurrentHealth(int);
    //Get Current Health
    int getCurrentHealth();
    //Set Max Mana
    void setMaxMana(int);
    //Get Max Mana
    int getMaxMana();
    //Set Current Mana
    void setCurrentMana(int);
    //Get Current Mana 
    int getCurrentMana();
    //getMob Exp on kill
    int getExperiencePoints();
    //Set mob Exp points
    void setExperiencePoints(int);
//leaving out the member functions for space conservation

};

The individual mob that I’m trying to create is a green slime, which I’m trying to create via the default constructor I’ve made…

   class greenSlime: private baseMob{
    public:
        greenSlime(){
            setHealthMax(100);
            setMaxMana(100);
            setCurrentHealth(100);
            setCurrentMana(100);
            setExperiencePoints(150);
        }
    };

My main function looks like this right now:

 greenSlime slime();
    for(; slime.getCurrentHealth() >= 0; slime.setCurrentHealth(-1)){
        cout << "The current health of the slime is: " << slime.getCurrentHealth() << endl;
        if (slime.getCurrentHealth() <= 0 ){
            cout << "Player is awarded with: " << slime.getExperiencePoints() << " Experience. ";
        }
    }

If anyone wants to tear this up and make me look like a jackass, I’d really appreciate the help.

The error that I’m presently getting is:

Project1.cpp:107: error: request for member getCurrentHealth' inslime’, which is of non-class type `greenSlime ()()’

Along with other errors of the same type.

Tl;Dr: Class implementation isn’t working, posted all my source when I probably could’ve posted about 1/10th of this and still made sense, and would love to have someone tell me why it’s not working and how bad I am.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T00:34:33+00:00Added an answer on May 28, 2026 at 12:34 am

    Others have pointed out problems in terms of why your code doesn’t work. I’ll make a recommendation about program design.

    When explaining inheritance, tutorials and programming classes frequently use toy examples that are very similar to your code. These examples show what inheritance is, but really aren’t very good at showing what inheritance is useful for.

    I wouldn’t use inheritance in this case. I think a better design is to have a class that represents the mob type and holds all the data that is static for all that mob of that type, such as the mob name, starting/max HP, attack types, etc. And then have another class where each instance represents a specific mob and holds data that changes for that mob, such as current hp.

    class Mob_type {
        string name;
        int max_hp;
        vector<shared_ptr<Attack_type>> attacks;
    public:
        Mob_type(string name,int max_hp,vector<shared_ptr<Attack_type>> attacks)
        : name(name),max_hp(max_hp),attacks(attacks) {}
        int get_max_hp() const { return max_hp; }
    };
    
    class Mob {
        Mob_type const &type;
        int hp;
    public:
        Mob(Mob_type const &type) : type(type), hp(type.get_max_hp()) {}
        Mob_type const &get_type() const { return type; }
        int get_hp() const { return hp; }
    };
    
    void print_health(Mob const &m) {
        cout << m.get_hp() << '/' << m.get_type().get_max_hp() << '\n';
    }
    
    int main() {
        vector<shared_ptr<Attack_type>> attacks; // ...
        Mob_type green_slime("Green Slime",50,attacks);
    
        Mob green_slime_A(green_slime), green_slime_B(green_slime);
    
        fight(green_slime_A,green_slime_B);
    
        cout << "A: ";
        print_health(green_slime_A);
        cout << "B: ";
        print_health(green_slime_B);
    
    }
    

    This way you can have a data file that contains the mob types and all you have to do to add a type is to update the data file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please see the code below. Basically, when the user creates an object of this
Please consider this example class: [Serializable] public class SomeClass { private DateTime _SomeDateTime; public
Please, provide code examples in a language of your choice. Update : No constraints
Please consider this Query: SELECT tesd.State_Code, tesd.City_Code, tesd.Row_ID, tesd.Qsno, tesd.Total_Period, tesd.Current_Period, tesd.Week, tesd.Block_No, tesd.Family_ID,
Please consider the following code: #include <iostream> #include <typeinfo> template< typename Type > void
Please Help me to do this first i have this div <div class=loader alt=stat.php>
Please tell me why i am getting ClassCastException in this case I have type
Please advise me a jQuery carousel plugin that can make a carousel like the
Please help me out, i came across this script in my project. Is this
Please how can I use spl_autoload_register() with Codeigniter? I need to do this because

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.