import java.awt.*; import java.applet.Applet; import java.awt.event.*; public class secretnumb extends Applet implements MouseListener { Image randy; int secret = (int)(Math.random()*900+101); int mouseX; int mouseY; int leftClicks=0; public void init() { randy = getImage(getCodeBase(), "randy.jpg"); addMouseListener(this); System.out.println("Ran init"); } public void paint(Graphics g) { g.drawLine(100,500,1000,500); //numb line int y = 100; int x = 1; while (y <= 1000) { g.drawLine(y, 500, y, 475); g.drawString(" " +x, y-8, 525); y = y+100; x = x+1; } if (mouseX <100) //tells you to click on line { g.drawString("Click on the Number Line Please ; )", 550, 300); } else if ( mouseX > 1000 || (mouseY <= 425 || mouseY >= 550) && ( (mouseX <= 99 || mouseX >=1050) || (mouseY <= 100 || mouseY >=200) ) ) { g.drawString("Click on the Number Line Please ; )", 550, 300); } g.drawString("You've used " + leftClicks +" out of 5 Chances!!", 525 , 100); if (mouseX >= 100 && mouseX <=1050 && mouseY >= 450 && mouseY <=525) { leftClicks++; } else if (leftClicks==4) { g.setColor(Color.red); g.drawString("You've used" + leftClicks+"out of 5 Chances!!",525,400); } if (leftClicks > 5) { g.drawString("Try Again :P", 300,400); leftClicks = 0; } if (mouseX > (secret-50) && mouseX < (secret + 50) && mouseY >= 450 && mouseY <= 525) //win { g.setColor(Color.white); g.fillRect(0,0,1366,768); g.drawImage(randy,453,5,this); g.setColor(Color.black); g.drawString("You Win",453,500); } else if (mouseX > (secret-100) && mouseX < (secret-50) && mouseY >= 425 && mouseY <= 550) //close to number { g.drawString("Little Higher", 600,550); } else if (mouseX > (secret+ 50) && mouseX < (secret + 100) && mouseY >= 425 && mouseY <= 550) { g.drawString("Little Lower", 600, 550); } if(mouseX>(secret-10) && mouseX>=100 && mouseY >=425 && mouseY<=5550) { g.drawString("Left!",460,550); } if(mouseX<(secret-10)&& mouseX<1000 && mouseY>=425 && mouseY<=550) { g.drawString("RIGHT!",460,550); } if (mouseX > (secret+250) || mouseX < (secret - 250) && mouseY >= 425 && mouseY <= 550) { g.drawString("Yikes! You are Far Away", 460, 300); } else if (mouseX >= 150 && mouseX <=250 && mouseY >= 100 && mouseY <=200) // secret number { g.drawString("Secret Number is " + secret/100.0, 140 , 225); } } public void mouseExited(MouseEvent me) { } public void mouseEntered(MouseEvent me) { } public void mousePressed(MouseEvent me) { } public void mouseReleased(MouseEvent me) { } public void mouseClicked(MouseEvent me) { System.out.println("Mouse X Clicked at " + me.getX()); System.out.println("Mouse Y Clicked at " + me.getY()); mouseX = me.getX(); mouseY = me.getY(); repaint(); } }