// Diver catches fish -- Final Exam: arrays of fish, divers, buttons. String author= "WHO ARE YOU????"; String title= "Final Exam for "+author; String help= "ADD YOUR CODE TO THIS TEMPLATE \n (and remove this message)";; float surface=100, bottom=480; int nf=7, nd=6, nb=nd+2; Fish[] fishArray= new Fish[nf]; Diver[] diverArray= new Diver[nd]; Button[] buttonArray= new Button[nb]; color[] colorArray= { #FF0000, #FF9900, #FFFF00, #00FF00, #00FFFF, #FF00FF, #6666FF, #999999 }; // Colors for divers: 1 2 3 4 5 6 7 8 // RED ORANGE YELLOW GREEN CYAN MAGENTA BLUE GRAY void setup() { // setup // size( 640, 480 ); restart(); } void restart( ) { // Make fish 50 apart, at y=150, 20, 250, ... float y=surface+50; for (int j=0; j0) triangle( x+40,surface, x+40,surface-20, x+40+20,surface-20); if (dx<0) triangle( x,surface, x,surface-20, x-20,surface-20); fill(0); text( "#"+n, x+5,surface-5 ); text( total, x+20,surface-25 ); // Show total //-- fill(r,g,b); fill(c); // Diver if (dy>0) { /***************** INSERT YOUR CODE HERE ***************/ text( caught, x+20,y-10 ); // How many fish caught (on this dive). } if (dy<0) { /***************** INSERT YOUR CODE HERE ***************/ } } void move() { // Move boat/diver. if (dy==0) { // Boat is moving. (Diver is not diving.) /***************** INSERT YOUR CODE HERE ***************/ } else { // Diver is still diving. /***************** INSERT YOUR CODE HERE ***************/ } } void dive() { //// Stop the boat & start the dive. y= surface+50; dy=1; caught=0; } void net( Fish f ) { //// Check if diver nets fish if (dy==0) return; // Not diving. if (dist(x,y, f.x,f.y) < 50) { // Fish is near. if (dy>0) { // Descending: catch the fish.d /***************** INSERT YOUR CODE HERE ***************/ } else { // Lose the entire catch, if diver bumps into a fish. /***************** INSERT YOUR CODE HERE ***************/ } } } boolean hit( float xx, float yy) { //// True if xx,yy is near this diver. boolean result=true; /***************** INSERT YOUR CODE HERE ***************/ return result; } void reset() { //// Reset diver. if (dy==0) x=50; // Boat stops.goes back to left side. if (dy>0) y=surface+50; // If diving, start again at surface. if (dy<0) y=bottom; // If ascending, go back to bottom.. } } class Button { //// Button (kind: 1,2,5) float x, y; float w=60, h=30; int r=200,g=200,b=200; int kind=2; // Rectangular button. int n=0; String s="# "; color c; // CONSTRUCTORS // Button( String s, int kind, float x, float y, color c ) { this.s= s; this.kind= kind; this.x= x; this.y= y; this.c=c; } /*************** ADD MORE CONSTRUCTORS HERE **********/ // METHODS: show button, detect click void show() { // Draw the button //-- fill( r,g,b ); fill(c); if (kind==1) { /***************** INSERT YOUR CODE HERE ***************/ ellipse( x,y, w,h ); } if (kind==2) { /***************** INSERT YOUR CODE HERE ***************/ } if (kind==3) { triangle( x,y-h, x-w/2,y+15, x+w/2,y+15 ); } if (kind==5) { rect( x,y, w,h, 15 ); } // Text within button. /***************** INSERT YOUR CODE HERE ***************/ fill(0); text( s, x+10-w/2, y+10 ); /**** REMOVE OR MODIFY THIS, IF NECCESSARY. ****/ } boolean hit( float xx, float yy) { //// True if x,y are within this button. boolean result=false; if (kind==2 || kind==5) { //// True if (xx,yy) is within rectangular button. // /***************** INSERT YOUR CODE HERE ***************/ } else { // Use dist() for other kinds. result= ( dist(xx,yy, x,y) < w/2 ); } return result; } }