Added basic welcome screen and some level stuff.

This commit is contained in:
t-moe
2016-06-20 00:56:22 +02:00
parent fd287beb9d
commit 0a70f9610e
3 changed files with 70 additions and 21 deletions

View File

@@ -14,6 +14,7 @@ public class Game {
// Constants
static final int numberOfColors = 5;
static final int linesPerLevel = 40;
// Private members
private int[][] field;
@@ -24,6 +25,7 @@ public class Game {
private int freeBlocks;
private int freeMoves;
private int numUndos;
private int linesLeft;
private Random rand;
private ArrayList<UpdateListener> updateListeners;
@@ -37,16 +39,9 @@ public class Game {
* @author aaron
* @param size
*/
public Game (int size) {
/* Initialize variables */
this.size = size;
this.level = 1;
this.score = 0;
this.freeBlocks = size * size;
this.updateListeners = new ArrayList<UpdateListener>();
public Game (int size) {
rand = new Random(); // Initialize random object
this.reset();
this.reset(size);
}
public void addUpdateListener(UpdateListener listener) {
@@ -75,6 +70,10 @@ public class Game {
}
public int getLinesLeft() {
return linesLeft;
}
public int getLevel(){
return level;
}
@@ -223,7 +222,11 @@ public class Game {
*
* @author aaron
*/
public void reset(){
public void reset(int size){
this.size = size;
this.freeBlocks = size * size;
this.updateListeners = new ArrayList<UpdateListener>();
// Initialize new blocks
nextBlocks = new ArrayList<Integer>();
nextBlocks.add(1);
@@ -236,6 +239,7 @@ public class Game {
score = 0;
numUndos = 0;
freeMoves = 0;
linesLeft=linesPerLevel;
// Populate game field
this.populateField();
@@ -328,6 +332,13 @@ public class Game {
private void nextStep(final Point lastPoint) {
if(!checkRemoveBlocks(lastPoint)){
populateField(); //add new blocks
} else {
linesLeft--;
if(linesLeft==0) {
level++;
linesLeft=linesPerLevel;
}
}
emitUpdateEvent();
}