News:

11 March 2016 - Forum Rules

Main Menu

Organized Battle System.

Started by InfamousKnight, November 11, 2012, 01:12:18 PM

Previous topic - Next topic

BRPXQZME

srand() seeds the RNG with the single argument. It gives it a starting point for faking random numbers. They're not actually random, but for most purposes it's really close enough. On a conceptual level, you give the RNG a "seed" number. For every call to rand(), you do crazy stuff to that seed until it looks like a random number and spit it out; that random number is the new seed. Actual implementation may vary. You probably don't want to call srand() with the same value every time unless you are testing something, as on the same system, it will always give the same sequence from rand().

time(0) returns time in seconds since midnight 1 January 1970 (as long as the system clock is set accurately). This isn't good enough a seed for security but for most games it is, since very few people would bother to stack randomness in their favor by setting the system clock. This way, you get a different sequence of random numbers depending on what time the srand() function was called.
we are in a horrible and deadly danger

InfamousKnight

The reason why I made a new thread was because if I double posted or edited my post nobody would notice.. right?

BRPXQZME

On these forums, double posting or editing will mark the thread new, but without bumping it.
we are in a horrible and deadly danger

Nagato

#23
Deleted.

InfamousKnight

a range would be like:
if(rand() % 4 >= 0 && rand() % 4 <= 8) {}

that code doesn't make a lot of sense its just a sample of range. I learned about making a range in computer programming 1 in 10th grade. Apparently, that was the ONLY thing I learned that I actually care about :P

BRPXQZME

It doesn't make any sense at all. Two calls to rand() is like rolling a die twice; plus, rand()%4 will always be greater or equal than 0, and rand()%4 will always be less than or equal to 8 so you might as well omit the conditional ;)
we are in a horrible and deadly danger

InfamousKnight

#26
I know that code didn't make a lot of sense I should have wrote:
if(input >= 0 && input <= 7)

that ^ would make more sense.

I didn't know that about random numbers.. Like the 0 - 1 chance. That ain't random at all. Thanks for whoever told me about this! yeah, I forgot his username :P

November 25, 2012, 01:08:37 PM - (Auto Merged - Double Posts are not allowed before 7 days.)

Quote from: InfamousKnight on November 11, 2012, 01:12:18 PM
I've created a battle system with some pretty ugly code so I updated it breaking the good parts into sections.

Here's my new code:
http://pastebin.com/5tkVG138
Somebody suggested that I make a damage calculation function but I couldn't bother. Sorry about all the constant text in the comments. I just like yelling at the people trying to learn lol.. no.

henke37

You still have instances of forcibly seeding the random number generator. And all the other issues I pointed out aren't addressed at all.

InfamousKnight

Like putting music and a better UI in the game? I don't think I'm advanced enough for that.. 1: I do not compose music, 2: I never deal with fancy UIs. This is a console application which are typically easy to write. If I were to make graphics in my game I might use java since java and c++ are somewhat similar. I don't know ANYTHING about java except hello world and I'm also not an artist for the game sprites although I can go on videogamesprites.net for those but then again I'm not a graphics programmer..

Give me credit! This was done all by me. Meaning just one person. Professional games take at least 10 people to work on it. One person for the programming one person for the music/graphics etc.

Also, for some reason, linux wouldn't let me install the JDK with the package manager and for some reason my code doesn't work on dev-cpp on windows. Like it crashes when you start the battle.. That is like SOOO weird. It works on linux with g++ though..

BRPXQZME

Nobody is denying it's a start, but Henke here is just tellin' it like it is; this code has serious outstanding issues that really aren't outside your reach to address.
we are in a horrible and deadly danger

henke37

I actually didn't say anything about the assets or such. I pointed out that your design has a lot of strings that should be enums or pointers to objects. As well as pointing out that your design doesn't work for running all the rest of the tasks a game needs to run. Such as animations, sound and music.

It isn't that you don't have the assets to do it, but rather that the design wouldn't work even if you did.

InfamousKnight

Uh, does this game work for you on windows? For some reason, it only works on linux. No clue why it worked before on windows. There's no windows nor linux system calls in this game. Its pure c++. Please test my code. Note: I was using g++ to compile it.

LostTemplar

Maybe your compiler is on its period.

No, seriously, shouldn't your compiler say why it's not working? If it compiles, but won't run, what happens? No error messages?

I feel ashamed I even have to ask, but you are aware that you have to recompile it with a Windows compiler in order to make it work on Windows?

InfamousKnight

It compiles just fine. It crashes when the battle starts.

LostTemplar

Well, then use a debugger and look for what's wrong.