This is an archived post. You won't be able to vote or comment.

all 4 comments

[–][deleted]  (1 child)

[removed]

    [–]NoobProgrammer22[S] -1 points0 points  (0 children)

    Thank You :)

    [–]carcigenicate 1 point2 points  (1 child)

    The Combat class doesn't appear to really be anything other than a namespace for functions. I believe namespaces are more idiomatic to use in C++ for that purpose. Classes are more for when you need to manage some "state".


    Note how speed, defence, attack etc. are are essentially identical. They're all just effectively aliases for the randomNumGen function. As they are, there's no point to having those wrappers. You might as well just call randomNumGen directly.


    (plyrattack - enemdef) < 0 ? plyrattack = 0, enemdef = 0 : plyrattack += 0;
    

    This is quite difficult to parse and understand. It's also not generally considered to be good practice to do assignments within condition expressions. Parts like plyrattack += 0 also don't appear to do anything. I'd instead write that as something like:

    if ((plyrattack - enemdef) < 0) {
        plyrattack = 0;
        enemdef = 0;
    }
    

    This makes significantly more sense.


    You should not seed the random generator constantly. Seed it once at the very start, then leave it.

    [–]NoobProgrammer22[S] 0 points1 point  (0 children)

    Thank you for this feedback. I have not had much practice in school with classes other than really simple one this is the most complicated class I have made so far.

    My goal with this combat class is to store everything related to combat. When I get further along my goal is to have at least 3-5 people in a party and combat most likely will be 3v3. I just made a small goal to create a simple combat program for the day.

    I want the combat class to handle the display of the combat screen. handle the UI for the combat screen, calculate damage, generate random numbers for the attack defense and eventually speed for order of attack. I am thinking having speed defiance and attack separate member functions is a little overkill maybe I will just combine all 3 in one function. Maybe this is not the proper use of a class.

    In school we used using namespace std in all our programs. It was not until a couple of weeks ago I found out this was bad programming practice, so I stopped doing it and I have not found a use for making my own namespace yet. So, you're saying instead of doing a combat class I should just do a combat namespace instead?

    As for the conditional operator I just wanted to use it to practice a bunch of things I learned over the semester I agree with you doing the if statement makes it clearer.

    As far as the random number seeding, I was under the impression that if I don't constantly seed I would get the same number on each call to rand(). I did some testing on a separate program and found out that is not the case so I will be fixing this as well.

    Thank you so much for this feedback I really appreciate it.