diff --git a/src/ch/bfh/sevennotseven/Game.java b/src/ch/bfh/sevennotseven/Game.java index 883b687..779e886 100644 --- a/src/ch/bfh/sevennotseven/Game.java +++ b/src/ch/bfh/sevennotseven/Game.java @@ -31,6 +31,12 @@ public class Game { this(7); } + /** + * Constructor. + * + * @author aaron + * @param size + */ public Game (int size) { /* Initialize variables */ this.size = size; @@ -87,6 +93,14 @@ public class Game { } + /** + * Check if there is a valid path from src to dst and move a block if possible. + * + * @author aaron + * @param src + * @param dst + * @return + */ public boolean doMove(Point src, Point dst){ if(field[src.x][src.y]==0 ||field[dst.x][dst.y] !=0 || src.equals(dst)) { return false; @@ -105,7 +119,12 @@ public class Game { } /** - * Pathfinding of shortest path between src and dst. + * Pathfinding of shortest path between src and dst. + * + * @author aaron + * @param src + * @param dst + * @return */ public List getPath(final Point src, final Point dst){ @@ -161,6 +180,14 @@ public class Game { return false; } + /** + * Do a free move if freeMoves < 0. + * + * @author aaron + * @param src + * @param dst + * @return + */ public boolean doFreeMove(Point src, Point dst){ //move without path checking if(getAvailFreeMoves() <= 0 ) { @@ -191,6 +218,11 @@ public class Game { return numUndos; } + /** + * Reset game score, field and state. + * + * @author aaron + */ public void reset(){ // Initialize new blocks nextBlocks = new ArrayList(); @@ -211,6 +243,10 @@ public class Game { /** * Finds the nearest vertex to start + * + * @author aaron + * @param vertices + * @return */ private Vertex findNearestVertex(final List vertices){ Vertex tmp = vertices.get(0); @@ -226,11 +262,28 @@ public class Game { return tmp; } + /** + * Helper function for pathfinding. Finds a vertex corresponding to the given coordinate. + * + * @author aaron + * @param x + * @param y + * @param vertices + * @return + */ private Vertex findVertex(int x, int y, final List vertices) { return findVertex(new Point(x,y), vertices); } + /** + * Helper function for pathfinding. Finds a vertex corresponding to the given point. + * + * @author aaron + * @param pos + * @param vertices + * @return + */ private Vertex findVertex(final Point pos, final List vertices) { for (int i = 0; i < vertices.size(); i++) { Vertex n = vertices.get(i); @@ -242,7 +295,9 @@ public class Game { } /** + * Helper function for pathfinding. Returns shortest path between src and dst in a given set of vertices. * + * @author aaron * @param vertices * @param src * @param dst @@ -267,7 +322,7 @@ public class Game { /** * Calculates the next game step. This method will either call populateField, or it will cleanup blocks * - * @author + * @author aaron * @param lastPoint */ private void nextStep(final Point lastPoint) { @@ -280,7 +335,7 @@ public class Game { /** * Collision detection and block removal if there are 4 or more blocks in a row in any direction. * - * @author + * @author aaron * @param lastPoint */ private boolean checkRemoveBlocks(final Point lastPoint){ @@ -343,6 +398,14 @@ public class Game { freeMoves++; } + int sum = 0; + + for( Integer i : matches ) sum += i; + + score += (1 + distinctmatches * sum); + + System.out.println("Score: " + score); + return true; }