//Homework #9 //Erica D. Cochran //ericac@andrew.cmu.edu //Section B //Copyright © Erica D. Cochran //October 15, 2009 //Carnegie Mellon University //Exploring Programming with Graphics //Pittsburgh, PA, USA //All Rights Reserved /** Instructions


Click the image that best answers the question
Questions relate to Architecture & Sustainability

Read source code for programming information and
additional information on images

Each correct answer will give you 20 points
Any mouse click (even if not correct) will move to the next question

To Start Over


Press the space bar at any time to start over.

When finished, either close program or
press the space bar to play again


*/ // Declare gobal variables here PFont f1; //listed below are images used in the game PImage material1; PImage material2; PImage material3; PImage elecheat1; PImage elecheat2; PImage elecheat3; PImage lav1; PImage lav2; PImage lav3; PImage plant1; PImage plant2; PImage plant3; PImage recycle1; PImage recycle2; PImage recycle3; float hBoard, bTop, bWidth, bHeight; int score; int questionCount; int xHigh; int [ ] xValues = {0, 20, 40, 60, 80, 100}; void setup( ) { size (600,600); background (79, 58, 91); f1 = loadFont ("f1.vlw"); textFont (f1); material1 = loadImage ("material1.jpg"); material2 = loadImage ("material2.jpg"); material3 = loadImage ("material3.jpg"); elecheat1 = loadImage ("elecheat1.jpg"); elecheat2 = loadImage ("elecheat2.jpg"); elecheat3 = loadImage ("elecheat3.jpg"); lav1 = loadImage ("lav1.jpg"); lav2 = loadImage ("lav2.jpg"); lav3 = loadImage ("lav3.JPG"); plant1 = loadImage ("plant1.JPG"); plant2 = loadImage ("plant2.JPG"); plant3 = loadImage ("plant3.jpg"); recycle1 = loadImage ("recycle1.jpg"); recycle2 = loadImage ("recycle2.jpg"); recycle3 = loadImage ("recycle3.jpg"); hBoard = .067*width; bTop = .5*height; bWidth = .2*width; bHeight = .2*height; score = 0; questionCount = 5; } // will draw items on screen to play game void draw () { textFont (f1, 15); drawBoxes (); showScore (); showCount (); startFinish (); noLoop (); } /* The score will go up when the mouse is pressed in the correct place After answering a question, the next question will appear each question is one frame count The timer counts backwards to zero indicating no more questions. Clicking the mouse will move to the next question even when answer is wrong. */ void drawBoxes() { fill (79, 58, 91); rect (0,0, width, height); println (frameCount); if (frameCount == 1) { roundOne (); } else if (frameCount == 2) { roundTwo (); } else if (frameCount == 3) { roundThree (); } else if (frameCount == 4) { roundFour (); } else if (frameCount == 5) { roundFive (); } //(frameCount == 6) shows score. //there are three levels of scoring 0-20 is low //a score of 40-60 is okay, and a score of 80 - 100 is good else { drawLocation (); ellipse ((hBoard*13), (height*.20), hBoard, hBoard); if (score <21) { fill (255); text ("low score", width*.4, height*.40); text ("press space key to start again", width*.3, height*.50); } else if (score <61) { fill (255); text ("okay score", width*.4, height*.40); text ("press space key to start again", width*.3, height*.50); } else { fill (255); text ("good score", width*.4, height*.40); text ("press space key to start again", width*.3, height*.50); } } stroke (0); } // Provides instruction to add score and count down the remaining number of questions //questions are scored seperatly, this will allow the user to change question point values //For example, is question 5 is difficult, it could result in more points. void mousePressed () { if (frameCount < 7) { if (frameCount == 1) { if (mouseX> (hBoard*10) && mouseY> (bTop) && mouseX< (hBoard*13) && mouseY< (height*.7)) { score+=20; } questionCount -= 1; } else if (frameCount == 2) { if (mouseX> (hBoard*10) && mouseY> (bTop) && mouseX< (hBoard*13) && mouseY< (height*.7)) { score+=20; } questionCount -= 1; } else if (frameCount == 3) { if (mouseX> (hBoard*10) && mouseY> (bTop) && mouseX< (hBoard*13) && mouseY< (height*.7)) { score+=20; } questionCount -= 1; } else if (frameCount == 4) { if (mouseX> (hBoard*6) && mouseY> (bTop) && mouseX< (hBoard*9) && mouseY< (height*.7)) { score+=20; } questionCount -= 1; } else if (frameCount == 5) { if (mouseX> (hBoard*2) && mouseY> (bTop) && mouseX< (hBoard*5) && mouseY< (height*.7)) { score+=20; } questionCount -= 1; } else { if (mouseX> (hBoard*2) && mouseY> (bTop) && mouseX< (hBoard*5) && mouseY< (height*.7)) { score+=20; } questionCount -=1; } } // frameCount and score shown within processing to help follow mouse clicks. //This makes it easier to identify game position (location within game for frame count and score) println (frameCount); println (score); loop (); } // show Score and showCount only display the score and questions remaining //it does not control the values. void showScore () { text ("Score", width*.02, height*.05); text (score, width*.12, height*.05); } void showCount () { text ("Questions remaining", width*.02, height*.10); text (questionCount, width*.3, height*.10); } //each question was identified by a round. //images can be replaced with rectancles or circles. //Game could easily be transformed to a child game where the goal //is to identify the correct color or shape. //once made into an aluminum can recycling the material will //require about 5% of the original energy to recycle. void roundOne () { drawLocation (); ellipse ((hBoard/2), (height*.20), hBoard, hBoard); fill (255); text ("Which items once recycled will produce the LEAST", width*.167, height*.3); text ("CO2 per Square Meter?", width*.167, height*.35); fill (0, 150, 200); image (recycle3, hBoard*2, bTop, bWidth, bHeight); image (recycle2, hBoard*6, bTop, bWidth, bHeight); image (recycle1, hBoard*10, bTop, bWidth, bHeight); } //In Architecture lingo lavatory = sink void roundTwo () { drawLocation (); ellipse ((hBoard*3), (height*.20), hBoard, hBoard); fill (255); text ("Select the picture with a lavatory included", width*.167, height*.3); text ("hint: architectural definition", width*.167, height*.35); fill (255, 10, 10); image (lav2, hBoard*2, bTop, bWidth, bHeight); image (lav1, hBoard*6, bTop, bWidth, bHeight); image (lav3, hBoard*10, bTop, bWidth, bHeight); } //roses, celosia Plants, and dusty millers are not drought resistant void roundThree () { drawLocation (); ellipse ((hBoard*5.5), (height*.20), hBoard, hBoard); fill (255); text ("Select the warm weather plant that requires the least water", width*.167, height*.3); fill (15, 210, 10); image (plant2, hBoard*2, bTop, bWidth, bHeight); image (plant3, hBoard*6, bTop, bWidth, bHeight); image (plant1, hBoard*10, bTop, bWidth, bHeight); } //look for the plug in heater next to the dog void roundFour () { drawLocation (); ellipse ((hBoard*8), (height*.20), hBoard, hBoard); fill (255); text ("Which room uses an electric heat source?", width*.167, height*.3); fill (255, 110, 10); image (elecheat1, hBoard*2, bTop, bWidth, bHeight); image (elecheat2, hBoard*6, bTop, bWidth, bHeight); image (elecheat3, hBoard*10, bTop, bWidth, bHeight); } //The building on the left uses bamboo scaffolding. The others use steel. void roundFive () { drawLocation (); ellipse ((hBoard*10.5), (height*.20), hBoard, hBoard); fill (149, 240, 140); text ("Which building uses a rapidly renewable scaffolding material?", width*.167, height*.3); image (material1, hBoard*2, bTop, bWidth, bHeight); image (material2, hBoard*6, bTop, bWidth, bHeight); image (material3, hBoard*10, bTop, bWidth, bHeight); } void drawLocation () { points (); lines (); startFinish (); } void points () { for (int i=0; i < xValues.length; i++) { stroke (0); strokeWeight (8); point ((xValues [i] *5) +20, (height*.20)); } } void lines () { for (int i=0; i < xValues.length-1; i++) { stroke (150); strokeWeight (2); line ((xValues [i] *5) +20, (height*.20), (xValues [i+1] *5) +20, (height*.20)); } } void startFinish () { text ("Start", width*.015, height*.26); text ("Finish", width*.85, height*.26); } //starts game over at the beginning //use can continue to play so that he or she obtains a zero. void keyPressed () { if (key == ' ') { score = 0; frameCount = 1; questionCount = 5; } loop (); }