//If your name is "Xsample Your Zname" then you'll probably need some code like this: int many = 6; Dog [ ] xyz = new Dog [ many ]; //Create an array of dogs boolean gameover = false; String [ ] names = { "Rover", "Fido", "Pooch", "Butch", "Twinkles", "Spot" }; String title = "Dog Race"; String author = "author"; void setup ( ) { //Initialize size( 800, 650 ); /* xyz [ 0 ] = new Dog ( 100, "Rover" ); xyz [ 1 ] = new Dog ( 200, "Fido" ); xyz [ 2 ] = new Dog ( 300, "Pooch" ); xyz [ 3 ] = new Dog ( 400, "Butch" ); xyz [ 4 ] = new Dog ( 500, "Twinkles" ); xyz [ 5 ] = new Dog ( 600, "Spot" ); */ for ( int j = 0; j < x y z. length; j++ ) { xyz [ j ] = new Dog ( 100 + j * 100, names [ j ] ); } reset ( ); } void reset ( ) { //Start all dogs at x=50; random colors for ( int j = 0; j < many; j++ ) { xyz [ j ] .x =50; float w = random ( 50, 80 ); xyz [ j ] .w =w; xyz [ j ] .h = w / 2 + random ( 10 ); xyz [ j ] .c = color ( 100 + random ( 150 ), 50 + random ( 50 ), random ( 50 ) ); } gameover = false; } //NOTE: The draw ( ) method draws all objects, but does NOT move them void draw ( ) { //Draw all objects, but do not move them background ( 150, 200, 150 ); scene ( ); //background, scene, and text help ( ); //Show all objects on the screen for ( int j = 0; j < many; j++ ) { xyz [ j ] .show ( ); } //Check for leader/winner int k = leader ( xyz, many ); if ( xyz [ k ] .x + xyz [ k ] .w > width - 50 ) { gameover = true; text ( "GAME OVER", 100, 20); text ( "WINNER IS " + xyz [ k ] .name, 100, 40); xyz [ k ] .ring ( ); } else if ( key == 'd' ) { //d key displays the positions of the top dog if ( xyz [ k ] .x > 50 ) { text ( "The top dog is" + xyz [ k ] .name + "at x=" + xyz [ k ] .x, 100, 30 ); } } } void scene ( ) { //Draw the racecourse including green and red lines text ( title, width / 2 - 50, 10 ); text ( author, 10, height - 20 ); // stroke ( 0, 255, 0 ); //Green starting line strokeWeight ( 8 ); line ( 50, 50, 50, 600 ); //Red finish line stroke ( 255, 0, 0 ); strokeWeight ( 8 ); line ( width - 50, 50, width - 50, 600 ); //Racetracks strokeWeight ( 4 ); stroke ( 0, 0, 255 ); for ( int j = 0; j < many; j++ ) { float lineY = 100 + 100 * j; line ( 50, lineY, width - 50, lineY ); } } void help ( ) { //Instructions int n = 1; float x = width - 200; text ( "Space-bar to move all dogs", x, 12 * n++ ); text ( "click to turn any dog around", x, 12 * n++ ); text ( "d to display leader", x, 12 * n++ ); text ( "r to restart (with random size & color)", x, 12 * n++ ); } int leader ( Dog [ ] a, int m ) { //Return the index of the lead dog (ie greatest X) int w = 0; for ( int j = 0; j < m; j++ ) { if ( xyz [ j ] .x > xyz [ w ] .x ) w = j; } return w; } void mousePressed ( ) { //Check if any dog was clicked; if so, turn him around for ( int j = 0; j < many; j++ ) { if ( xyz [ j ] .hit ( mouseX, mouseY ) ) { xyz [ j ] .turnaround = true; xyz [ j ] .x -= random ( xyz [ j ] .w ); } } } void keyPressed ( ) { //Handle key-press // Determine WHICH key was pressed and respond to it if ( key ==' '){ //Space key moves all objects (unless game over) if ( ! gameover ) { for ( int j = 0; j < xyz .length; j++ ) { xyz [ j ] .move ( ); } } } else if ( key == 'r' ) { //R key restarts the game reset ( ); } } //you'll need a class definition something like this: //CLASS DEFINITION: Define dog class class Dog { float x = 50; //X coordinate starts at 50 float y; //Y coordiantes for this dog String name; //Name of this dog color c; //Color of this dog boolean turnaround = false; //This dog faces left when true // float w = random(50,80); float h = w / 2 + random ( 10 ); //CONSTRUCTORS Dog ( float yset, String nameset ) { this .y = yset; this .name = nameset; } //METHODS void show ( ) { //Draw the object at ( x, y ) float leg = h / 2; fill ( c ); noStroke ( ); rectMode ( CORNERS ); rect ( x, y - h - leg, x + w, y - leg ); //Body //Head float ww = w / 3, hh = h / 3; //width 7 height of head float xx = x + 5, yy = y - h + 5 - leg; //X,Y position of head if ( turnaround ) { xx = x + 5; rect ( xx - ww, yy - hh, xx, yy ); //Head facing left stroke ( c ); //Tail xx = x + w; line ( xx, yy - hh + 8, xx + 15, yy - hh - 8 ); } else { xx = x + w; rect ( xx, yy - hh, xx + ww, yy ); //Head facing right stroke ( c ); //Tail xx = x; line ( xx, yy - hh + 8, xx - 15, yy - hh - 8 ); } fill ( 0, 0, 150 ); text ( name, x, y - h, x + w, y ); //Name in dark blue //Legs strokeWeight ( 6 ); stroke ( c ); line ( x, y - leg, x, y ); //Straight legs line ( x + w, y - leg, x + w, y ); int walk = int ( x ); if ( walk %2 == 0 ) { line ( x, y - leg, x + leg, y ); //Legs going forward line ( x + w, y - leg, x + leg + w, y ); } else { line ( x, y - leg, x - leg, y ); //Legs going backward line ( x + w, y - leg, x - leg + w, y ); } } void move ( ) { //Move the object's x coordinate turnaround = false; //face forward x += random ( 10 ); } boolean hit ( float mx, float my ) { //Return true if ( mx, my ) is within the rectangle float leg = h / 2; return ( mx > x && mx < x + w && my > y - h - leg && my < y - leg ); } void ring ( ) { //Draw red ring around this dog noFill ( ); stroke ( 255, 0, 0 ); strokeWeight ( 10 ); ellipse ( x + w / 2, y - h, w + 50, h + 50 ); } }