added combos

This commit is contained in:
Lars Neuhaus 2024-10-23 17:41:05 +02:00
parent 73a374e529
commit 6638a48677

View File

@ -17,6 +17,7 @@ public class TetrisGame {
private int level = 1; private int level = 1;
private int lines = 0; private int lines = 0;
private int score = 0; private int score = 0;
private int combo = 0;
private int attackingLines = 0; private int attackingLines = 0;
public boolean lost = false; public boolean lost = false;
public boolean paused = true; public boolean paused = true;
@ -279,7 +280,9 @@ public class TetrisGame {
int removedLines = this.playfield.removeFullLines(); int removedLines = this.playfield.removeFullLines();
int combatLines = 0; int combatLines = 0;
this.combo += 1;
switch (removedLines) { switch (removedLines) {
case 0 -> this.combo = 0;
case 1 -> { case 1 -> {
this.lines += 1; this.lines += 1;
this.score += 40 * this.level; this.score += 40 * this.level;
@ -301,6 +304,11 @@ public class TetrisGame {
} }
} }
this.score += 50 * this.combo * this.level;
if(this.combo >= 2) {
combatLines += (int) Math.floor((double) this.combo /2);
}
if(this.hasCombat && this.attackingLines > 0) { if(this.hasCombat && this.attackingLines > 0) {
if(combatLines > 0 && this.attackingLines >= combatLines) { if(combatLines > 0 && this.attackingLines >= combatLines) {
this.attackingLines -= combatLines; this.attackingLines -= combatLines;