Modify a text file: $/final/final.java.java
$/final/final.java.java
//// CST-112 FINAL EXAM -- Steven Warren //// String student="Steven Warren"; String title="CST-112 FINAL EXAM: " + student; String news= "Click to move objects"; //////// GLOBAL DECLARATIONS //////// int score=0; int maxbugs=6; int numbugs=5; float grass; float left=50, top=50, right=750, bottom=550; Animal zoog, cat, bird, bird2; Animal submarine; Animal ant; Animal[] bugs= new Animal[maxbugs]; // +++++ ADD YOUR DECLARATIONS HERE, // +++++ to create array of 5 bugs. //////// SKETCH FUNCTIONS //////// void setup() { //// Setup. size( 800, 600 ); right=width-50; bottom=height-50; reset(); } void reset() { //// initialize the menagarie. cat= new Animal( 50, 30, 20, 4, 0 ); cat.setRGB( 200,150,50 ); cat.x=100; cat.y=100; cat.name= "cat"; // zoog= new Animal( 40, 80, 0, 2, 7 ); zoog.setRGB( 200,150,150 ); zoog.x= 200; zoog.y= 200; zoog.name= "Zoog"; // bird= new Animal( 3,0,0, 50, 15, 12, 0, 0 ); bird.setRGB( 50,50,250 ); bird.x= 300; bird.y= 300; // bird2= new Animal( 3,0,0, 50, 15, 12, 0, 0); bird2.setRGB( 255,0,0 ); bird2.x= 200; bird2.y= 200; // submarine= new Animal( 100,50,.05,8 ); submarine.setRGB( 155,0,255 ); submarine.x= 400; submarine.y= 400; submarine.name= "Nautilus"; // ant= new Animal( 6,0,3, 15,45, 255,50,50 ); ant.y= bottom ; //// Creat five bugs //// for (int i=0; i
right-20 ) { // Float off end; new ant. ant= new Animal( 6,0,3, 15,45, 255,0,0 ); ant.y= bottom; } } for (int i=0; i
right-20) { bugs[i]= new Animal( 6,0,3, 15,45, 255,0,0 ); bugs[i].y= bottom; } } } //// Move the bugs -- same as the ant. // ++++++++++ YOUR CODE GOES HERE. +++++++++++++ // } void crash() { //// Check for collisions //// // zoog kicks the cat (+50) -- move cat to right side. if (zoog.hit( cat ) ) { cat.x=right-20; score += 50; } // cat catches bird (-100) -- move bird to left side. if(cat.hit( bird ) ) {bird.x=left; score -= 100; } // ++++++++++ YOUR CODE GOES HERE. +++++++++++++ // // bird hits Zoog (-50) -- move Zoog to random position. if(bird.hit( zoog ) ) {zoog.x=top; score -= 50; } // ++++++++++ YOUR CODE GOES HERE. +++++++++++++ // // bird catches any bug (+10) -- start new bug at bottom // ++++++++++ YOUR CODE GOES HERE. +++++++++++++ // for (int i=0; i
right) dx= -dx; if (y
bottom) dy= -dy; //// x += dx; y += dy; } void show() { //// Draw the Animal on the screen //// rectMode( CENTER ); ellipseMode( CENTER ); fill(r,g,b); //// Front & back depend on dx //// float front=x+wide/2, rear=x-wide/2; if (dx<0) { front= x-wide/2; rear= x+wide/2; } //// Draw different shapes. //// if (shape == 0) { ellipse( x, y, wide, tall ); } else if (shape == 4) { rect( x, y, wide, tall ); } else if (shape == 3) { triangle( front,y, rear,y-tall/2, rear,y+tall/2 ); triangle( front,y+20,rear,y+25,rear,y); rect(rear-5, y,20,20); } else if (shape == 2) { ellipse(x,y,wide,tall); // ++++++++++ ADD YOUR CODE HERE. +++++++++++++ // } else if (shape == 6) { ellipse(x,y-tall*2/3, wide, tall/3 ); ellipse(x,y-tall/3, wide, tall/3 ); ellipse(x,y, wide, tall/3 ); reach= 8; } else { // ++++++++++ ADD YOUR CODE HERE. +++++++++++++ // text( "undefined object is here!", x, y ); } //// Head if (head>0) { // Head (if any) // ellipseMode( CENTER ); ellipse( front, y-tall/2-head/2, head, head ); // Head at front rect( rear, y-tall/2, 20, 6 ); // Tail at rear } limbs(); //// Name fill( 256-r, 256-g, 256-b ); text( name, x-wide/3, y-tall/6 ); } void limbs() { //// Legs & Arms //// float legX= x - wide/2; // First leg is at the left float legY= y + tall/2; // Legs start at bottom of rectangle. if (legs > 0) { line( legX,legY, legX,legY+reach ); // First leg. } if (legs > 1) { float legSpacing= wide / (legs-1); for (int i=1; i
this.x + this.wide/2) return false; if (y < this.y - this.tall/2) return false; if (y > this.y + this.tall/2) return false; return true; } boolean hit( Animal other ) { //// Return true iff other hits this one. return hit( other.x, other.y ); } }