making a pokemon game

Pages: 123
I don't know how far you're going to get in C++ if you insist on avoiding dynamic memory and pre-defining every variable.
You don't need pokemon moves to instantly change, pre-defining them is fine and means you can use them over and over again on different attack slots of different pokemon without having to re-define them, and I'm not avoiding it, I just haven't been in a situation where I need to use dynamic memory, and hopefully won't be in one for a while, deleting dynamic memory is a real annoyance, isn't that what code is all about? making the life of the programmer easier? well I'm sure you will disagree, but I believe it is.
Last edited on
IMO, it would be better far better to have one copy of all the moves stored in a file somewhere (since they never change) then just have the Pokemon have pointers to each one.

As for the Pokemon themselves...I don't remember if the stats are "random" or not, if they are, then I'd randomly generate them, otherwise you could probably get by with just each Pokemon having some functions that generate the stats based on levels/exp which you store somewhere. That storage would be dynamically generated based on how much you need, of course.
They aren't random, they gain different stats when they level up depending on the pokemon they knock out, but it isn't important.
that is true, they would need to be defined in the class, so you can just declare them as static constant variables inside the attack class, ie:

1
2
3
4
5
6
7
8
class Attack
{
public:
	static constant Attack Hydropump (120, 5, 75),
		Ember (40, 30, 95),
		Splash (0, 15, 0),
		Dig (90, 20, 90);
}


and then refer to them via: Attack::Hydropump, etc

PS. im not at war with anyone, just trying to help any way i can :/ i personally am having my own issues with Assertion errors in an almost completed balanced binary search tree >.<
so i figured, while im stuck why not come on here :)
Last edited on
I think code is about making the life of the user easier.

As far as having to re-define, you don't have to re-define them every time you use them. You can have a variable that doesn't change over the course of the program. The way you're doing it, what happens if you want the ability to level an ability up? If you're using const variables, then you get stuck with having to write the same code multiple times in order to define the same thing.

In addition, if you use classes the right way (define an object, then make instances of that object), you only have to write that code one time, and then just fill in the blanks whenever you come up with a new attack, say if you wanted to add in attacks that were just released as a result of a new game coming up. If you have them hard-coded in, you can't do that, you'll have to re-compile the whole program.

Also, with dynamic memory, you gain the ability to increase the number of objects (attacks, pokemon, trainers) that you have stored, and you can make a full-fledged game out of the deal. Avoiding these incredibly powerful and incredibly useful tools won't help your program at all, and using them won't automatically cause you to have to define the same attack repeatedly.
well honestly you could add a few stats and make the level up linear, ie:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
class Attack
{
private:
	int power,
		pp,
		accuracy,
		lvlpower,
		lvlaccuracy,
	
	std::string name;
	
public:
	Attack (int power, int pp, int accuracy, int lvlpow, int lvlac, std::string name)
	{
		this->name = name;
		this->power = power;
		this->pp = pp;
		this->accuracy = accuracy;
		this->lvlpower = lvlpow;
		this->lvlaccuracy = lvlac;
	}
	
	std::string GetName { return this->name; }
	int GetPower (int lvl) { return (this->power + (this->lvlpower * lvl)); }
	int GetAccuracy (int lvl) { return (this->accuracy + (this->lvlaccuracy * lvl)); }
}


and just store the level for each ability in the pokemon class
Last edited on
Well, now there are new errors on top of the old ones, I was able to get it to compile by just putting it in main, but that is just a hack.

the errors are along the lines of..

1
2
expected identifier before numeric constant|
expected ',' or '...' before numeric constant|


where the moves are being declared.

and cipher..

Why should the user care as long as it works? he doesn't have to mess with the code, unless he is also the coder, in which case he still shouldn't care, if the interface is good enough and the code doesn't suffer from performance issues.

as for not re-defining them, explain, I don't see how you can make a new attack slot for a different pokemon with your code using a move that was defined earlier without defining it again, unless your more experienced eyes have seen something I haven't.

Unless you are either using a file or a scripting language, don't you have to recompile the whole program? and if I didn't define my object and then make instances of it, please explain to me where I went wrong.

I don't understand what you mean by dynamic memory, I'm talking about new/delete, are you as well? maybe that isn't called dynamic memory, uh private memory? personal memory? the stack? I haven't used it so I'm not familiar with what people generally call it.
Last edited on
No, the user doesn't have to know how it works, but if every end user could write code, what would the point in programming for a living be? We deal with the details on the back end so that they have a quality product on the front end.

You don't have to re-define anything. You can just make an instance of attack called Dig, and then for every pokemon that has the ability to Dig, just have them refer to that instance. I would do that with pointers. Then you only define it once, and use it across your entire program without having to change anything at all.

