import java.awt.*;
import objectdraw.*;
/**
* Class ESP - write a description of the class here
*
* @author (your name)
* @version (a version number)
*/
public class ESP extends FrameWindowController
{
private FilledRect YellowSquare, BlueSquare, GreenSquare, RedSquare, InvisibleSquare;
private Text IntroMsg;
private RandomIntGenerator ColorSelect;
private int rgby;
public void begin(){
InvisibleSquare = new FilledRect(10,10,100,100,canvas);
ColorSelect = new RandomIntGenerator(1,4);
rgby = ColorSelect.nextValue();
// now set the color of the "invisible" square
if(rgby == 1) // set the "Invisible" square to red
{
InvisibleSquare.setColor(Color.RED);
}
if (rgby==2) // set the "Invisible" square to blue
{
InvisibleSquare.setColor(Color.BLUE);
}
if (rgby==3) // set the "Invisible" square to blue
{
InvisibleSquare.setColor(Color.YELLOW);
}
if (rgby==4) // set the "Invisible" square to blue
{
InvisibleSquare.setColor(Color.GREEN);
}
// and so on …
// Once the "invisible square" color is set – hide() it.
//Create 4 other square at the bottom of the canvas: YellowSquare, RedSquare, BlueSquare, and GreenSquare
YellowSquare = new FilledRect(10,200,50,50,canvas);
RedSquare = new FilledRect(60,200,50,50,canvas);
GreenSquare = new FilledRect(110,200,50,50,canvas);
BlueSquare = new FilledRect(160,200,50,50,canvas);
YellowSquare.setColor(Color.YELLOW);
RedSquare.setColor(Color.RED);
GreenSquare.setColor(Color.GREEN);
BlueSquare.setColor(Color.BLUE);
IntroMsg = new Text("Using your ESP Powers, click on a color which matches the color of the invisible square", 150,10,canvas);
InvisibleSquare.hide();
}
public void onMouseClick( Location pt)
{
if (InvisibleSquare.isHidden()){
InvisibleSquare.show();
IntroMsg.hide();
if (RedSquare.contains(pt) ) // Check to see if the red square was clicked
{
// red was clicked
new Text ( "You got vibes that the box was RED", 150,10,canvas);
// Now check to see if red is the color of the invisible box?
if ( InvisibleSquare.getColor() == Color.RED)
{
new Text( "And it was RED! You have strong ESP Powers.",150,30, canvas);
}
else // red is not the color of the invisible square
{
new Text( "WRONG!.",150,30, canvas);
}
}
else if ( YellowSquare.contains(pt) ) // Check to see if the yellow square was clicked
{
// yellow was clicked
new Text ( "You got vibes that the box was YELLOW", 150,10,canvas);
// Now check to see if yellow is the color of the invisible box?
if ( InvisibleSquare.getColor() == Color.YELLOW)
{
new Text( "And it was YELLOW! You have strong ESP Powers.",150,30, canvas);
}
else // yellow is not the color of the invisible square
{
new Text( "WRONG!.",150,30, canvas);
}
}
else if ( GreenSquare.contains(pt) ) // Check to see if the yellow square was clicked
{
// yellow was clicked
new Text ( "You got vibes that the box was GREEN", 150,10,canvas);
// Now check to see if yellow is the color of the invisible box?
if ( InvisibleSquare.getColor() == Color.GREEN)
{
new Text( "And it was GREEN! You have strong ESP Powers.",150,30, canvas);
}
else // yellow is not the color of the invisible square
{
new Text( "WRONG!.",150,30, canvas);
}
}
else if ( BlueSquare.contains(pt) ) // Check to see if the yellow square was clicked
{
// yellow was clicked
new Text ( "You got vibes that the box was BLUE", 150,10,canvas);
// Now check to see if yellow is the color of the invisible box?
if ( InvisibleSquare.getColor() == Color.BLUE)
{
new Text( "And it was BLUE! You have strong ESP Powers.",150,30, canvas);
}
else // yellow is not the color of the invisible square
{
new Text( "WRONG!.",150,30, canvas);
}
}
}else{
canvas.clear();
InvisibleSquare = new FilledRect(10,10,100,100,canvas);
ColorSelect = new RandomIntGenerator(1,4);
rgby = ColorSelect.nextValue();
// now set the color of the "invisible" square
if(rgby == 1) // set the "Invisible" square to red
{
InvisibleSquare.setColor(Color.RED);
}
if (rgby==2) // set the "Invisible" square to blue
{
InvisibleSquare.setColor(Color.BLUE);
}
if (rgby==3) // set the "Invisible" square to blue
{
InvisibleSquare.setColor(Color.YELLOW);
}
if (rgby==4) // set the "Invisible" square to blue
{
InvisibleSquare.setColor(Color.GREEN);
}
// and so on …
// Once the "invisible square" color is set – hide() it.
//Create 4 other square at the bottom of the canvas: YellowSquare, RedSquare, BlueSquare, and GreenSquare
YellowSquare = new FilledRect(10,200,50,50,canvas);
RedSquare = new FilledRect(60,200,50,50,canvas);
GreenSquare = new FilledRect(110,200,50,50,canvas);
BlueSquare = new FilledRect(160,200,50,50,canvas);
YellowSquare.setColor(Color.YELLOW);
RedSquare.setColor(Color.RED);
GreenSquare.setColor(Color.GREEN);
BlueSquare.setColor(Color.BLUE);
IntroMsg = new Text("Using your ESP Powers, click on a color which matches the color of the invisible square", 150,10,canvas);
InvisibleSquare.hide();
}
}
}