Today I had a breakthrough.
After reading a chapter about random number generation in my book on C programming I finally figured out how I'm going to achieve a task in my app that has had me stumped for ages.
In my game I'm going to have 5 different coloured bubbles and 5 'power' bubbles that will spawn randomly. For experienced programmers this probably won't cause any headaches but for me it seems pretty difficult.
Originally I was thinking I would need to apply the property directly to the bubble objects and I was hoping there would be a way to attach a probability factor to influence how often each variation of the bubbles would show up.
I finished the chapter then went back to work, whilst working it finally hit me and I started thinking like a programmer.
(once I have tested the method I will probably post a tutorial on it with code examples)
My theory is, first I will create a random number generator, using the srand() function, with 100 numbers and use the time function to generate a truly random sequence every time the game is run.
Next I will create a bubble object with 10 sub-objects (5 for the coloured bubbles and 5 for the special bubbles), I'm sure there are proper terms for this but for the moment they escape me.
I will then use a loop, I am undecided as to wether to go with an if-else loop or use a switch() statement, either way, the bubble objects will have values assigned to them, the colours will have 19 numbers assigned to each of them and the special bubbles will have the remaining 5 numbers assigned to them.
I'm going to use the loop to check for a number from the srand() function, this will then determine which bubble object is displayed.
I hope this was clear to you, if not, hopefully I will get around to creating a tutorial and that will make it clearer.
I suppose the whole point of this post is just to say, I feel like I'm starting to think like a programmer.
No comments:
Post a Comment