You have to create one or several classes, drawing the shape(s) you want. If you have several classes, they must implement the same interface, allowing to store heterogeneous but consistent data in the array.
Let's call it Shape (original...):
- interface Shape
- {
- void draw();
- }
You can put other methods in there, eg. void move() or similar.
Then your classes implement the interface:
- class Rectangle implements Shape
- {
- // Usual stuff in classes: fields, constructor, etc.
-
- // Mandatory, because of the implements clause
- void draw()
- {
- // Some graphical inits
-
- // And draw
- rect( ... );
- }
- }
Idem for Ellipse and Line
Then you can make an array of Shape objects: you are sure that whatever the Shape, you can call the draw() method in it:
- Shape[] shapes = new Shape[SHAPE_NB];
- shapes[0] = new Rectangle( ... );
- // etc.
-
- // And pick a random one to draw it
- shapes[int(random(0, shapes.length))].draw();