New Projekt Stukture
This commit is contained in:
+81
-2
@@ -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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user