diff --git a/src/main/java/eu/mhsl/minenet/minigames/instance/game/stateless/types/tetris/Tetris.java b/src/main/java/eu/mhsl/minenet/minigames/instance/game/stateless/types/tetris/Tetris.java index 11c25ac..0107b50 100644 --- a/src/main/java/eu/mhsl/minenet/minigames/instance/game/stateless/types/tetris/Tetris.java +++ b/src/main/java/eu/mhsl/minenet/minigames/instance/game/stateless/types/tetris/Tetris.java @@ -28,7 +28,7 @@ class Tetris extends StatelessGame { public Tetris(int nextTetrominoesCount, boolean isFast, boolean hasCombat) { super(Dimension.THE_END.key, "Tetris", new PointsWinScore()); - eventNode() + this.eventNode() .addListener(PlayerUseItemEvent.class, this::onPlayerInteract) .addListener(PlayerHandAnimationEvent.class, this::onPlayerAttack) .addListener(PlayerTickEvent.class, this::onPlayerTick); @@ -58,7 +58,7 @@ class Tetris extends StatelessGame { protected void onStop() { this.tetrisGames.forEach((player, tetrisGame) -> { tetrisGame.loose(); - getScore().insertResult(player, tetrisGame.getScore()); + this.getScore().insertResult(player, tetrisGame.getScore()); tetrisGame.sidebar.removeViewer(player); }); } @@ -106,7 +106,7 @@ class Tetris extends StatelessGame { TetrisGame tetrisGame = this.tetrisGames.get(player); if(tetrisGame == null) return; if(tetrisGame.lost && player.getGameMode() != GameMode.SPECTATOR) { - letPlayerLoose(player); + this.letPlayerLoose(player); } } @@ -114,15 +114,15 @@ class Tetris extends StatelessGame { TetrisGame tetrisGame = this.tetrisGames.get(player); player.setGameMode(GameMode.SPECTATOR); player.setInvisible(true); - getScore().insertResult(player, tetrisGame.getScore()); + this.getScore().insertResult(player, tetrisGame.getScore()); boolean allGamesLost = this.tetrisGames.values().stream() .filter(game -> !game.lost) .toList() .isEmpty(); - if(!setTimeLimit && !allGamesLost) { + if(!this.setTimeLimit && !allGamesLost) { this.setTimeLimit(90); - setTimeLimit = true; + this.setTimeLimit = true; } } @@ -134,7 +134,7 @@ class Tetris extends StatelessGame { if(this.tetrisGames.get(p) == null) { this.tetrisGames.put(p, new TetrisGame( this, - getSpawn().sub(6, 8, 15).add(this.tetrisGames.size()*30, 0, 0), + this.getSpawn().sub(6, 8, 15).add(this.tetrisGames.size()*30, 0, 0), Tetromino.Shape.J, this.nextTetrominoesCount, this.isFast, diff --git a/src/main/java/eu/mhsl/minenet/minigames/instance/game/stateless/types/tetris/game/Playfield.java b/src/main/java/eu/mhsl/minenet/minigames/instance/game/stateless/types/tetris/game/Playfield.java index edf4ddb..115e0fa 100644 --- a/src/main/java/eu/mhsl/minenet/minigames/instance/game/stateless/types/tetris/game/Playfield.java +++ b/src/main/java/eu/mhsl/minenet/minigames/instance/game/stateless/types/tetris/game/Playfield.java @@ -74,10 +74,10 @@ public class Playfield { } } - batch.setBlock(getPlayerSpawnPosition().sub(0, 1, 0), Block.STONE); - batch.setBlock(getPlayerSpawnPosition().sub(1, 1, 0), Block.STONE); - batch.setBlock(getPlayerSpawnPosition().sub(1, 1, 1), Block.STONE); - batch.setBlock(getPlayerSpawnPosition().sub(0, 1, 1), Block.STONE); + batch.setBlock(this.getPlayerSpawnPosition().sub(0, 1, 0), Block.STONE); + batch.setBlock(this.getPlayerSpawnPosition().sub(1, 1, 0), Block.STONE); + batch.setBlock(this.getPlayerSpawnPosition().sub(1, 1, 1), Block.STONE); + batch.setBlock(this.getPlayerSpawnPosition().sub(0, 1, 1), Block.STONE); BatchUtil.loadAndApplyBatch(batch, this.instance, () -> {}); } @@ -90,7 +90,7 @@ public class Playfield { if(this.instance.getBlock(this.lowerLeftCorner.add(x, y, 1)) == Block.AIR) isFullLine = false; } if(isFullLine) { - removeFullLine(y); + this.removeFullLine(y); removedLinesCounter += 1; y -= 1; } @@ -99,10 +99,10 @@ public class Playfield { } public void addLines(int lines) { - int xPosMissing = random.nextInt(1, 10); + int xPosMissing = this.random.nextInt(1, 10); for (int i = 0; i < lines; i++) { - moveAllLinesUp(); + this.moveAllLinesUp(); for (int x = 1; x < 11; x++) { if(x != xPosMissing) { this.instance.setBlock(this.lowerLeftCorner.add(x, 1, 1), Block.LIGHT_GRAY_CONCRETE); diff --git a/src/main/java/eu/mhsl/minenet/minigames/instance/game/stateless/types/tetris/game/TetrisGame.java b/src/main/java/eu/mhsl/minenet/minigames/instance/game/stateless/types/tetris/game/TetrisGame.java index 20d2902..dc6cabe 100644 --- a/src/main/java/eu/mhsl/minenet/minigames/instance/game/stateless/types/tetris/game/TetrisGame.java +++ b/src/main/java/eu/mhsl/minenet/minigames/instance/game/stateless/types/tetris/game/TetrisGame.java @@ -121,8 +121,8 @@ public class TetrisGame { public void tick() { if(this.lost || this.paused) return; - if(!currentTetromino.moveDown()) { - setActiveTetrominoDown(); + if(!this.currentTetromino.moveDown()) { + this.setActiveTetrominoDown(); } } @@ -176,7 +176,7 @@ public class TetrisGame { } private boolean switchHold() { - if(!holdPossible) return false; + if(!this.holdPossible) return false; Tetromino newCurrentTetromino; if(this.holdTetromino == null) { @@ -194,7 +194,7 @@ public class TetrisGame { this.currentTetromino.setPosition(this.tetrominoSpawnPosition); this.currentTetromino.draw(); - if(!this.currentTetromino.moveDown()) loose(); + if(!this.currentTetromino.moveDown()) this.loose(); double xChange = this.holdTetromino.getXChange(); this.holdTetromino.setPosition(this.holdPosition.add(xChange, 0, 0)); @@ -312,7 +312,7 @@ public class TetrisGame { this.currentTetromino.setPosition(this.tetrominoSpawnPosition); this.currentTetromino.draw(); if(!this.currentTetromino.moveDown()) { - loose(); + this.loose(); } } } diff --git a/src/main/java/eu/mhsl/minenet/minigames/instance/game/stateless/types/tetris/game/Tetromino.java b/src/main/java/eu/mhsl/minenet/minigames/instance/game/stateless/types/tetris/game/Tetromino.java index f673961..1c8a95c 100644 --- a/src/main/java/eu/mhsl/minenet/minigames/instance/game/stateless/types/tetris/game/Tetromino.java +++ b/src/main/java/eu/mhsl/minenet/minigames/instance/game/stateless/types/tetris/game/Tetromino.java @@ -38,13 +38,13 @@ public class Tetromino { this.uuid = UUID.randomUUID(); switch (this.shape) { - case I -> shapeArray = new int[][]{{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}, {0, 0, 0, 0}}; - case J -> shapeArray = new int[][]{{1,0,0}, {1,1,1}, {0,0,0}}; - case L -> shapeArray = new int[][]{{0,0,1}, {1,1,1}, {0,0,0}}; - case O -> shapeArray = new int[][]{{1,1}, {1,1}}; - case S -> shapeArray = new int[][]{{0,1,1}, {1,1,0}, {0,0,0}}; - case T -> shapeArray = new int[][]{{0,1,0}, {1,1,1}, {0,0,0}}; - case Z -> shapeArray = new int[][]{{1,1,0}, {0,1,1}, {0,0,0}}; + case I -> this.shapeArray = new int[][]{{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}, {0, 0, 0, 0}}; + case J -> this.shapeArray = new int[][]{{1,0,0}, {1,1,1}, {0,0,0}}; + case L -> this.shapeArray = new int[][]{{0,0,1}, {1,1,1}, {0,0,0}}; + case O -> this.shapeArray = new int[][]{{1,1}, {1,1}}; + case S -> this.shapeArray = new int[][]{{0,1,1}, {1,1,0}, {0,0,0}}; + case T -> this.shapeArray = new int[][]{{0,1,0}, {1,1,1}, {0,0,0}}; + case Z -> this.shapeArray = new int[][]{{1,1,0}, {0,1,1}, {0,0,0}}; } } @@ -58,22 +58,22 @@ public class Tetromino { public boolean rotate(boolean clockwise) { int[][] newShapeArray = this.getTurnedShapeArray(clockwise); - return checkCollisionAndMove(this.position, newShapeArray); + return this.checkCollisionAndMove(this.position, newShapeArray); } public boolean moveDown() { Pos newPosition = this.position.sub(0, 1, 0); - return checkCollisionAndMove(newPosition, this.shapeArray); + return this.checkCollisionAndMove(newPosition, this.shapeArray); } public boolean moveLeft() { Pos newPosition = this.position.sub(1, 0, 0); - return checkCollisionAndMove(newPosition, this.shapeArray); + return this.checkCollisionAndMove(newPosition, this.shapeArray); } public boolean moveRight() { Pos newPosition = this.position.add(1, 0, 0); - return checkCollisionAndMove(newPosition, this.shapeArray); + return this.checkCollisionAndMove(newPosition, this.shapeArray); } public void draw() { @@ -83,11 +83,11 @@ public class Tetromino { public void draw(boolean withGhost) { if(withGhost) { Pos ghostPos = this.position; - while (!checkCollision(ghostPos.sub(0, 1, 0), this.shapeArray)) { + while (!this.checkCollision(ghostPos.sub(0, 1, 0), this.shapeArray)) { ghostPos = ghostPos.sub(0, 1, 0); } Pos positionChange = this.position.sub(ghostPos); - getBlockPositions().forEach(pos -> { + this.getBlockPositions().forEach(pos -> { Entity ghostBlock = new Entity(ghostEntityType); ((FallingBlockMeta) ghostBlock.getEntityMeta()).setBlock(this.getGhostBlock()); ghostBlock.setNoGravity(true); @@ -97,11 +97,11 @@ public class Tetromino { }); } - getBlockPositions().forEach(pos -> this.instance.setBlock(pos, this.getColoredBlock())); + this.getBlockPositions().forEach(pos -> this.instance.setBlock(pos, this.getColoredBlock())); } public void drawAsEntities() { - getBlockPositions().forEach(pos -> { + this.getBlockPositions().forEach(pos -> { Entity ghostBlock = new Entity(ghostEntityType); ((FallingBlockMeta) ghostBlock.getEntityMeta()).setBlock(this.getColoredBlock()); ghostBlock.setNoGravity(true); @@ -222,10 +222,10 @@ public class Tetromino { } private boolean checkCollision(Pos newPosition, int[][] newShapeArray) { - List newBlockPositions = getBlockPositions(newPosition, newShapeArray); + List newBlockPositions = this.getBlockPositions(newPosition, newShapeArray); for(Pos pos : newBlockPositions) { - if(isPartOfTetromino(pos)) continue; + if(this.isPartOfTetromino(pos)) continue; if(this.instance.getBlock(pos) == this.getGhostBlock()) continue; if(this.instance.getBlock(pos) != Block.AIR) return true; } @@ -234,7 +234,7 @@ public class Tetromino { } private boolean checkCollisionAndMove(Pos newPosition, int[][] newShapeArray) { - if(!checkCollision(newPosition, newShapeArray)) { + if(!this.checkCollision(newPosition, newShapeArray)) { this.remove(); this.shapeArray = Arrays.stream(newShapeArray).map(int[]::clone).toArray(int[][]::new); this.setPosition(newPosition);