From d63a2d0dfdf696b16fc85cd70fd66e4da3f64f1e Mon Sep 17 00:00:00 2001 From: Noah Date: Thu, 30 Sep 2021 22:33:46 +0200 Subject: [PATCH] Maunuel Mode Prototype --- src/game/Clock.java | 5 +-- src/game/Control.java | 33 ++++++++++++++-- src/gui/GUI.java | 87 ++++++++++++++++++++++++++++++++++++------- 3 files changed, 104 insertions(+), 21 deletions(-) diff --git a/src/game/Clock.java b/src/game/Clock.java index 38557b4..1f9a6c3 100644 --- a/src/game/Clock.java +++ b/src/game/Clock.java @@ -12,14 +12,13 @@ public class Clock extends Thread{ public void start(Control control, GUI gui){ - Timer t = new Timer(); TimerTask tt = new TimerTask() { @Override public void run() { if (running){ - gui.showGrid(control.getCells()); + control.showGrid(control.getCells()); control.nextGen(); @@ -27,7 +26,7 @@ public class Clock extends Thread{ } }; - t.scheduleAtFixedRate(tt, 1000, 200); + t.scheduleAtFixedRate(tt, 1000, 20000); } diff --git a/src/game/Control.java b/src/game/Control.java index f8f756d..8a6acbd 100644 --- a/src/game/Control.java +++ b/src/game/Control.java @@ -57,14 +57,21 @@ public class Control { gui = new GUI(this); } - gui.gameWindow(this.xSize, this.ySize); + if (startMode == StartMode.Manuel){ + gui.manuelGameWindow(this.xSize, this.ySize); + } else { + gui.gameWindow(this.xSize, this.ySize); + } + startGame(); } private void buildManuelGame() { - System.out.println("Test"); + + + } private void generateTask1() { @@ -81,7 +88,7 @@ public class Control { } - + // cells[1][2] = true; // cells[2][2] = true; @@ -204,7 +211,25 @@ public class Control { } - public void showGrid() { + public void showGrid(boolean[][] grid) { + gui.showGrid(grid); + } + + + public void addCell(int x, int y) { + System.out.print("X" + x + "|" + "Y" + y + " "); + + System.out.println((int) (x / (800f / xSize))); + +// cells[(int) ((x / (800f / xSize)) + ((800f / xSize)/2))][(int) ((y / (800f / ySize)) + ((800f / ySize)/2))] = true; + showGrid(cells); + + } + + public void removeCell(int x, int y) { + + cells[Math.round(y/(800f/xSize))][Math.round(y/(800f/ySize))] = false; + showGrid(cells); } } diff --git a/src/gui/GUI.java b/src/gui/GUI.java index 3826e2b..9225525 100644 --- a/src/gui/GUI.java +++ b/src/gui/GUI.java @@ -64,6 +64,7 @@ public class GUI { /* End of Game view Elements */ + private JFrame jfGameManuel; public GUI(Control control) { @@ -375,20 +376,6 @@ public class GUI { draw.setVisible(true); - jfGame.addMouseMotionListener(new MouseMotionListener() { - @Override - public void mouseDragged(MouseEvent e) { - int x=e.getX(); - int y=e.getY(); - System.out.println(x+","+y); - } - - @Override - public void mouseMoved(MouseEvent e) { - System.out.println("Not Pressed"); - } - }); - jfGame.add(draw); jfGame.pack(); @@ -397,6 +384,78 @@ public class GUI { jfGame.setVisible(true); + } + + + public void manuelGameWindow(int xSize, int ySize) { + this.xSize = xSize; + this.ySize = ySize; + + + jfGameManuel = new JFrame(title); + + jfGameManuel.getContentPane().setPreferredSize(new Dimension(1000, 1000)); + jfGameManuel.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + jfGameManuel.setResizable(false); + + float ratio = (float)(ySize) / (float)(xSize); + draw = new Draw(this.xSize, this.ySize, ratio); + jfGameManuel.setBounds(0, 0, 800, 800); + + jfGameManuel.setVisible(true); + + jfGameManuel.addMouseListener(new MouseListener() { + @Override + public void mouseClicked(MouseEvent e) { + control.startGame(); + } + + @Override + public void mousePressed(MouseEvent e) { + + } + + @Override + public void mouseReleased(MouseEvent e) { + + } + + @Override + public void mouseEntered(MouseEvent e) { + + } + + @Override + public void mouseExited(MouseEvent e) { + + } + }); + + jfGameManuel.addMouseMotionListener(new MouseMotionListener() { + @Override + public void mouseDragged(MouseEvent e) { + + control.removeCell(e.getX(), e.getY()); + + + } + + @Override + public void mouseMoved(MouseEvent e) { + control.addCell(e.getX(), e.getY()); + + } + }); + + jfGameManuel.add(draw); + + jfGameManuel.pack(); + jfGameManuel.setLayout(null); + jfGameManuel.setLocationRelativeTo(null); + jfGameManuel.setVisible(true); + + } private void initGameComponents() {