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