From 9cb505d4da2af1dcbbc7ee3f2263aa47809c6b50 Mon Sep 17 00:00:00 2001 From: Noah Date: Sun, 3 Oct 2021 22:39:26 +0200 Subject: [PATCH] First Size Calculating --- src/game/Control.java | 18 +++++++++++++++++- src/gui/ControlWindow.java | 12 +++++++++++- src/gui/GUI.java | 4 ++-- src/gui/GameWindow.java | 32 ++++++++++++++++---------------- 4 files changed, 46 insertions(+), 20 deletions(-) diff --git a/src/game/Control.java b/src/game/Control.java index acd9916..84c310a 100644 --- a/src/game/Control.java +++ b/src/game/Control.java @@ -17,6 +17,8 @@ public class Control { private int x = 0; private int y = 0; + private int width, height; + public void start() { @@ -57,7 +59,9 @@ public class Control { gui = new GUI(this); } - gui.createGameWindow(this.xSize, this.ySize); + calcSize(); + + gui.createGameWindow(this.xSize, this.ySize, this.width, this.height); startGame(); @@ -243,6 +247,18 @@ public class Control { gui.showGrid(cells); } + private void calcSize(){ + + float c = 800; + + width = Math.round(xSize * (c / xSize)); + height = Math.round(ySize * (c / ySize)); + + System.out.println(xSize + " " + width); + System.out.println(ySize + " " + height); + + } + private boolean checkCellCount() { int counter = 0; diff --git a/src/gui/ControlWindow.java b/src/gui/ControlWindow.java index f9d52bf..7387203 100644 --- a/src/gui/ControlWindow.java +++ b/src/gui/ControlWindow.java @@ -1,15 +1,25 @@ package gui; import javax.swing.*; +import java.awt.*; public class ControlWindow { private JFrame controlWindow; public ControlWindow(){ + controlWindow = new JFrame(); - controlWindow.setVisible(true); + + controlWindow.getContentPane().setPreferredSize(new Dimension(400, 800)); controlWindow.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); + controlWindow.setResizable(false); +// controlWindow.set + controlWindow.setLayout(null); + + controlWindow.pack(); + controlWindow.setVisible(true); + } } diff --git a/src/gui/GUI.java b/src/gui/GUI.java index f81fb64..2af41ff 100644 --- a/src/gui/GUI.java +++ b/src/gui/GUI.java @@ -20,8 +20,8 @@ public class GUI { menuWindow = new MenuWindow(title, control); } - public void createGameWindow(int cellCountX, int cellCountY){ - gameWindow = new GameWindow(title, control, cellCountX, cellCountY); + public void createGameWindow(int cellCountX, int cellCountY, int width, int height){ + gameWindow = new GameWindow(title, control, cellCountX, cellCountY, width, height); } public void createControlWindow(){ diff --git a/src/gui/GameWindow.java b/src/gui/GameWindow.java index 1d75d4a..1623826 100644 --- a/src/gui/GameWindow.java +++ b/src/gui/GameWindow.java @@ -9,7 +9,7 @@ import java.awt.event.*; public class GameWindow { - private final JFrame jfGame; + private final JFrame gameWindow; private final Draw draw; private final int cellCountX; @@ -20,17 +20,17 @@ public class GameWindow { private boolean mouseLeft = false, mouseRight = false; - public GameWindow(String title, Control control, int cellCountX, int cellCountY) { + public GameWindow(String title, Control control, int cellCountX, int cellCountY, int width, int height) { this.cellCountX = cellCountX; this.cellCountY = cellCountY; - jfGame = new JFrame(title); + gameWindow = new JFrame(title); - jfGame.getContentPane().setPreferredSize(new Dimension(800, 800)); - jfGame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + gameWindow.getContentPane().setPreferredSize(new Dimension(width, height)); + gameWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - jfGame.addKeyListener(new KeyListener() { + gameWindow.addKeyListener(new KeyListener() { @Override public void keyTyped(KeyEvent e) { @@ -49,7 +49,7 @@ public class GameWindow { } }); - jfGame.getContentPane().addMouseMotionListener(new MouseMotionListener() { + gameWindow.getContentPane().addMouseMotionListener(new MouseMotionListener() { @Override public void mouseDragged(MouseEvent e) { @@ -66,7 +66,7 @@ public class GameWindow { } }); - jfGame.getContentPane().addMouseListener(new MouseListener() { + gameWindow.getContentPane().addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { @@ -105,20 +105,20 @@ public class GameWindow { } }); - jfGame.setResizable(false); + gameWindow.setResizable(false); ratio = (float) (cellCountY) / (float) (cellCountX); - draw = new Draw(this.cellCountX, this.cellCountY, 800, 800, ratio); - draw.setBounds(0, 0, 800, 800); + draw = new Draw(this.cellCountX, this.cellCountY, width, height, ratio); + draw.setBounds(0, 0, width, height); draw.setVisible(true); - jfGame.add(draw); + gameWindow.add(draw); - jfGame.pack(); - jfGame.setLayout(null); - jfGame.setLocationRelativeTo(null); - jfGame.setVisible(true); + gameWindow.pack(); + gameWindow.setLayout(null); + gameWindow.setLocationRelativeTo(null); + gameWindow.setVisible(true); } public void showGrid(boolean[][] grid) {