diff --git a/src/game/Control.java b/src/game/Control.java index eb4d5e2..0433e78 100644 --- a/src/game/Control.java +++ b/src/game/Control.java @@ -238,6 +238,10 @@ public class Control { public void createControlWindow() { gui.createControlWindow(); } + + public void setCells(){ + + } } diff --git a/src/gui/GameWindow.java b/src/gui/GameWindow.java index 2c54760..58ca39a 100644 --- a/src/gui/GameWindow.java +++ b/src/gui/GameWindow.java @@ -5,8 +5,7 @@ import game.Control; import javax.swing.*; import java.awt.*; -import java.awt.event.KeyEvent; -import java.awt.event.KeyListener; +import java.awt.event.*; public class GameWindow { @@ -19,6 +18,8 @@ public class GameWindow { private int width, height; private float ratio; + private boolean mouseLeft = false, mouseRight = false; + public GameWindow(String title, Control control, int cellCountX, int cellCountY) { this.cellCountX = cellCountX; this.cellCountY = cellCountY; @@ -49,6 +50,82 @@ public class GameWindow { } }); + jfGame.getContentPane().addMouseMotionListener(new MouseMotionListener() { + + @Override + public void mouseDragged(MouseEvent e) + { + if(mouseLeft) + { + // control.setCell(e.getX(), e.getY(), true); + control.addCell(e.getX(), e.getY()); + } + else if(mouseRight) + { + control.setCell(e.getX(), e.getY(), 0); + } + } + + @Override + public void mouseMoved(MouseEvent e) + { + + } + }); + + gameWindow.getContentPane().addMouseListener(new MouseListener() + { + @Override + public void mouseClicked(MouseEvent e) + { + + } + + @Override + public void mousePressed(MouseEvent e) + { + switch(e.getButton()) + { + case 1: + mouseLeft = true; +// control.setCell(e.getX(), e.getY(), true); + control.addCell(e.getX(), e.getY()); + break; + case 3: + mouseRight = true; +// control.setCell(e.getX(), e.getY(), false); + control.addCell(e.getX(), e.getY()); + break; + } + } + + @Override + public void mouseReleased(MouseEvent e) + { + switch(e.getButton()) + { + case 1: + mouseLeft = false; + break; + case 3: + mouseRight = false; + break; + } + } + + @Override + public void mouseEntered(MouseEvent e) + { + + } + + @Override + public void mouseExited(MouseEvent e) + { + + } + }); + jfGame.setResizable(false); ratio = (float) (cellCountY) / (float) (cellCountX); @@ -83,4 +160,6 @@ public class GameWindow { height = (int) (cellCountY * ratio); } + + }