feat: multi synced player scores
All checks were successful
Linux arm64 / Build (push) Successful in 31s
All checks were successful
Linux arm64 / Build (push) Successful in 31s
This commit is contained in:
@@ -7,7 +7,11 @@ import java.util.Random;
|
||||
import common.Signal;
|
||||
import game.Game;
|
||||
import game.Player;
|
||||
import network.protocol.packets.ChangeCellPacket;
|
||||
import network.protocol.packets.LoginPacket;
|
||||
import sudoku.structure.Cell;
|
||||
import sudoku.structure.MultiDoku;
|
||||
import sudoku.structure.Sudoku;
|
||||
|
||||
public class Client {
|
||||
private final ClientConnexion clientConnection;
|
||||
@@ -54,4 +58,16 @@ public class Client {
|
||||
stop();
|
||||
}
|
||||
|
||||
public void sendCellChange(Cell cell) {
|
||||
MultiDoku doku = getGame().getDoku();
|
||||
for (int sudokuIndex = 0; sudokuIndex < doku.getNbSubGrids(); sudokuIndex++) {
|
||||
Sudoku sudoku = doku.getSubGrid(sudokuIndex);
|
||||
int cellIndex = sudoku.getCells().indexOf(cell);
|
||||
if (cellIndex != -1) {
|
||||
this.clientConnection.sendPacket(new ChangeCellPacket(sudokuIndex, cellIndex, cell.getSymbolIndex()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,13 +6,16 @@ import java.net.UnknownHostException;
|
||||
|
||||
import game.Player;
|
||||
import network.Connexion;
|
||||
import network.protocol.packets.ChangeCellPacket;
|
||||
import network.protocol.packets.ConnexionInfoPacket;
|
||||
import network.protocol.packets.DisconnectPacket;
|
||||
import network.protocol.packets.EndGamePacket;
|
||||
import network.protocol.packets.KeepAlivePacket;
|
||||
import network.protocol.packets.LoginPacket;
|
||||
import network.protocol.packets.PlayerJoinPacket;
|
||||
import network.protocol.packets.PlayerLeavePacket;
|
||||
import network.protocol.packets.StartGamePacket;
|
||||
import network.protocol.packets.UpdatePlayerScorePacket;
|
||||
import sudoku.io.SudokuSerializer;
|
||||
|
||||
public class ClientConnexion extends Connexion {
|
||||
@@ -73,4 +76,23 @@ public class ClientConnexion extends Connexion {
|
||||
this.client.onGameStarted.emit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitPacket(EndGamePacket packet) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'visitPacket'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitPacket(UpdatePlayerScorePacket packet) {
|
||||
Player player = this.client.getGame().getPlayerById(packet.getPlayerId());
|
||||
assert(player != null);
|
||||
player.setScore(packet.getCellsLeft());
|
||||
System.out.println("Score for " + player.getPseudo() + " : " + packet.getCellsLeft());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitPacket(ChangeCellPacket packet) {
|
||||
throw new UnsupportedOperationException("Unimplemented method 'visitPacketChangeCell'");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user