//// Squid race: Create a race for an array of creatures. //SQUIDS.JAVA THIS IS TEMPLATE FOR THE TEST PRACTICE+++ String title= "S Q U I D R A C E"; String author= "Your Name"; int many=10; int winner=-1; float surface; Squid neptune[]= new Squid[many]; ////// Setup: screen size, create array, etc. void setup() { size( 789, 654 ); surface= height/4; reset(); } ////// Create the array of squids, spaced across the window. void reset() { winner= -1; float x= 50; for (int i=0; i=0) { textSize(20); text( "G A M E O V E R", width/4, height/2 ); text( "Winner is #"+winner, width/4, 20+height/2 ); } } ////// Handle keyboard. void keyPressed() { if (key == 'q') exit(); if (key == 'r') reset(); if (key == ' ') race(); //when space bar is pressed they move } ////// Move all creatures upward, with a random value. void race() { if (winner<0) { neptune[1].y -= random( 1.5, 20.5 ); if (neptune[1].y <= surface) winner=1; // change this to make all squids affected } else { text( "SORRY -- GAME IS OVER!", width/3, height-200 ); } } //////////////////////////// CLASS Squid //////////////////// class Squid { //// PROPERTIES //// float x=50, y=height-50; // Position of this creature. float w=30, h=50; // width & height int legs=10; int r, g, b; // Color. //// CONSTRUCTORS //// Squid() { // Default constructor -- does nothing } Squid( float w, float h, int r, int g, int b) { this.w= w; this.h= h; setColors( r, g, b ); } Squid( float w, float h) { this.w= w; this.h= h; setColors( int(random(0, 255)), int(random(0, 255)), int(random(0, 255)) ); legs= int( random( 2, 12 ) ); } // Store colors in member variables. // void setColors( int r, int g, int b ) { this.r= r; this.g= g; this.b= b; } // //// METHODS //// // Display the creature. // void show() { fill( r, g, b ); rectMode(CENTER); rect( x, y, w, h ); ellipseMode(CENTER); ellipse( x, y-h/2, w, h ); eye( x, y-h*3/4); showLegs(); } void showLegs() { //++++++++++++++++++ ADD YOUR OWN CODE TO SHOW LEGS //// } void eye( float eyeX, float eyeY ) { //++++++++++++++++++ ADD YOUR OWN CODE TO SHOW THE EYE //// } }