Initial Commit
This commit is contained in:
commit
bc5081c0d9
5 changed files with 175 additions and 0 deletions
6
.classpath
Normal file
6
.classpath
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||||
|
<classpathentry kind="src" path="src"/>
|
||||||
|
<classpathentry kind="output" path="bin"/>
|
||||||
|
</classpath>
|
17
.project
Normal file
17
.project
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>button-game</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
4
bin/.gitignore
vendored
Normal file
4
bin/.gitignore
vendored
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
/Console.class
|
||||||
|
/Main$1.class
|
||||||
|
/Main$2.class
|
||||||
|
/Main.class
|
35
src/Console.java
Normal file
35
src/Console.java
Normal file
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
113
src/Main.java
Normal file
113
src/Main.java
Normal file
|
@ -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
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue