continued fixing pr comments
This commit is contained in:
parent
0699206c21
commit
3fe57d5fe9
@ -50,7 +50,7 @@ public class StatelessGame extends Game {
|
|||||||
|
|
||||||
int timeLeft = timeLimit - timePlayed;
|
int timeLeft = timeLimit - timePlayed;
|
||||||
switch (timeLeft) {
|
switch (timeLeft) {
|
||||||
case 60, 30, 10, 5, 4, 3, 2, 1 ->
|
case 90, 60, 30, 10, 5, 4, 3, 2, 1 ->
|
||||||
new ChatMessage(Icon.SCIENCE).appendStatic("Noch " + timeLeft + " Sekunden!").send(getPlayers());
|
new ChatMessage(Icon.SCIENCE).appendStatic("Noch " + timeLeft + " Sekunden!").send(getPlayers());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,8 +4,6 @@ import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
|
|||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.tetris.game.TetrisGame;
|
import eu.mhsl.minenet.minigames.instance.game.stateless.types.tetris.game.TetrisGame;
|
||||||
import eu.mhsl.minenet.minigames.instance.Dimension;
|
import eu.mhsl.minenet.minigames.instance.Dimension;
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.tetris.game.Tetromino;
|
import eu.mhsl.minenet.minigames.instance.game.stateless.types.tetris.game.Tetromino;
|
||||||
import eu.mhsl.minenet.minigames.message.Icon;
|
|
||||||
import eu.mhsl.minenet.minigames.message.type.ChatMessage;
|
|
||||||
import eu.mhsl.minenet.minigames.score.PointsWinScore;
|
import eu.mhsl.minenet.minigames.score.PointsWinScore;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.minestom.server.coordinate.Pos;
|
import net.minestom.server.coordinate.Pos;
|
||||||
@ -18,7 +16,6 @@ import net.minestom.server.item.ItemStack;
|
|||||||
import net.minestom.server.item.Material;
|
import net.minestom.server.item.Material;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.WeakHashMap;
|
import java.util.WeakHashMap;
|
||||||
@ -54,7 +51,7 @@ class Tetris extends StatelessGame {
|
|||||||
.forEach(Entity::remove);
|
.forEach(Entity::remove);
|
||||||
|
|
||||||
if(this.hasCombat) {
|
if(this.hasCombat) {
|
||||||
this.tetrisGames.values().forEach(tetrisGame -> tetrisGame.updateOtherTetrisGames((List<TetrisGame>) this.tetrisGames.values()));
|
this.tetrisGames.values().forEach(tetrisGame -> tetrisGame.updateOtherTetrisGames(this.tetrisGames.values()));
|
||||||
}
|
}
|
||||||
|
|
||||||
this.tetrisGames.forEach((player, tetrisGame) -> tetrisGame.start());
|
this.tetrisGames.forEach((player, tetrisGame) -> tetrisGame.start());
|
||||||
@ -146,13 +143,12 @@ class Tetris extends StatelessGame {
|
|||||||
getScore().insertResult(player, tetrisGame.getScore());
|
getScore().insertResult(player, tetrisGame.getScore());
|
||||||
|
|
||||||
boolean allGamesLost = this.tetrisGames.values().stream()
|
boolean allGamesLost = this.tetrisGames.values().stream()
|
||||||
.filter(tetrisGame1 -> !tetrisGame1.lost)
|
.filter(game -> !game.lost)
|
||||||
.toList()
|
.toList()
|
||||||
.isEmpty();
|
.isEmpty();
|
||||||
if(!setTimeLimit && !allGamesLost) {
|
if(!setTimeLimit && !allGamesLost) {
|
||||||
this.setTimeLimit(90);
|
this.setTimeLimit(90);
|
||||||
setTimeLimit = true;
|
setTimeLimit = true;
|
||||||
new ChatMessage(Icon.SCIENCE).appendStatic("Noch 90 Sekunden!").send(getPlayers());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,8 +157,8 @@ class Tetris extends StatelessGame {
|
|||||||
p.getInventory().setItemStack(0, ItemStack.builder(Material.BIRCH_BUTTON).customName(Component.text("Controller")).build());
|
p.getInventory().setItemStack(0, ItemStack.builder(Material.BIRCH_BUTTON).customName(Component.text("Controller")).build());
|
||||||
p.setSprinting(false);
|
p.setSprinting(false);
|
||||||
|
|
||||||
if(this.tetrisGames.get(p) == null) {
|
this.tetrisGames.computeIfAbsent(p, player -> {
|
||||||
this.tetrisGames.put(p, new TetrisGame(
|
TetrisGame newTetrisGame = new TetrisGame(
|
||||||
this,
|
this,
|
||||||
getSpawn().sub(6, 8, 15).add(this.tetrisGames.size()*30, 0, 0),
|
getSpawn().sub(6, 8, 15).add(this.tetrisGames.size()*30, 0, 0),
|
||||||
Tetromino.Shape.J,
|
Tetromino.Shape.J,
|
||||||
@ -170,10 +166,12 @@ class Tetris extends StatelessGame {
|
|||||||
this.isFast,
|
this.isFast,
|
||||||
this.hasCombat,
|
this.hasCombat,
|
||||||
this.randomSeed
|
this.randomSeed
|
||||||
));
|
);
|
||||||
this.tetrisGames.get(p).generate();
|
this.tetrisGames.get(p).generate();
|
||||||
this.tetrisGames.forEach((player, tetrisGame) -> tetrisGame.updateOtherTetrisGames(this.tetrisGames.values().stream().toList()));
|
this.tetrisGames.values().forEach(tetrisGame -> tetrisGame.updateOtherTetrisGames(this.tetrisGames.values()));
|
||||||
}
|
return newTetrisGame;
|
||||||
|
});
|
||||||
|
|
||||||
TetrisGame tetrisGame = this.tetrisGames.get(p);
|
TetrisGame tetrisGame = this.tetrisGames.get(p);
|
||||||
|
|
||||||
p.teleport(tetrisGame.getPlayerSpawnPosition());
|
p.teleport(tetrisGame.getPlayerSpawnPosition());
|
||||||
|
@ -45,10 +45,6 @@ public class TetrisGame {
|
|||||||
space
|
space
|
||||||
}
|
}
|
||||||
|
|
||||||
public TetrisGame(StatelessGame instance, Pos lowerLeftCorner, long randomSeed) {
|
|
||||||
this(instance, lowerLeftCorner, Tetromino.Shape.J, 3, false, false, randomSeed);
|
|
||||||
}
|
|
||||||
|
|
||||||
public TetrisGame(StatelessGame instance, Pos lowerLeftCorner, Tetromino.Shape startTetrominoShape, int nextTetrominoesCount, boolean isfast, boolean hasCombat, long randomSeed) {
|
public TetrisGame(StatelessGame instance, Pos lowerLeftCorner, Tetromino.Shape startTetrominoShape, int nextTetrominoesCount, boolean isfast, boolean hasCombat, long randomSeed) {
|
||||||
this.isFast = isfast;
|
this.isFast = isfast;
|
||||||
this.hasCombat = hasCombat;
|
this.hasCombat = hasCombat;
|
||||||
@ -68,19 +64,24 @@ public class TetrisGame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void pressedButton(Button button) {
|
public void pressedButton(Button button) {
|
||||||
if(this.lastPresses.getOrDefault(button, 0L) >= System.currentTimeMillis()-100) return;
|
final int standardButtonDelay = 100;
|
||||||
|
final int buttonDebounce = 70;
|
||||||
|
|
||||||
|
if(this.lastPresses.getOrDefault(button, 0L) >= System.currentTimeMillis()-standardButtonDelay) return;
|
||||||
|
|
||||||
this.lastPresses.put(button, System.currentTimeMillis());
|
this.lastPresses.put(button, System.currentTimeMillis());
|
||||||
if(button == Button.W) this.lastPresses.put(button, System.currentTimeMillis()+70);
|
if(button == Button.W) this.lastPresses.put(button, System.currentTimeMillis()+buttonDebounce);
|
||||||
if(button == Button.S) this.lastPresses.put(button, System.currentTimeMillis()-70);
|
if(button == Button.S) this.lastPresses.put(button, System.currentTimeMillis()-buttonDebounce);
|
||||||
|
|
||||||
|
if(this.lost || this.paused) return;
|
||||||
|
|
||||||
switch (button) {
|
switch (button) {
|
||||||
case A -> this.moveLeft();
|
case A -> this.currentTetromino.moveLeft();
|
||||||
case S -> this.moveDown();
|
case S -> this.moveDown();
|
||||||
case D -> this.moveRight();
|
case D -> this.currentTetromino.moveRight();
|
||||||
case W -> this.hardDrop();
|
case W -> this.hardDrop();
|
||||||
case mouseLeft -> this.rotate(false);
|
case mouseLeft -> this.currentTetromino.rotate(false);
|
||||||
case mouseRight -> this.rotate(true);
|
case mouseRight -> this.currentTetromino.rotate(true);
|
||||||
case space -> this.switchHold();
|
case space -> this.switchHold();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -96,18 +97,16 @@ public class TetrisGame {
|
|||||||
if(this.lost) return TaskSchedule.stop();
|
if(this.lost) return TaskSchedule.stop();
|
||||||
int standardTickDelay = 40;
|
int standardTickDelay = 40;
|
||||||
if(this.isFast) standardTickDelay = 20;
|
if(this.isFast) standardTickDelay = 20;
|
||||||
if(this.paused) return TaskSchedule.tick(Math.round((float) standardTickDelay /this.level));
|
|
||||||
|
TaskSchedule nextTick = TaskSchedule.tick(Math.round((float) standardTickDelay /this.level));
|
||||||
|
if(this.paused) return nextTick;
|
||||||
this.tick();
|
this.tick();
|
||||||
return TaskSchedule.tick(Math.round((float) standardTickDelay /this.level));
|
return nextTick;
|
||||||
});
|
});
|
||||||
|
|
||||||
this.updateInfo();
|
this.updateInfo();
|
||||||
this.nextTetrominoes.forEach(tetromino -> {
|
this.nextTetrominoes.forEach(tetromino -> {
|
||||||
double xChange;
|
double xChange = -tetromino.getXChange();
|
||||||
switch (tetromino.shape) {
|
|
||||||
case O, I -> xChange = 0;
|
|
||||||
case null, default -> xChange = -0.5;
|
|
||||||
}
|
|
||||||
tetromino.setPosition(this.nextPosition.sub(xChange, 4*this.nextTetrominoes.indexOf(tetromino), 0));
|
tetromino.setPosition(this.nextPosition.sub(xChange, 4*this.nextTetrominoes.indexOf(tetromino), 0));
|
||||||
tetromino.drawAsEntities();
|
tetromino.drawAsEntities();
|
||||||
});
|
});
|
||||||
@ -131,7 +130,7 @@ public class TetrisGame {
|
|||||||
return this.score;
|
return this.score;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateOtherTetrisGames(List<TetrisGame> tetrisGames) {
|
public void updateOtherTetrisGames(Collection<TetrisGame> tetrisGames) {
|
||||||
List<TetrisGame> games = new ArrayList<>(tetrisGames);
|
List<TetrisGame> games = new ArrayList<>(tetrisGames);
|
||||||
games.remove(this);
|
games.remove(this);
|
||||||
games.removeIf(tetrisGame -> tetrisGame.lost);
|
games.removeIf(tetrisGame -> tetrisGame.lost);
|
||||||
@ -151,23 +150,7 @@ public class TetrisGame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private boolean rotate(boolean clockwise) {
|
|
||||||
if(this.lost || this.paused) return false;
|
|
||||||
return this.currentTetromino.rotate(clockwise);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean moveLeft() {
|
|
||||||
if(this.lost || this.paused) return false;
|
|
||||||
return this.currentTetromino.moveLeft();
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean moveRight() {
|
|
||||||
if(this.lost || this.paused) return false;
|
|
||||||
return this.currentTetromino.moveRight();
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean moveDown() {
|
private boolean moveDown() {
|
||||||
if(this.lost || this.paused) return false;
|
|
||||||
if(!this.currentTetromino.moveDown()) {
|
if(!this.currentTetromino.moveDown()) {
|
||||||
this.setActiveTetrominoDown();
|
this.setActiveTetrominoDown();
|
||||||
return false;
|
return false;
|
||||||
@ -178,7 +161,6 @@ public class TetrisGame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean hardDrop() {
|
private boolean hardDrop() {
|
||||||
if(this.lost || this.paused) return false;
|
|
||||||
if(!this.currentTetromino.moveDown()) {
|
if(!this.currentTetromino.moveDown()) {
|
||||||
this.setActiveTetrominoDown();
|
this.setActiveTetrominoDown();
|
||||||
return false;
|
return false;
|
||||||
@ -195,7 +177,6 @@ public class TetrisGame {
|
|||||||
|
|
||||||
private boolean switchHold() {
|
private boolean switchHold() {
|
||||||
if(!holdPossible) return false;
|
if(!holdPossible) return false;
|
||||||
if(this.lost || this.paused) return false;
|
|
||||||
|
|
||||||
Tetromino newCurrentTetromino;
|
Tetromino newCurrentTetromino;
|
||||||
if(this.holdTetromino == null) {
|
if(this.holdTetromino == null) {
|
||||||
@ -208,18 +189,14 @@ public class TetrisGame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.currentTetromino.remove();
|
this.currentTetromino.remove();
|
||||||
this.holdTetromino = new Tetromino(this.instance, this.currentTetromino.shape);
|
this.holdTetromino = new Tetromino(this.instance, this.currentTetromino.getShape());
|
||||||
this.currentTetromino = newCurrentTetromino;
|
this.currentTetromino = newCurrentTetromino;
|
||||||
|
|
||||||
this.currentTetromino.setPosition(this.tetrominoSpawnPosition);
|
this.currentTetromino.setPosition(this.tetrominoSpawnPosition);
|
||||||
this.currentTetromino.draw();
|
this.currentTetromino.draw();
|
||||||
if(!this.currentTetromino.moveDown()) loose();
|
if(!this.currentTetromino.moveDown()) loose();
|
||||||
|
|
||||||
double xChange;
|
double xChange = this.holdTetromino.getXChange();
|
||||||
switch (this.holdTetromino.shape) {
|
|
||||||
case O, I -> xChange = 0;
|
|
||||||
case null, default -> xChange = 0.5;
|
|
||||||
}
|
|
||||||
this.holdTetromino.setPosition(this.holdPosition.add(xChange, 0, 0));
|
this.holdTetromino.setPosition(this.holdPosition.add(xChange, 0, 0));
|
||||||
this.holdTetromino.drawAsEntities();
|
this.holdTetromino.drawAsEntities();
|
||||||
this.holdPossible = false;
|
this.holdPossible = false;
|
||||||
@ -239,11 +216,7 @@ public class TetrisGame {
|
|||||||
Tetromino newTetromino = this.tetrominoBag.removeFirst();
|
Tetromino newTetromino = this.tetrominoBag.removeFirst();
|
||||||
this.nextTetrominoes.add(newTetromino);
|
this.nextTetrominoes.add(newTetromino);
|
||||||
this.nextTetrominoes.forEach(tetromino -> {
|
this.nextTetrominoes.forEach(tetromino -> {
|
||||||
double xChange;
|
double xChange = -tetromino.getXChange();
|
||||||
switch (tetromino.shape) {
|
|
||||||
case O, I -> xChange = 0;
|
|
||||||
case null, default -> xChange = -0.5;
|
|
||||||
}
|
|
||||||
tetromino.setPosition(this.nextPosition.sub(xChange, 4*this.nextTetrominoes.indexOf(tetromino), 0));
|
tetromino.setPosition(this.nextPosition.sub(xChange, 4*this.nextTetrominoes.indexOf(tetromino), 0));
|
||||||
tetromino.drawAsEntities();
|
tetromino.drawAsEntities();
|
||||||
});
|
});
|
||||||
|
@ -14,7 +14,7 @@ import java.util.List;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class Tetromino {
|
public class Tetromino {
|
||||||
public final Shape shape;
|
private final Shape shape;
|
||||||
private final StatelessGame instance;
|
private final StatelessGame instance;
|
||||||
private Pos position;
|
private Pos position;
|
||||||
private int[][] shapeArray;
|
private int[][] shapeArray;
|
||||||
@ -90,12 +90,10 @@ public class Tetromino {
|
|||||||
getBlockPositions().forEach(pos -> {
|
getBlockPositions().forEach(pos -> {
|
||||||
Entity ghostBlock = new Entity(ghostEntityType);
|
Entity ghostBlock = new Entity(ghostEntityType);
|
||||||
((FallingBlockMeta) ghostBlock.getEntityMeta()).setBlock(this.getGhostBlock());
|
((FallingBlockMeta) ghostBlock.getEntityMeta()).setBlock(this.getGhostBlock());
|
||||||
// ((BlockDisplayMeta) ghostBlock.getEntityMeta()).setBlockState(this.getGhostBlock());
|
|
||||||
ghostBlock.setNoGravity(true);
|
ghostBlock.setNoGravity(true);
|
||||||
ghostBlock.setGlowing(true);
|
ghostBlock.setGlowing(true);
|
||||||
ghostBlock.setTag(uuidTag, this.uuid.toString());
|
ghostBlock.setTag(uuidTag, this.uuid.toString());
|
||||||
ghostBlock.setInstance(this.instance, pos.sub(positionChange).add(0.5, 0, 0.5));
|
ghostBlock.setInstance(this.instance, pos.sub(positionChange).add(0.5, 0, 0.5));
|
||||||
// ghostBlock.setInstance(this.instance, pos.sub(positionChange).add(1, 0, 1));
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,11 +104,9 @@ public class Tetromino {
|
|||||||
getBlockPositions().forEach(pos -> {
|
getBlockPositions().forEach(pos -> {
|
||||||
Entity ghostBlock = new Entity(ghostEntityType);
|
Entity ghostBlock = new Entity(ghostEntityType);
|
||||||
((FallingBlockMeta) ghostBlock.getEntityMeta()).setBlock(this.getColoredBlock());
|
((FallingBlockMeta) ghostBlock.getEntityMeta()).setBlock(this.getColoredBlock());
|
||||||
// ((BlockDisplayMeta) ghostBlock.getEntityMeta()).setBlockState(this.getGhostBlock());
|
|
||||||
ghostBlock.setNoGravity(true);
|
ghostBlock.setNoGravity(true);
|
||||||
ghostBlock.setTag(uuidTag, this.uuid.toString());
|
ghostBlock.setTag(uuidTag, this.uuid.toString());
|
||||||
ghostBlock.setInstance(this.instance, pos.add(0.5, 0, 0.5));
|
ghostBlock.setInstance(this.instance, pos.add(0.5, 0, 0.5));
|
||||||
// ghostBlock.setInstance(this.instance, pos.sub(positionChange).add(1, 0, 1));
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,12 +134,27 @@ public class Tetromino {
|
|||||||
this.instance.getEntities().stream()
|
this.instance.getEntities().stream()
|
||||||
.filter(entity -> {
|
.filter(entity -> {
|
||||||
String tagValue = entity.getTag(uuidTag);
|
String tagValue = entity.getTag(uuidTag);
|
||||||
if(tagValue != null) return entity.getTag(uuidTag).equals(this.uuid.toString());
|
if(tagValue == null) return false;
|
||||||
return false;
|
return entity.getTag(uuidTag).equals(this.uuid.toString());
|
||||||
})
|
})
|
||||||
.forEach(Entity::remove);
|
.forEach(Entity::remove);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public double getXChange() {
|
||||||
|
switch (this.shape) {
|
||||||
|
case O, I -> {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
case null, default -> {
|
||||||
|
return 0.5;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Shape getShape() {
|
||||||
|
return this.shape;
|
||||||
|
}
|
||||||
|
|
||||||
private Block getGhostBlock() {
|
private Block getGhostBlock() {
|
||||||
Block returnBlock;
|
Block returnBlock;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user