Improved docu, changed one game color
This commit is contained in:
@@ -29,7 +29,7 @@ public class FieldCanvas extends JPanel{
|
|||||||
new Color(0x486F70),
|
new Color(0x486F70),
|
||||||
new Color(0xCBD840),
|
new Color(0xCBD840),
|
||||||
new Color(0x8B2700),
|
new Color(0x8B2700),
|
||||||
new Color(0x33CCCC)
|
new Color(0x439999)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -47,6 +47,9 @@ public class FieldCanvas extends JPanel{
|
|||||||
*/
|
*/
|
||||||
FieldCanvas(Game g){
|
FieldCanvas(Game g){
|
||||||
MouseAdapter ad = new MouseAdapter(){
|
MouseAdapter ad = new MouseAdapter(){
|
||||||
|
/**
|
||||||
|
* mousePressed Handler gets called when the user pressed the mouse button down
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void mousePressed(MouseEvent e) {
|
public void mousePressed(MouseEvent e) {
|
||||||
super.mousePressed(e);
|
super.mousePressed(e);
|
||||||
@@ -65,6 +68,9 @@ public class FieldCanvas extends JPanel{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* mouseDrag Handler gets called when the user moves the mouse while the mouse button is pressed
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void mouseDragged(MouseEvent e) {
|
public void mouseDragged(MouseEvent e) {
|
||||||
super.mouseDragged(e);
|
super.mouseDragged(e);
|
||||||
@@ -93,6 +99,9 @@ public class FieldCanvas extends JPanel{
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* mouseRelease Handler gets called when the user releases the mouse button
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void mouseReleased(MouseEvent e) {
|
public void mouseReleased(MouseEvent e) {
|
||||||
super.mouseReleased(e);
|
super.mouseReleased(e);
|
||||||
|
|||||||
@@ -19,9 +19,9 @@ public class Game {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
static final int numberOfColors = 5;
|
static final int numberOfColors = 5; //number of distinct block colors
|
||||||
static final int linesPerLevel = 40;
|
static final int linesPerLevel = 40; //number of lines the user has to clear before he moves to the next level
|
||||||
static final int blocksPerLevel []= {3,4,5};
|
static final int blocksPerLevel []= {3,4,5}; //number of blocks that are added in each step for the first n=3 levels.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class that stores one specific state of the game and restores it on demand
|
* Class that stores one specific state of the game and restores it on demand
|
||||||
@@ -45,6 +45,7 @@ public class Game {
|
|||||||
level = Game.this.level;
|
level = Game.this.level;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Storage for the state variables
|
||||||
private ArrayList<Integer> nextBlocks;
|
private ArrayList<Integer> nextBlocks;
|
||||||
private int score;
|
private int score;
|
||||||
private int field[][];
|
private int field[][];
|
||||||
@@ -101,43 +102,77 @@ public class Game {
|
|||||||
this.reset(size);
|
this.reset(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isGameOver(){
|
/**
|
||||||
return false;
|
* Returns the number of freemoves left
|
||||||
}
|
* @return
|
||||||
|
*/
|
||||||
public int getAvailFreeMoves(){
|
public int getAvailFreeMoves(){
|
||||||
return freeMoves;
|
return freeMoves;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the number of available undos
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public int getAvailUndo(){
|
public int getAvailUndo(){
|
||||||
return numUndos;
|
return numUndos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the size of the game in one dimensions (field is always quadratic)
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public int getSize(){
|
public int getSize(){
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the current score
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public int getScore(){
|
public int getScore(){
|
||||||
return score;
|
return score;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the number of lines that need to be cleared to reach the next level
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public int getLinesLeft(){
|
public int getLinesLeft(){
|
||||||
return linesLeft;
|
return linesLeft;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the current level number
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public int getLevel(){
|
public int getLevel(){
|
||||||
return level;
|
return level;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the block color which will be placed next on the field
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public List<Integer> getNextBlocks(){
|
public List<Integer> getNextBlocks(){
|
||||||
return nextBlocks;
|
return nextBlocks;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int[][] getField(){
|
/**
|
||||||
|
* Returns the current game field
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public final int[][] getField(){
|
||||||
return field;
|
return field;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether or not we can move from src to dst without crossing any walls
|
||||||
|
* @param src start point
|
||||||
|
* @param dst destination point
|
||||||
|
* @return true if move is possible
|
||||||
|
*/
|
||||||
public boolean canMove(Point src, Point dst){
|
public boolean canMove(Point src, Point dst){
|
||||||
return getPath(src, dst) != null;
|
return getPath(src, dst) != null;
|
||||||
}
|
}
|
||||||
@@ -172,10 +207,10 @@ public class Game {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Try to move the block from src to dst without crossing any walls
|
* Try to move the block from src to dst (without crossing any walls)
|
||||||
*
|
*
|
||||||
* @param src
|
* @param src source block position
|
||||||
* @param dst
|
* @param dst destination position
|
||||||
* @return True if a move was successful
|
* @return True if a move was successful
|
||||||
*/
|
*/
|
||||||
public boolean doMove(Point src, Point dst){
|
public boolean doMove(Point src, Point dst){
|
||||||
@@ -198,7 +233,7 @@ public class Game {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Seeks the shortest path between src and dst without crossing any walls
|
* Returns the shortest path between src and dst (without crossing any walls)
|
||||||
*
|
*
|
||||||
* @param src
|
* @param src
|
||||||
* @param dst
|
* @param dst
|
||||||
@@ -249,6 +284,9 @@ public class Game {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Saves the current game state/step
|
||||||
|
*/
|
||||||
private void saveStep() {
|
private void saveStep() {
|
||||||
lastStates.add(new State()); //add a new State Object (which will be initialized to the current game state) to the backup list
|
lastStates.add(new State()); //add a new State Object (which will be initialized to the current game state) to the backup list
|
||||||
|
|
||||||
@@ -287,7 +325,7 @@ public class Game {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reset game score, field and state.
|
* Resets the game. The game will restart
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public void reset(int size){
|
public void reset(int size){
|
||||||
@@ -345,7 +383,7 @@ public class Game {
|
|||||||
* Collision detection and block removal if there are 4 or more blocks in a row in any direction.
|
* Collision detection and block removal if there are 4 or more blocks in a row in any direction.
|
||||||
* Also increases the score if necessary
|
* Also increases the score if necessary
|
||||||
*
|
*
|
||||||
* @param lastPoint
|
* @param lastPoint point around which the checks should be made
|
||||||
* @return True if any blocks got removed
|
* @return True if any blocks got removed
|
||||||
*/
|
*/
|
||||||
private boolean checkRemoveBlocks(final Point lastPoint){
|
private boolean checkRemoveBlocks(final Point lastPoint){
|
||||||
|
|||||||
@@ -92,6 +92,7 @@ public class PathFinder {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Storage for last values
|
||||||
private ArrayList<Vertex> verticies = null;
|
private ArrayList<Vertex> verticies = null;
|
||||||
private Point lastSrc = null;
|
private Point lastSrc = null;
|
||||||
private int[][] lastField = null;
|
private int[][] lastField = null;
|
||||||
@@ -155,6 +156,7 @@ public class PathFinder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//assign new values to storage
|
||||||
lastSrc = src;
|
lastSrc = src;
|
||||||
verticies = allVerticies;
|
verticies = allVerticies;
|
||||||
lastField = field;
|
lastField = field;
|
||||||
|
|||||||
@@ -53,6 +53,9 @@ public class Window extends JFrame implements ActionListener, Game.UpdateListen
|
|||||||
initMainLayout();
|
initMainLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the main layout
|
||||||
|
*/
|
||||||
private void initMainLayout() {
|
private void initMainLayout() {
|
||||||
mainPanel = new JPanel();
|
mainPanel = new JPanel();
|
||||||
cardLayout = new CardLayout();
|
cardLayout = new CardLayout();
|
||||||
@@ -65,6 +68,9 @@ public class Window extends JFrame implements ActionListener, Game.UpdateListen
|
|||||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the layout of the game itself
|
||||||
|
*/
|
||||||
private void initGameLayout() {
|
private void initGameLayout() {
|
||||||
|
|
||||||
moves = new NextMovesCanvas(game);
|
moves = new NextMovesCanvas(game);
|
||||||
@@ -112,6 +118,9 @@ public class Window extends JFrame implements ActionListener, Game.UpdateListen
|
|||||||
mainPanel.add(gamePanel);
|
mainPanel.add(gamePanel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the welcome screen layout
|
||||||
|
*/
|
||||||
private void initWelcomeLayout() {
|
private void initWelcomeLayout() {
|
||||||
JPanel welcomePanel = new JPanel();
|
JPanel welcomePanel = new JPanel();
|
||||||
welcomePanel.setLayout(new BoxLayout(welcomePanel, BoxLayout.Y_AXIS));
|
welcomePanel.setLayout(new BoxLayout(welcomePanel, BoxLayout.Y_AXIS));
|
||||||
|
|||||||
Reference in New Issue
Block a user