This commit is contained in:
Noah
2021-12-02 19:13:06 +01:00
parent e1c6b1cffc
commit cb8e4246db
9 changed files with 264 additions and 226 deletions
Binary file not shown.
+60
View File
@@ -1486,3 +1486,63 @@ java.sql.SQLClientInfoException: Client info name 'ApplicationName' not supporte
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)
2021-12-02 14:22:39 jdbc[3]: exception
java.sql.SQLClientInfoException: Client info name 'ApplicationName' not supported.
at org.h2.jdbc.JdbcConnection.setClientInfo(JdbcConnection.java:1749)
at com.intellij.database.remote.jdbc.impl.RemoteConnectionImpl.setClientInfo(RemoteConnectionImpl.java:470)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:359)
at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200)
at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196)
at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:562)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:796)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:677)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:676)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)
2021-12-02 14:22:43 jdbc[4]: exception
java.sql.SQLClientInfoException: Client info name 'ApplicationName' not supported.
at org.h2.jdbc.JdbcConnection.setClientInfo(JdbcConnection.java:1749)
at com.intellij.database.remote.jdbc.impl.RemoteConnectionImpl.setClientInfo(RemoteConnectionImpl.java:470)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:359)
at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200)
at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196)
at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:562)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:796)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:677)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:676)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)
2021-12-02 15:26:55 jdbc[3]: exception
org.h2.jdbc.JdbcSQLNonTransientException: Keine Daten verfügbar
No data is available [2000-200]
2021-12-02 15:26:55 jdbc[3]: exception
org.h2.jdbc.JdbcSQLNonTransientException: Keine Daten verfügbar
No data is available [2000-200]
2021-12-02 15:26:58 jdbc[3]: exception
org.h2.jdbc.JdbcSQLNonTransientException: Keine Daten verfügbar
No data is available [2000-200]
2021-12-02 15:26:58 jdbc[3]: exception
org.h2.jdbc.JdbcSQLNonTransientException: Keine Daten verfügbar
No data is available [2000-200]
2021-12-02 15:26:59 jdbc[3]: exception
org.h2.jdbc.JdbcSQLNonTransientException: Keine Daten verfügbar
No data is available [2000-200]
2021-12-02 15:26:59 jdbc[3]: exception
org.h2.jdbc.JdbcSQLNonTransientException: Keine Daten verfügbar
No data is available [2000-200]
+35 -9
View File
@@ -9,7 +9,7 @@ public class DataBase {
private Connection connection;
private Statement statement;
public void connect(){
private void connect(){
try {
connection = DriverManager.getConnection("jdbc:h2:./lib/Conway-Game-Of-Live", "sa", "");
statement = connection.createStatement();
@@ -18,7 +18,7 @@ public class DataBase {
}
}
public void disconnect(){
private void disconnect(){
try {
statement.close();
@@ -29,7 +29,7 @@ public class DataBase {
}
public void simpleSQL(String sqlStatement){
private void simpleSQL(String sqlStatement){
try {
statement.executeUpdate(sqlStatement);
} catch (SQLException e) {
@@ -37,7 +37,7 @@ public class DataBase {
}
}
public ResultSet resultSetSQL(String sqlStatement){
private ResultSet resultSetSQL(String sqlStatement){
try {
return statement.executeQuery(sqlStatement);
} catch (SQLException e) {
@@ -51,7 +51,7 @@ public class DataBase {
public void createTables(){
connect();
simpleSQL("create table gameInfo(id int not null auto_increment, name varchar, width int, height int, generation int)");
simpleSQL("create table gameInfo(id int not null auto_increment, name varchar, width int, height int, generation int, cellcount int)");
simpleSQL("create table gameData(id int, x int, y int)");
disconnect();
@@ -93,11 +93,11 @@ public class DataBase {
}
public void saveGrid(boolean[][] grid, String gridName, int generation){
public void saveGrid(boolean[][] grid, String gridName, int generation, int cellCount){
connect();
simpleSQL("insert into GAMEINFO(name, width, height, GENERATION) values ('"+gridName+"', "+grid.length+", "+grid[0].length+", "+generation+")");
simpleSQL("insert into GAMEINFO(NAME, WIDTH, HEIGHT, GENERATION, CELLCOUNT) values ('"+gridName+"', "+grid.length+", "+grid[0].length+", "+generation+","+cellCount+")");
ResultSet resultSet = resultSetSQL("select * from gameInfo order by id desc limit 1");
@@ -125,8 +125,6 @@ public class DataBase {
connect();
ResultSet resultInfo = resultSetSQL("select * from gameInfo where name = '"+gridName+"'");
try {
@@ -173,4 +171,32 @@ public class DataBase {
}
public int getCellCount(String gridName){
connect();
ResultSet resultSet = resultSetSQL("select CELLCOUNT from gameInfo where name = '"+gridName+"'");
try {
resultSet.next();
int cellCount = resultSet.getInt("CELLCOUNT");
disconnect();
return cellCount;
} catch (SQLException e) {
e.printStackTrace();
}
disconnect();
return 0;
}
public boolean checkName(String name){
List<String> allNames = getAllGrids();
if (allNames.contains(name)){
return false;
} else {
return true;
}
}
}
+60 -122
View File
@@ -3,6 +3,7 @@ package game;
import data.database.DataBase;
import gui.GUI;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
@@ -39,6 +40,36 @@ public class Control {
}
public void buildGameWindow(int xSize, int ySize, int cellCount, String startMode) {
switch (startMode) {
case "Randomized" -> {
generateRandomized(xSize, ySize, cellCount);
}
case "Manuel" -> {
buildManuelGame(xSize, ySize, cellCount);
}
default -> {
getFromDatabase(startMode);
}
}
saveFirstGrid();
calcSize();
gui.createGameWindow(this.xSize, this.ySize, this.width, this.height);
if (startMode == "Manuel"){
gui.buildControlWindow();
}
startGame();
}
private void buildManuelGame(int xSize, int ySize, int cellCount) {
this.xSize = xSize;
this.ySize = ySize;
this.cellCount = cellCount;
@@ -52,42 +83,6 @@ public class Control {
newcells = new boolean[this.xSize][this.ySize];
startingCells = new boolean[this.xSize][this.ySize];
switch (startMode) {
case "Task1" -> {
generateTask1();
}
case "Randomized" -> {
generateRandomized();
}
case "Manuel" -> {
buildManuelGame();
}
default -> {
getFromDatabase(startMode);
}
}
saveFirstGrid();
calcSize();
gui.createGameWindow(this.xSize, this.ySize, this.width, this.height);
setRunning(true);
if (startMode == "Manuel") {
setRunning(false);
gui.buildControlWindow();
this.mouseLocked = false;
}
startGame();
}
private void buildManuelGame() {
for (int x = 0; x < xSize; x++) {
for (int y = 0; y < ySize; y++) {
cells[x][y] = false;
@@ -96,36 +91,39 @@ public class Control {
syncCells();
setRunning(false);
this.mouseLocked = false;
}
private void getFromDatabase(String name){
cells = dataBase.getGrid(name);
gen = dataBase.getGen(name);
this.xSize = cells.length;
this.ySize = cells[0].length;
this.cellCount = this.xSize * this.ySize;
newcells = new boolean[this.xSize][this.ySize];
startingCells = new boolean[this.xSize][this.ySize];
syncCells();
setRunning(true);
}
private void generateTask1() {
for (int x = 0; x < xSize; x++) {
for (int y = 0; y < ySize; y++) {
cells[x][y] = false;
}
}
private void generateRandomized(int xSize, int ySize, int cellCount) {
this.xSize = xSize;
this.ySize = ySize;
this.cellCount = cellCount;
clock.setFirstGen(true);
cells[1][2] = true;
cells[2][2] = true;
cells[2][4] = true;
cells[3][1] = true;
cells[3][3] = true;
cells[4][3] = true;
gen = 0;
mouseLocked = true;
cells = new boolean[this.xSize][this.ySize];
newcells = new boolean[this.xSize][this.ySize];
startingCells = new boolean[this.xSize][this.ySize];
syncCells();
}
private void generateRandomized() {
for (int i = 0; i < this.cellCount; i++) {
int x = rand(0, this.xSize);
int y = rand(0, this.ySize);
@@ -136,7 +134,7 @@ public class Control {
}
}
syncCells();
setRunning(true);
}
private void syncCells() {
@@ -236,71 +234,6 @@ public class Control {
}
}
// public void checkN(Boolean[][] arr, Boolean[][] futureGen, int columns, int rows) {
// ArrayList<Thread> threads = new ArrayList<>();
// final int NUM_OF_THREADS = 8; //Or can be passed as an argument
// for (int tid = 0; tid < NUM_OF_THREADS; tid++) {
// Integer thread_local_row_start = tid * rows / NUM_OF_THREADS;
// Integer thread_local_row_end = (tid + 1) * rows / NUM_OF_THREADS;
// Thread t = new Thread(() -> {
// for (int row = thread_local_row_start; row < thread_local_row_end; row++) {
// for (int column = 0; column < columns; column++) {
// countNeighbors(arr, row, column, rows, columns);
// evaluateNeighbors(arr[row][column], futureGen[row][column]);
// }
// }
// });
// t.start();
// threads.add(t);
// }
// for (Thread t : threads) {
// try {
// t.join();
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
// }
// }
public boolean[][] nextGenBackup() {
gen++;
// System.out.println("Generation:" + gen);
for (int x = 0; x < xSize; x++) {
for (int y = 0; y < ySize; y++) {
int n = aliveNeigbours(x, y);
if (n == 3 && !cells[x][y]) {
newcells[x][y] = true;
}
if (n < 2) {
newcells[x][y] = false;
}
if (n == 2 || n == 3) {
}
if (n > 3) {
newcells[x][y] = false;
}
}
}
for (int x = 0; x < this.xSize; x++) {
for (int y = 0; y < this.ySize; y++) {
cells[x][y] = newcells[x][y];
}
}
return cells;
}
private int aliveNeigbours(int x, int y) {
int count = 0;
@@ -318,17 +251,14 @@ public class Control {
return count;
}
private int rand(int min, int max) {
return ThreadLocalRandom.current().nextInt(min, max);
}
public void showGrid(boolean[][] grid) {
gui.showGrid(grid);
}
public void setVisibility(boolean value) {
gui.setVisibility(value);
}
@@ -456,6 +386,14 @@ public class Control {
public List<String> getAllGrids(){
return dataBase.getAllGrids();
}
public void saveGridInDB(String gridName){
dataBase.saveGrid(this.cells, gridName, this.gen, this.cellCount);
}
public boolean checkName(String name){
return dataBase.checkName(name);
}
}
+62 -33
View File
@@ -12,11 +12,10 @@ public class ControlWindow {
private final int width = 400, height = 800;
private Font head;
private Font text;
private MouseAdapter hover;
private final Font head;
private final Font text;
private JFrame controlWindow;
private final JFrame controlWindow;
private JLabel heading;
private JButton toggleGame;
private JButton nextGenButton;
@@ -30,14 +29,16 @@ public class ControlWindow {
private JTextField saveGrid;
private JLabel saveGridPlaceholder;
private int velocity, minVelocity = 1 , maxVelocity = 5000;
private int velocity;
private final int minVelocity = 1;
private final int maxVelocity = 5000;
private JSlider velocitySlider;
private JLabel velocitySliderName;
private JTextField velocitySliderLabel;
private GUI gui;
private final GUI gui;
public ControlWindow(GameWindow gameWindow, GUI gui, int offset) {
@@ -45,7 +46,6 @@ public class ControlWindow {
this.head = gui.getHead();
this.text = gui.getText();
this.hover = gui.getHover();
velocity = 500;
@@ -68,18 +68,25 @@ public class ControlWindow {
}
});
controlWindow.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
saveGrid.setFocusable(false);
saveGrid.setFocusable(true);
}
});
controlWindow.pack();
controlWindow.setVisible(true);
initComponents();
addComponents();
}
private void initComponents(){
private void initComponents() {
initHeading();
initVelocity();
initToggleButton();
@@ -92,7 +99,7 @@ public class ControlWindow {
initSaveGrid();
}
private void initHeading(){
private void initHeading() {
heading = new JLabel("Control Panel");
heading.setFont(head);
heading.setForeground(Color.decode("#121212"));
@@ -100,7 +107,7 @@ public class ControlWindow {
heading.setVisible(true);
}
private void initVelocity(){
private void initVelocity() {
velocitySlider = new JSlider(minVelocity, maxVelocity);
velocitySlider.setBounds(120, 110, 230, 20);
velocitySlider.setFont(text);
@@ -109,7 +116,7 @@ public class ControlWindow {
velocitySlider.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
if(!gui.isSliderLocked()) {
if (!gui.isSliderLocked()) {
velocity = velocitySlider.getValue();
velocitySliderLabel.setText(String.valueOf(velocity));
gui.setVelocity(velocity);
@@ -166,7 +173,7 @@ public class ControlWindow {
}
private void initToggleButton(){
private void initToggleButton() {
toggleGame = new JButton();
toggleGame.setText("Start Game");
@@ -177,19 +184,22 @@ public class ControlWindow {
toggleGame.setContentAreaFilled(false);
toggleGame.setBounds(50, 750, 300, 50);
toggleGame.setVisible(true);
toggleGame.addMouseListener(hover);
toggleGame.addMouseListener(new Hover());
toggleGame.setBorder(new RoundedBorder(25));
toggleGame.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (gui.getGeneration() == 0){
if (gui.getGeneration() == 0) {
gui.saveFirstGrid();
}
if (!gui.isRunning()){
if (!gui.isRunning()) {
gui.setMouseLocked(true);
saveGrid.setFocusable(false);
updateLockedMouse();
} else {
saveGrid.setFocusable(true);
}
gui.setRunning(!gui.isRunning());
updateToggleButton();
@@ -200,7 +210,7 @@ public class ControlWindow {
updateToggleButton();
}
private void initNextButton(){
private void initNextButton() {
nextGenButton = new JButton();
nextGenButton.setText("Next Gen.");
nextGenButton.setFont(text);
@@ -210,7 +220,7 @@ public class ControlWindow {
nextGenButton.setContentAreaFilled(false);
nextGenButton.setBounds(225, 675, 125, 50);
nextGenButton.setVisible(true);
nextGenButton.addMouseListener(hover);
nextGenButton.addMouseListener(new Hover());
nextGenButton.setBorder(new RoundedBorder(25));
nextGenButton.addActionListener(new ActionListener() {
@Override
@@ -226,7 +236,7 @@ public class ControlWindow {
});
}
private void initPreviousGenButton(){
private void initPreviousGenButton() {
previousGenButton = new JButton();
previousGenButton.setText("Prior Gen.");
previousGenButton.setFont(text);
@@ -236,7 +246,7 @@ public class ControlWindow {
previousGenButton.setContentAreaFilled(false);
previousGenButton.setBounds(50, 675, 125, 50);
previousGenButton.setVisible(true);
previousGenButton.addMouseListener(hover);
previousGenButton.addMouseListener(new Hover());
previousGenButton.setBorder(new RoundedBorder(25));
previousGenButton.addActionListener(new ActionListener() {
@Override
@@ -249,7 +259,7 @@ public class ControlWindow {
});
}
private void initDrawLockButton(){
private void initDrawLockButton() {
lockMouse = new JButton();
lockMouse.setFont(text);
lockMouse.setForeground(Color.decode("#121212"));
@@ -258,7 +268,7 @@ public class ControlWindow {
lockMouse.setContentAreaFilled(false);
lockMouse.setBounds(50, 450, 300, 50);
lockMouse.setVisible(true);
lockMouse.addMouseListener(hover);
lockMouse.addMouseListener(new Hover());
lockMouse.setBorder(new RoundedBorder(25));
lockMouse.addActionListener(new ActionListener() {
@Override
@@ -272,7 +282,7 @@ public class ControlWindow {
updateLockedMouse();
}
private void initClearButton(){
private void initClearButton() {
clearButton = new JButton();
clearButton.setText("Clear Grid");
clearButton.setFont(text);
@@ -282,7 +292,7 @@ public class ControlWindow {
clearButton.setContentAreaFilled(false);
clearButton.setBounds(50, 375, 300, 50);
clearButton.setVisible(true);
clearButton.addMouseListener(hover);
clearButton.addMouseListener(new Hover());
clearButton.setBorder(new RoundedBorder(25));
clearButton.addActionListener(new ActionListener() {
@Override
@@ -295,7 +305,7 @@ public class ControlWindow {
});
}
private void initMultibleGenSkip(){
private void initMultibleGenSkip() {
multipleGenSkipButton = new JButton();
multipleGenSkipButton.setText("Next Generation");
@@ -306,7 +316,7 @@ public class ControlWindow {
multipleGenSkipButton.setContentAreaFilled(false);
multipleGenSkipButton.setBounds(50, 600, 300, 50);
multipleGenSkipButton.setVisible(true);
multipleGenSkipButton.addMouseListener(hover);
multipleGenSkipButton.addMouseListener(new Hover());
multipleGenSkipButton.setBorder(new RoundedBorder(25));
multipleGenSkipButton.addActionListener(new ActionListener() {
@Override
@@ -335,7 +345,7 @@ public class ControlWindow {
});
}
private void initJump2Gen(){
private void initJump2Gen() {
jump2GenButton = new JButton();
jump2GenButton.setText("Jump to generation");
@@ -346,7 +356,7 @@ public class ControlWindow {
jump2GenButton.setContentAreaFilled(false);
jump2GenButton.setBounds(50, 525, 300, 50);
jump2GenButton.setVisible(true);
jump2GenButton.addMouseListener(hover);
jump2GenButton.addMouseListener(new Hover());
jump2GenButton.setBorder(new RoundedBorder(25));
jump2GenButton.addActionListener(new ActionListener() {
@Override
@@ -375,7 +385,7 @@ public class ControlWindow {
});
}
private void initSaveGrid(){
private void initSaveGrid() {
saveGridPlaceholder = new JLabel("Save Grid...");
saveGridPlaceholder.setBounds(50, 300, 300, 50);
@@ -385,6 +395,7 @@ public class ControlWindow {
saveGrid = new JTextField();
saveGrid.setDocument(new JTextFieldLimit(10));
saveGrid.setFocusable(false);
saveGrid.setOpaque(false);
saveGrid.setBackground(null);
saveGrid.setBorder(null);
@@ -398,6 +409,21 @@ public class ControlWindow {
evt.consume();
}
}
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
if (gui.checkName(saveGrid.getText())) {
gui.saveGridInDB(saveGrid.getText());
} else {
System.out.println("Vergeben");
}
saveGrid.setText("");
saveGridPlaceholder.setVisible(true);
}
}
});
saveGrid.addFocusListener(new FocusListener() {
@Override
@@ -407,13 +433,16 @@ public class ControlWindow {
@Override
public void focusLost(FocusEvent e) {
saveGridPlaceholder.setVisible(true);
if (saveGrid.getText().equals("")) {
saveGridPlaceholder.setVisible(true);
}
}
});
}
private void addComponents(){
private void addComponents() {
controlWindow.add(heading);
controlWindow.add(velocitySlider);
controlWindow.add(velocitySliderName);
@@ -452,12 +481,12 @@ public class ControlWindow {
}
}
public void dispose(){
public void dispose() {
controlWindow.dispose();
}
public void setVelocity(int velocity){
public void setVelocity(int velocity) {
gui.setVelocity(velocity);
}
}
+13 -33
View File
@@ -2,21 +2,17 @@ package gui;
import game.Control;
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.List;
public class GUI {
private final String title = "Conway's game if Live";
private final String title = "Conway's game if Live";
private final Control control;
private Font head;
private Font text;
private MouseAdapter hover;
private boolean sliderLocked = false;
private final int offset = 20;
@@ -36,27 +32,6 @@ public class GUI {
head = new Font("Segoe UI Light", Font.PLAIN, 24);
text = new Font("Segoe UI Light", Font.PLAIN, 16);
hover = new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) {
super.mouseEntered(e);
JButton b = (JButton) e.getSource();
b.setForeground(Color.decode("#C40233"));
b.setBounds(b.getX() - 10, b.getY() - 10, b.getWidth() + 20, b.getHeight() + 20);
}
@Override
public void mouseExited(MouseEvent e) {
super.mouseExited(e);
JButton b = (JButton) e.getSource();
b.setForeground(Color.decode("#121212"));
b.setBounds(b.getX() + 10, b.getY() + 10, b.getWidth() - 20, b.getHeight() - 20);
}
};
}
public void createMenuWindow(){
@@ -119,10 +94,6 @@ public class GUI {
this.sliderLocked = sliderLocked;
}
public MouseAdapter getHover() {
return hover;
}
public void nextGen(){
control.nextGen();
}
@@ -167,6 +138,18 @@ public class GUI {
control.jump2Gen(wantedtGen);
}
public void saveGridInDB(String gridName){
control.saveGridInDB(gridName);
}
public List<String> getAllGrids(){
return control.getAllGrids();
}
public boolean checkName(String name){
return control.checkName(name);
}
//TODO: Delet this Methods. Those are shit.
public void setVisibility(boolean value){
controlWindow.setVisibility(value);
@@ -176,9 +159,6 @@ public class GUI {
return controlWindow;
}
public List<String> getAllGrids(){
return control.getAllGrids();
}
}
+27
View File
@@ -0,0 +1,27 @@
package gui;
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class Hover extends MouseAdapter {
@Override
public void mouseEntered(MouseEvent e) {
super.mouseEntered(e);
JButton b = (JButton) e.getSource();
b.setForeground(Color.decode("#C40233"));
b.setBounds(b.getX() - 10, b.getY() - 10, b.getWidth() + 20, b.getHeight() + 20);
}
@Override
public void mouseExited(MouseEvent e) {
super.mouseExited(e);
JButton b = (JButton) e.getSource();
b.setForeground(Color.decode("#121212"));
b.setBounds(b.getX() + 10, b.getY() + 10, b.getWidth() - 20, b.getHeight() - 20);
}
}
+1 -6
View File
@@ -81,8 +81,6 @@ public class MenuWindow {
this.head = gui.getHead();
this.text = gui.getText();
this.hover = gui.getHover();
initHeading();
@@ -300,9 +298,6 @@ public class MenuWindow {
modeBox.setBounds(180, 257, 200, 20);
addComboBoxEntry(modeBox, "Randomized");
addComboBoxEntry(modeBox, "Manuel");
addComboBoxEntry(modeBox, "Task1");
addComboBoxEntry(modeBox, "Blinker");
addComboBoxEntry(modeBox, "Toad");
for (int i = 0; i < gui.getAllGrids().size(); i++){
addComboBoxEntry(modeBox, gui.getAllGrids().get(i));
@@ -325,7 +320,7 @@ public class MenuWindow {
startButton.setContentAreaFilled(false);
startButton.setBounds(50, 310, 330, 50);
startButton.setVisible(true);
startButton.addMouseListener(hover);
startButton.addMouseListener(new Hover());
startButton.setBorder(new RoundedBorder(25));
startButton.addActionListener(new ActionListener() {
@Override
+6 -23
View File
@@ -1,11 +1,13 @@
package main;
import data.database.DataBase;
import game.Control;
public class Main {
//TODO: Database Seve Button. Alert when Name is already is taken.
//TODO: Database Seve Button.
//TODO: Show grid name.
//TODO: Database window to Delete Entries.
//TODO: Save Velocity in DB
//TODO: Correct generation saving in DB and read out it
@@ -14,8 +16,10 @@ public class Main {
//TODO: Correct new Initialisation when game starts
//TODO: Change the population Rules
//TODO: Limit input length
//TODO: DB Reload when Menu windows Opened
//TODO: Implement Corona Virus. Infected, Vaccinated, Recovered and Normal
//TODO: Implement Picture to grid function
//TODO: Implement a war mode.
@@ -27,28 +31,7 @@ public class Main {
// DataBase dataBase = new DataBase();
// dataBase.deleteTables();
// dataBase.createTables();
//
//
// boolean[][] cells = new boolean[44][66];
//
// for (int x = 0; x < 6; x++) {
// for (int y = 0; y < 6; y++) {
// }
// }
//
//
// for (int x = 0; x < 6; x++) {
// for (int y = 0; y < 6; y++) {
// cells[x][y] = true;
// }
// }
//
// dataBase.saveGrid(cells, "Noah", 1012);
//
// System.out.println(dataBase.getAllGrids());
//
// boolean[][] x = dataBase.getGrid("penis");
//
}