This commit is contained in:
@@ -3,20 +3,45 @@ package network.client;
|
||||
import java.io.IOException;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import common.Signal;
|
||||
import game.Game;
|
||||
import game.Player;
|
||||
import network.protocol.packets.LoginPacket;
|
||||
|
||||
public class Client {
|
||||
private final ClientConnexion clientConnection;
|
||||
private final Game game;
|
||||
|
||||
public final Signal onConnect = new Signal();
|
||||
public final Signal onDisconnect = new Signal();
|
||||
public final Signal onClosed = new Signal();
|
||||
|
||||
public Client(String address, short port) throws UnknownHostException, IOException {
|
||||
this.clientConnection = new ClientConnexion(address, port, this);
|
||||
this.game = new Game();
|
||||
login("Player2" + Math.random());
|
||||
}
|
||||
|
||||
public void login(String pseudo) {
|
||||
System.out.println("Logging in with pseudo " + pseudo + " ...");
|
||||
this.clientConnection.sendPacket(new LoginPacket(pseudo));
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
this.clientConnection.close();
|
||||
}
|
||||
|
||||
public void onDisconnect() {
|
||||
// do some stuff
|
||||
System.out.println("OSEKOUR");
|
||||
public void addPlayer(Player player) {
|
||||
this.game.addPlayer(player);
|
||||
}
|
||||
|
||||
|
||||
public Game getGame() {
|
||||
return game;
|
||||
}
|
||||
|
||||
public void forceDisconnect() {
|
||||
this.onClosed.emit();
|
||||
stop();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user