Comments++ changed button behaviour at game start.
This commit is contained in:
@@ -9,14 +9,20 @@ import java.util.List;
|
|||||||
|
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* FieldCanvas class, implements the field to draw upon. Draws the game field and handles mouse actions.
|
||||||
|
*
|
||||||
|
* @author timo
|
||||||
|
*/
|
||||||
public class FieldCanvas extends JPanel{
|
public class FieldCanvas extends JPanel{
|
||||||
|
|
||||||
|
// private and static members
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
static final int borderLeft = 5;
|
static final int borderLeft = 5;
|
||||||
static final int borderRight = 5;
|
static final int borderRight = 5;
|
||||||
static final int borderTop = 5;
|
static final int borderTop = 5;
|
||||||
static final int borderBottom = 5;
|
static final int borderBottom = 5;
|
||||||
|
|
||||||
|
|
||||||
public static final Color[] colors = {
|
public static final Color[] colors = {
|
||||||
new Color(0xD66436),
|
new Color(0xD66436),
|
||||||
new Color(0x486F70),
|
new Color(0x486F70),
|
||||||
@@ -32,6 +38,12 @@ public class FieldCanvas extends JPanel{
|
|||||||
private List<Point> path;
|
private List<Point> path;
|
||||||
private boolean freeMoveMode = false;
|
private boolean freeMoveMode = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor of FieldCanvas
|
||||||
|
*
|
||||||
|
* @author timo
|
||||||
|
* @param g
|
||||||
|
*/
|
||||||
FieldCanvas(Game g){
|
FieldCanvas(Game g){
|
||||||
MouseAdapter ad = new MouseAdapter(){
|
MouseAdapter ad = new MouseAdapter(){
|
||||||
@Override
|
@Override
|
||||||
@@ -87,12 +99,22 @@ public class FieldCanvas extends JPanel{
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback if button freeMove gets pressed.
|
||||||
|
*
|
||||||
|
* @author timo
|
||||||
|
*/
|
||||||
public void doFreeMove() {
|
public void doFreeMove() {
|
||||||
if(game.getAvailFreeMoves()>0) {
|
if(game.getAvailFreeMoves()>0) {
|
||||||
freeMoveMode = true;
|
freeMoveMode = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback if button undo gets pressed.
|
||||||
|
*
|
||||||
|
* @author timo
|
||||||
|
*/
|
||||||
public void doUndo() {
|
public void doUndo() {
|
||||||
if(game.getAvailUndo()>0) {
|
if(game.getAvailUndo()>0) {
|
||||||
game.doUndo();
|
game.doUndo();
|
||||||
@@ -100,6 +122,13 @@ public class FieldCanvas extends JPanel{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculates the position in which a click event has happened.
|
||||||
|
*
|
||||||
|
* @author timo
|
||||||
|
* @param globalPos
|
||||||
|
* @return Position of clickevent
|
||||||
|
*/
|
||||||
private Point getClickPoint(Point globalPos) {
|
private Point getClickPoint(Point globalPos) {
|
||||||
int total = Math.min(this.getHeight()-borderTop-borderBottom,FieldCanvas.this.getWidth()-borderLeft-borderRight);
|
int total = Math.min(this.getHeight()-borderTop-borderBottom,FieldCanvas.this.getWidth()-borderLeft-borderRight);
|
||||||
int space = total/game.getSize();
|
int space = total/game.getSize();
|
||||||
@@ -109,6 +138,11 @@ public class FieldCanvas extends JPanel{
|
|||||||
return new Point(globalPos.x/space,globalPos.y/space);
|
return new Point(globalPos.x/space,globalPos.y/space);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Paint the game field.
|
||||||
|
*
|
||||||
|
* @author timo
|
||||||
|
*/
|
||||||
public void paintComponent(Graphics g) {
|
public void paintComponent(Graphics g) {
|
||||||
super.paintComponent(g);
|
super.paintComponent(g);
|
||||||
|
|
||||||
|
|||||||
@@ -305,8 +305,8 @@ public class Game {
|
|||||||
|
|
||||||
level = 1;
|
level = 1;
|
||||||
score = 0;
|
score = 0;
|
||||||
numUndos = 100;
|
numUndos = 2;
|
||||||
freeMoves = 100;
|
freeMoves = 0;
|
||||||
linesLeft=linesPerLevel;
|
linesLeft=linesPerLevel;
|
||||||
|
|
||||||
// Populate game field
|
// Populate game field
|
||||||
|
|||||||
@@ -2,6 +2,11 @@ package ch.bfh.sevennotseven;
|
|||||||
|
|
||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Vertex class which abstracts vertices as an object.
|
||||||
|
*
|
||||||
|
* @author aaron
|
||||||
|
*/
|
||||||
public class Vertex {
|
public class Vertex {
|
||||||
|
|
||||||
/* Class Members */
|
/* Class Members */
|
||||||
|
|||||||
@@ -1,16 +1,10 @@
|
|||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package ch.bfh.sevennotseven;
|
package ch.bfh.sevennotseven;
|
||||||
|
|
||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
import java.awt.Button;
|
|
||||||
import java.awt.CardLayout;
|
import java.awt.CardLayout;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.FlowLayout;
|
import java.awt.FlowLayout;
|
||||||
import java.awt.Frame;
|
|
||||||
import java.awt.HeadlessException;
|
import java.awt.HeadlessException;
|
||||||
import java.awt.Panel;
|
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.awt.event.WindowAdapter;
|
import java.awt.event.WindowAdapter;
|
||||||
@@ -21,11 +15,10 @@ import javax.swing.JFrame;
|
|||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author aaron
|
* Window class, places gui elements and listeners.
|
||||||
*
|
*
|
||||||
|
* @author timo
|
||||||
*/
|
*/
|
||||||
public class Window extends JFrame implements ActionListener{
|
public class Window extends JFrame implements ActionListener{
|
||||||
|
|
||||||
@@ -42,7 +35,12 @@ public class Window extends JFrame implements ActionListener{
|
|||||||
private JPanel mainPanel;
|
private JPanel mainPanel;
|
||||||
private CardLayout cardLayout;
|
private CardLayout cardLayout;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor of window class
|
||||||
|
*
|
||||||
|
* @param title
|
||||||
|
* @throws HeadlessException
|
||||||
|
*/
|
||||||
public Window(String title) throws HeadlessException {
|
public Window(String title) throws HeadlessException {
|
||||||
super(title);
|
super(title);
|
||||||
|
|
||||||
@@ -60,7 +58,6 @@ public class Window extends JFrame implements ActionListener{
|
|||||||
|
|
||||||
moves.setPreferredSize(new Dimension(200, 40));
|
moves.setPreferredSize(new Dimension(200, 40));
|
||||||
|
|
||||||
|
|
||||||
buttonFreeMove= new JButton("Free Move (0)");
|
buttonFreeMove= new JButton("Free Move (0)");
|
||||||
buttonFreeMove.setEnabled(false);
|
buttonFreeMove.setEnabled(false);
|
||||||
buttonFreeMove.addActionListener(this);
|
buttonFreeMove.addActionListener(this);
|
||||||
@@ -82,6 +79,11 @@ public class Window extends JFrame implements ActionListener{
|
|||||||
topPanel.add(labelLevel);
|
topPanel.add(labelLevel);
|
||||||
topPanel.add(moves);
|
topPanel.add(moves);
|
||||||
|
|
||||||
|
buttonFreeMove.setEnabled(game.getAvailFreeMoves()>0);
|
||||||
|
buttonUndo.setEnabled(game.getAvailUndo()>0);
|
||||||
|
buttonFreeMove.setText("Free Move ("+game.getAvailFreeMoves()+")");
|
||||||
|
buttonUndo.setText("Undo ("+game.getAvailUndo()+")");
|
||||||
|
|
||||||
game.addUpdateListener(new Game.UpdateListener() {
|
game.addUpdateListener(new Game.UpdateListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -106,7 +108,6 @@ public class Window extends JFrame implements ActionListener{
|
|||||||
welcomePanel.add(btn);
|
welcomePanel.add(btn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
JPanel gamePanel = new JPanel();
|
JPanel gamePanel = new JPanel();
|
||||||
gamePanel.setLayout(new BorderLayout());
|
gamePanel.setLayout(new BorderLayout());
|
||||||
gamePanel.add(topPanel, BorderLayout.NORTH);
|
gamePanel.add(topPanel, BorderLayout.NORTH);
|
||||||
@@ -123,10 +124,14 @@ public class Window extends JFrame implements ActionListener{
|
|||||||
this.setSize(470,460);
|
this.setSize(470,460);
|
||||||
this.setVisible(true);
|
this.setVisible(true);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Action listener callback, determines which function to call.
|
||||||
|
*
|
||||||
|
* @author timo
|
||||||
|
* @param e ActionEvent
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
String command = e.getActionCommand();
|
String command = e.getActionCommand();
|
||||||
@@ -143,6 +148,9 @@ public class Window extends JFrame implements ActionListener{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Main method
|
||||||
|
*
|
||||||
|
* @author timo
|
||||||
* @param args
|
* @param args
|
||||||
*/
|
*/
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|||||||
Reference in New Issue
Block a user