- The Noverlap Game * You are asked to produce a simple game based on the shapes hierarchy you created in Lab03 and 03b. * The game places randomly sized circles at random locations on the screen, one by one. Clicking on a circle removes it from the screen. The game consist of five rounds. During each round ten circles are added to the display. Points are awarded at the end of each round, one point for each circle that is not overlapped by any other circle. The game gets progressively faster with each round. * You can try playing the game by downloading this [[http://www.cs.bilkent.edu.tr/~bgedik/courses/cs102/2012-fall/Noverlap.jar|Noverlap.jar]] file and running it (by double-clicking on the file or typing "java -classpath Noverlap.jar Lab04"). The maximum possible score is 150 points, but a score of 50 or more is probably very good (doing nothing usually gets you about 10 points). Don't spend too much time playing though, the real fun is in building it! * **Building the game** * Creating the project * Create a new JCreator project, Lab04b, and copy all your shape related files from Lab03 and 03b, into it. This should include ''Shape'', ''Circle'', ''Rectangle'', ''Square'', ''Locatable'', ''Selectable'', ''Movable'', and ''ShapeContainer''. * Creating drawable shapes * Create a new interface, ''Drawable'', which includes a single abstract method: ''void draw( Graphics g)'' * Make ''Circle'' and ''ShapeContainer'' implement ''Drawable''. Check your textbook and the Java API for examples. * Note: you can also do Rectangle & Square, but they are not needed for the current game. * Creating the GUI * Create a new subclass of =JPanel=, called ''ShapesCanvas''. It will simply display the shapes in the ''ShapeContainer'' that is passed to its constructor (by telling the ''ShapeContainer'' to draw itself). It should have a preferred size of ''500'' by ''500''. * Make sure all this is working by creating a ''ShapeContainer'' with a few ''Circle'' objects in it, creating a ''ShapesCanvas'' to display this ''ShapeContainer'', and adding it to an instance of ''JFrame''. * The ''ShapesGame'' class is also based on ''JPanel''. It includes an instance of your ''ShapesCanvas'', along with a ''JLabel'' at the bottom to show the points and a ''JProgressBar'' on the right to show progress in each round. You should be able to add one or more instances of it to a ''JFrame'' or to a ''JApplet''. * Handling the events * Add a ''MouseListener'' to your ''ShapesCanvas'' such that, ''mouseReleased'' first selects the ''Shape'' at the location of the mouse click (using the ''Selectable'' interface methods), then calls your ''ShapeContainer'''s ''removeSelected()'' method to actually remove it from the collection. Note that you will have to repaint the canvas to "see" the effect. * Last, but not least, add a (''java.swing'') ''Timer'' object to your ''ShapesGame'' class, that triggers an ''ActionEvent'' every ''500'' milliseconds. Have its event handler add a new (randomly sized and positioned) ''Circle'' to the collection. * Remaining "bells 'n whistles" * Have a round counter that stops the game after five rounds and a progress counter that counts the number of circles added this round (maximum ten). * Update the ''JProgressbar'' using the progress counter value. * Update the ''JLabel'' with the points scored (you will need to write a method that actually computes the number of non-overlapping circles and adds that to the points scored). * Stopping the game requires you stop the Timer and make sure mouse clicks no longer remove circles from the screen. * Congratulations, you should now have a simple interactive game. Of course, it could be improved a lot. Use your imagination and show us what you can do!