Implemented score undo
This commit is contained in:
@@ -22,6 +22,7 @@ public class Game {
|
|||||||
private ArrayList<Integer> nextBlocks;
|
private ArrayList<Integer> nextBlocks;
|
||||||
private ArrayList<Integer[][]> oldFields;
|
private ArrayList<Integer[][]> oldFields;
|
||||||
private ArrayList<ArrayList<Integer>> oldNextBlocks;
|
private ArrayList<ArrayList<Integer>> oldNextBlocks;
|
||||||
|
private ArrayList<Integer> oldScore;
|
||||||
private int level;
|
private int level;
|
||||||
private int score;
|
private int score;
|
||||||
private int size;
|
private int size;
|
||||||
@@ -50,7 +51,6 @@ public class Game {
|
|||||||
|
|
||||||
public boolean isGameOver(){
|
public boolean isGameOver(){
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getAvailFreeMoves(){
|
public int getAvailFreeMoves(){
|
||||||
@@ -84,12 +84,10 @@ public class Game {
|
|||||||
|
|
||||||
public Integer[][] getField(){
|
public Integer[][] getField(){
|
||||||
return field;
|
return field;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canMove(Point src, Point dst){
|
public boolean canMove(Point src, Point dst){
|
||||||
return getPath(src, dst) != null;
|
return getPath(src, dst) != null;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -219,6 +217,15 @@ public class Game {
|
|||||||
|
|
||||||
field= oldFields.remove(oldFields.size() - 1);
|
field= oldFields.remove(oldFields.size() - 1);
|
||||||
nextBlocks = oldNextBlocks.remove(oldNextBlocks.size() - 1);
|
nextBlocks = oldNextBlocks.remove(oldNextBlocks.size() - 1);
|
||||||
|
|
||||||
|
int old1 = oldScore.get(oldScore.size() - 1); // this round
|
||||||
|
int old2 = oldScore.get(oldScore.size() - 2); // last round
|
||||||
|
|
||||||
|
// If score has changed in the last round
|
||||||
|
if((oldScore.size() > 1) && (old1 > old2)){
|
||||||
|
score = old2; // Reset score
|
||||||
|
}
|
||||||
|
|
||||||
numUndos--;
|
numUndos--;
|
||||||
|
|
||||||
emitUpdateEvent();
|
emitUpdateEvent();
|
||||||
@@ -237,6 +244,7 @@ public class Game {
|
|||||||
|
|
||||||
oldNextBlocks.add(new ArrayList<Integer>(nextBlocks));
|
oldNextBlocks.add(new ArrayList<Integer>(nextBlocks));
|
||||||
oldFields.add(fieldCopy);
|
oldFields.add(fieldCopy);
|
||||||
|
oldScore.add(score);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -257,7 +265,6 @@ public class Game {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
saveStep();
|
saveStep();
|
||||||
|
|
||||||
field[dst.x][dst.y] = field[src.x][src.y];
|
field[dst.x][dst.y] = field[src.x][src.y];
|
||||||
@@ -294,6 +301,7 @@ public class Game {
|
|||||||
//undo stuff
|
//undo stuff
|
||||||
oldFields = new ArrayList<Integer[][]>();
|
oldFields = new ArrayList<Integer[][]>();
|
||||||
oldNextBlocks = new ArrayList<ArrayList<Integer>>();
|
oldNextBlocks = new ArrayList<ArrayList<Integer>>();
|
||||||
|
oldScore = new ArrayList<Integer>();
|
||||||
|
|
||||||
level = 1;
|
level = 1;
|
||||||
score = 0;
|
score = 0;
|
||||||
@@ -399,6 +407,8 @@ public class Game {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
oldScore.add(score);
|
||||||
emitUpdateEvent();
|
emitUpdateEvent();
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -474,6 +484,7 @@ public class Game {
|
|||||||
|
|
||||||
for( Integer i : matches ) sum += i;
|
for( Integer i : matches ) sum += i;
|
||||||
|
|
||||||
|
oldScore.add(score);
|
||||||
score += (1 + distinctmatches * sum);
|
score += (1 + distinctmatches * sum);
|
||||||
|
|
||||||
System.out.println("Score: " + score);
|
System.out.println("Score: " + score);
|
||||||
@@ -492,7 +503,6 @@ public class Game {
|
|||||||
*/
|
*/
|
||||||
private void populateField(){
|
private void populateField(){
|
||||||
|
|
||||||
|
|
||||||
// while there are blocks left in nextBlocks
|
// while there are blocks left in nextBlocks
|
||||||
while((nextBlocks.size() > 0) && (freeBlocks > 0)){
|
while((nextBlocks.size() > 0) && (freeBlocks > 0)){
|
||||||
int x = rand.nextInt(size); // get random x position
|
int x = rand.nextInt(size); // get random x position
|
||||||
|
|||||||
Reference in New Issue
Block a user