You don't have to recompile a program unless the code itself is changed. If you're only changing the data that's being entered into the program, then you don't need to compile again, just use the same bin.

Dynamic memory is new/delete, the memory that gets put on the stack. It's used to create a number of instances of any specific type at compile time, so that the users can decide how many of what they need, instead of having some sort of imposed limit on it.
you just dont want to have to keep allocating new memory and deleting it which is more taxing on the system which makes sense

as far as the errors ill compile this in a bit

also, since when do pokemon attacks level?
Last edited on
Edit: gfreak

pokemon attacks don't level, I was referring to their stats (attack, spec attack, etc), although there are items that can increase the maximum PP of moves, I don't remember their names but essentially a 5 PP move would become a 8 PP move, for that pokemon only of course.

I understand that cipher, but imagine if programmers didn't have loops but could use recursive functions, would that make it easier or harder for the programmer? the same goes for having to constantly delete memory, perhaps not easier/harder, and I'm sure there are some situations where it is best to use it or it wouldn't even be there, but if you can avoid it by doing it another way, then why not avoid it? IMO having to add a whole extra line each time you use dynamic memory would annoy me endlessly.

Okay, here is your code cipher:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class attack
{
private:
    std::string mName;
    int mPower, mPP, mAccuracy;
public:
    attack(const std::string& inName, int inPower, int inPP, int inAccuracy);
    ~attack() {}
};

attack::attack(const std::string& inName, int inPower, int inPP, int inAccuracy)
{
    mName = inName;
    mPower = inPower;
    mPP = inPP;
    mAccuracy = inAccuracy;
}

int main()
{
    attack *att1 = new attack("HydroPump", 120, 5, 75);
    attack *att2 = new attack("Ember", 40, 30, 95);

    ...
    delete att1;
    delete att2;
    return 0;
}


how would you assign Hydropump to slot 3 without redefining it? for example, not like this:

1
2
3
4
5
...
attack *att1 = new attack("HydroPump", 120, 5, 75);
attack *att2 = new attack("Ember", 40, 30, 95);
attack *att3 = new attack("HydroPump", 120, 5, 75);
...


I'm not trying to be annoying, sorry if it seems that way, I just really want to know how, I don't often get to be in a situation of 'interactive dynamic learning' and I'm finding it hard to understand how you would use a pointer for reusing that definition, so when I get the chance to prod someone about something, I like to take it :b

how would you add new moves without adding code to the program if you aren't using a scripting language or editing a file?
Last edited on
You would include a copy constructor, and then just
attack *att3 = att1;
wouldn't that be in the local scope only though?
1
2
3
4
5
...
attack *att1 = new attack ("HydroPump", 120, 5, 75);
attack *att2 = new attack ("Ember", 40, 30, 95);
attack *att3 = att1;
...

???

as far as the pp, you could add things like that to the pokemon class, just like you would keep track of each abilities current pp available, you would have to keep track of any additional pp they have, thats not to be saved in the ability but the pokemon itself, and the actual damage/stats of each ability should be calculated upon using it, not a constant, ie: use the ability, calculate attacker offense - defender defense, reduce/increase damage by a percent determined by that, roll dice, check if its a in a certain percent, if so do critical (double) damage, if not do regular damage, all of that should be a combination of the power of the ability and the pokemons stats etc
Last edited on
that isn't going to work when your pokemon levels up and decides it doesn't like hydropump anymore, and instead wants to learn splash, and then next time it levels up it wants to learn hydropump on slot 3. it also isn't global, you would have to define att1 each time and then define att3.
Last edited on
i agree that my way of doing it is better, but i also get what cipher was saying, its all dependent on whether the memory is more important or processing the information, also, if it does not matter in the long run then ease of use is what matters
Your way doesn't work yet :b but when it does, it will be the better choice.

add some file i/o to it and it'd be even better. (talking about moves)
Last edited on
???
you mean an animation file for the moves?
or a file string?

i was considering adding attack type options (ice/water/fire/thunder/earth/etc)

but as far as that goes, why dont you try and re-create it, including all the info you want to be saved in each class then get back to me with any issues you run into (teach a man to fish)
Last edited on
re-create what? your code? why would I do that? and I can fish, perhaps not very well, but I can fish.

I mean a text file with all the moves in it, it was a suggestion, nothing more, your code isn't for me anyway, its for whoever started this thread on the previous page.
Last edited on
???
you mean an animation file for the moves?
or a file string?


Something like:
Name Pow Acc BasePP //This line is not actually in the file
Scratch 10 100 40
//etc


Then you can just load them all from the file and if you need to add more it's really easy (don't even need to recompile your code).
Pages: 123