commit bc5081c0d92a0484af003755217a40a86c59d87c Author: Sebastian Cabrera Date: Sun Jul 26 11:37:08 2020 -0400 Initial Commit diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..0cbf9cd --- /dev/null +++ b/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..a9ee7a2 --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + button-game + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/bin/.gitignore b/bin/.gitignore new file mode 100644 index 0000000..11195d3 --- /dev/null +++ b/bin/.gitignore @@ -0,0 +1,4 @@ +/Console.class +/Main$1.class +/Main$2.class +/Main.class diff --git a/src/Console.java b/src/Console.java new file mode 100644 index 0000000..50bb81f --- /dev/null +++ b/src/Console.java @@ -0,0 +1,35 @@ +import java.awt.Point; +import java.awt.TextArea; +import javax.swing.*; + +public class Console { + // Variables + static String title = "Console"; + static Point consoleWindowLocation = new Point(120, 120); + + // Create objects + static JFrame consoleWindow = new JFrame(); + static JPanel consolePanel = new JPanel(); + static TextArea clicksConsole = new TextArea(); + static TextArea sleepConsole = new TextArea(); + static TextArea locationConsole = new TextArea(); + + + public Console() { + consolePanel.add(clicksConsole); + consolePanel.add(sleepConsole); + consolePanel.add(locationConsole); + + clicksConsole.setEditable(false); + sleepConsole.setEditable(false); + locationConsole.setEditable(false); + + consoleWindow.add(consolePanel); + consoleWindow.setResizable(false); + consoleWindow.setTitle(title); + consoleWindow.pack(); + consoleWindow.setLocation(consoleWindowLocation); + consoleWindow.setVisible(true); + consoleWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + } +} diff --git a/src/Main.java b/src/Main.java new file mode 100644 index 0000000..b9403fd --- /dev/null +++ b/src/Main.java @@ -0,0 +1,113 @@ +import java.awt.Dimension; +import java.awt.Toolkit; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Random; +import javax.swing.*; + +public class Main { + // Variables + static boolean isRunning; // isRunning boolean for gameloop + static boolean isPaused; // isPause boolean for pausing + + static String title = "- Button Game - Luckyknife"; // Window title + static String buttonText = "@FuckSebastian"; // Button text variable + + static Random RND = new Random(); // Create random number generator for button location + + static int width = 300; // Window width variable + static int height = width / 16 * 9; // Window height variable + static int scale = 3; // Window dimension scale + static int newWidth = width * scale; // Fuck you + static int newHeight = height * scale; // Fuck you again + static int clicks; // Click counter + static int sleepTime = 2999; // Time to sleep for + + static Dimension size = new Dimension(newWidth, newHeight); // Create dimension variable + static Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); // Create another dimension variable + + + // Create objects + static JFrame window = new JFrame(); // Create window + static JPanel gameArea = new JPanel(); // Create gamearea + static JButton mainButton = new JButton(); // Create main button + static JButton pauseButton = new JButton(); // Create pause button + + // Other + static int maxX = (screenSize.width - window.getWidth()) / 2; + static int maxY = (screenSize.height - window.getHeight()) / 2; + + public static void tick() { + while (isRunning) { + if (!isPaused) { + mainButton.setLocation(RND.nextInt(maxX - 100), RND.nextInt(maxY - 100)); + + Console.clicksConsole.append("Clicks: " + clicks + "\n"); + Console.sleepConsole.append("Sleep: " + sleepTime + "\n"); + Console.locationConsole.append(mainButton.getLocation() + "\n"); + sleep(); + } + } + } + + public static void sleep() { + try { + Thread.sleep(sleepTime); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + public static void draw() { + // Object settings + pauseButton.setText("Pause"); + pauseButton.setLocation(420, 410); + + pauseButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + if (pauseButton.getText().contains("Pause")) { + pauseButton.setText("Resume"); + mainButton.setEnabled(false); + isPaused = true; + } else { + pauseButton.setText("Pause"); + mainButton.setEnabled(true); + isPaused = false; + } + } + }); + + mainButton.setText(buttonText); + mainButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + mainButton.setLocation(RND.nextInt(maxX - 100), RND.nextInt(maxY - 100)); + clicks ++; + sleepTime -= clicks; + } + }); + + gameArea.add(mainButton); + //gameArea.add(pauseButton); + + window.add(gameArea); + window.setTitle(title); + window.setSize(size); + window.setLocationRelativeTo(null); + window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + window.setResizable(false); + window.setVisible(true); + } + + public static void run() { + isRunning = true; // Set isRunning to true (obviously) + + draw(); // Draw the game + new Console(); // Create the console + tick(); // Start ticking (not a bomb) + } + + public static void main(String[] args) { + run(); // Start the run method + } + +}