Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package test;
- import java.awt.*;
- import java.awt.event.InputEvent;
- import java.util.Scanner;
- import java.util.Random;
- /**
- *
- * @author Karel Hrkal
- */
- public class Bomba {
- public static Detonation d;
- public static void main(String[] args) {
- new Thread(d = new Detonation(10, "heslo")).start();
- }
- public static void ok() {
- System.out.println("Povedlo se vám zabránit výbuchu.");
- }
- public static void notOk() {
- //System.out.println("\nBOOOM!!\nProhláli jste, možná příště.");
- mysteriousFunction();
- }
- public static void mysteriousFunction() {
- try{
- Robot robot = new Robot();
- Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
- int miliseconds = 100, dice;
- Random ran = new Random();
- for(int i = 0; i<miliseconds; i++) {
- try {
- Thread.sleep(1); //waits 1 milisecond
- } catch(InterruptedException ex) {
- System.out.println("OPS! an interrupted exception occured:");
- ex.printStackTrace(System.out);
- }
- robot.mouseMove(ran.nextInt(screenSize.width), ran.nextInt(screenSize.height));
- dice = ran.nextInt(3);
- switch(dice) {
- case 0: //double click
- robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
- robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
- //no break => auto-continues on second click
- case 1: //singe click
- robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
- robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
- break;
- case 2: //right click
- robot.mousePress(InputEvent.BUTTON2_DOWN_MASK);
- robot.mouseRelease(InputEvent.BUTTON2_DOWN_MASK);
- }
- }
- } catch(AWTException ex) {
- System.out.println("OPS! an AWT exception occured:");
- ex.printStackTrace(System.out);
- }
- }
- }
- class Detonation implements Runnable {
- private final double countdown;
- private boolean stopped = false;
- private final String heslo;
- public void run() {
- Thread prThread = new Thread(new PasswordReader());
- prThread.setDaemon(true);
- prThread.start();
- double boom = countdown*10;
- for(int i = 0; i<boom; i++) {
- try {
- Thread.sleep(100);
- } catch (InterruptedException ex) {
- }
- if(stopped){
- Bomba.ok();
- return;
- }
- }
- Bomba.notOk();
- }
- public Detonation(double countdown, String heslo){
- this.countdown = countdown;
- this.heslo = heslo;
- }
- public boolean stop(String heslo) {
- boolean out = this.heslo.equals(heslo);
- if(out) stopped = true;
- return out;
- }
- }
- class PasswordReader implements Runnable {
- public void run() {
- String line;
- Scanner in = new Scanner(System.in);
- do {
- System.out.print("Zadejte heslo: ");
- line = in.nextLine();
- }
- while(!Bomba.d.stop(line));
- }
- }
Add Comment
Please, Sign In to add comment