Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pkg2048ai;
- import java.awt.AWTException;
- import java.awt.Robot;
- import java.awt.event.InputEvent;
- import java.awt.event.KeyEvent;
- public class Main {
- public static void main(String[] args) {
- while (true) {
- int x = 0;
- while (x < 300) {
- try {
- x += 1;
- int num = (int) (Math.random() * 3) + 1;
- Robot robot = new Robot();
- if (num == 1) {
- robot.keyPress(KeyEvent.VK_DOWN);
- robot.keyRelease(KeyEvent.VK_DOWN);
- } else if (num > 1) {
- robot.keyPress(KeyEvent.VK_RIGHT);
- robot.keyRelease(KeyEvent.VK_RIGHT);
- }
- try {
- Thread.sleep(5L);
- } catch (Exception e) {
- }
- } catch (AWTException e) {
- e.printStackTrace();
- }
- }
- try {
- Robot robot = new Robot();
- int num2 = (int) (Math.random() * 5) + 1;
- if (num2 < 5) {
- robot.keyPress(KeyEvent.VK_UP);
- robot.keyRelease(KeyEvent.VK_UP);
- } else {
- robot.keyPress(KeyEvent.VK_LEFT);
- robot.keyPress(KeyEvent.VK_LEFT);
- }
- } catch (AWTException e) {
- e.printStackTrace();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement