| Objects and Classes - Part 3 (Java) | |
|---|---|
| Tweet Topic Started: Jul 13 2007, 11:08 AM (800 Views) | |
| rig | Jul 13 2007, 11:08 AM Post #1 |
|
1a5a6a4
![]()
|
Note: Some of this has been partially covered but its good to know stuff again and possibly different uses and more. Firstly some terms to know Void - Returns nothing Random gen = new Random(); //Creates a new random number generator gen.nextInt(SomeNumber); //nextInt() is a method for the generator object //Which actually generates the random number, from zero to SomeNumber Constructor - What sets the object to be different from others Instanziation - Where we create the object, using our decided constructor Overloading - Rather than dice(), its be dice(x), or dice(x,y) -- Another constructer except this one is when there is "too much for the other to handle" i.e. the name overloading. You may be wondering... classes? "I think I already know how to make those", or "Classes? What are you talking about?"
Does that explain classes good enough? I hope, but actually classes are things that do things... simplify things, so you dont have to do them over and over again. "Instances" of classes are called objects (Seems easy enough, especially if you know GML). Instead of ball.x, think dice_a.roll, although there'll be much much more.
How do we determine how many sides the die has... here is how
Great... so now in our main program we can do this:
Depending on your compiler you may need to show some inheiritance but that depends on your compiler so I cant help on that, it might say in error messages when you attempt to compile. Now how do we get a random number from this die? Add this to your dice class.
Once you understand this, you can also combine the two or make other variations too. ...Now lastly lets go back to our main program
Any questions, comments, things that didnt quite make sense, I worded badly, or didnt quite finish an idea, please tell me so I can further improve the quality of my tutorials! ->->->->->->->->->->->->->->->->->->->->->->->->->->->->->-> Here is the final dice class:
Final Program Code:
|
| |
![]() |
|
| 1 user reading this topic (1 Guest and 0 Anonymous) | |
| « Previous Topic · Tutorials · Next Topic » |







3:20 AM Jul 11