Add: PING PONG TCP
This commit is contained in:
@@ -3,8 +3,8 @@ package it.polimi.ingsw.gc14;
|
||||
|
||||
import it.polimi.ingsw.gc14.Controller.GameController;
|
||||
import it.polimi.ingsw.gc14.Model.Game;
|
||||
import it.polimi.ingsw.gc14.Network.ClientPlayer;
|
||||
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||
import it.polimi.ingsw.gc14.Network.NetworkEvents.AddPlayer;
|
||||
import it.polimi.ingsw.gc14.Network.RMI.Server.RMIServer;
|
||||
import it.polimi.ingsw.gc14.Network.TCP.Server.TCPServer;
|
||||
import it.polimi.ingsw.gc14.View.TUI.TUI;
|
||||
@@ -21,10 +21,10 @@ import java.net.*;
|
||||
* The workflow is divided into two parts: game creation and game execution.
|
||||
* The process flow for game creation is as follows:
|
||||
* - The first client (TCP/RMI) requests to join the game by providing a username and the desired number of players
|
||||
* - The TCP/RMI server checks {@link #playerList} and, if it is empty, sets the number of players according to the first user's request using {@link LimitedList#setLimit(int)}
|
||||
* - The TCP/RMI server checks {@link #playerList} and, if it is empty, sets the number of players according to the first user's request using {@link LimitedMap#setLimit(int)}
|
||||
* - The TCP/RMI server creates the {@link Game} with the requested number of players and adds the player to {@link #playerList}
|
||||
* - Other players request to join the game (their requested number of players is ignored)
|
||||
* - When the number of players in {@link #playerList} reaches the {@link LimitedList}'s limit, the list calls {@link #run()}
|
||||
* - When the number of players in {@link #playerList} reaches the {@link LimitedMap}'s limit, the list calls {@link #run()}
|
||||
* - All players are notified of the {@link Game}
|
||||
*
|
||||
* The process flow for game execution is as follows:
|
||||
@@ -52,11 +52,11 @@ public class ServerLauncher {
|
||||
|
||||
/**
|
||||
* List containing the usernames of joined players.
|
||||
* {@link LimitedList}'s limit defines at which size the list calls its action
|
||||
* Both the limit and the action can be set using {@link LimitedList#setLimit(int)} and {@link LimitedList#setAction(Runnable)}
|
||||
* {@link LimitedMap}'s limit defines at which size the list calls its action
|
||||
* Both the limit and the action can be set using {@link LimitedMap#setLimit(int)} and {@link LimitedMap#setAction(Runnable)}
|
||||
* The limit is set by the first player joining the game. The action consists in calling {@link #run()}
|
||||
*/
|
||||
static LimitedList<String> playerList;
|
||||
static LimitedMap<String,Boolean> playerList;
|
||||
|
||||
TUI view;
|
||||
|
||||
@@ -105,7 +105,7 @@ public class ServerLauncher {
|
||||
* @throws RemoteException if this exception is issued by run method
|
||||
*/
|
||||
public static void main(String[] args) throws InterruptedException, RemoteException {
|
||||
playerList = new LimitedList<>(5, ()->{});
|
||||
playerList = new LimitedMap<String,Boolean>(5, ()->{});
|
||||
BlockingQueue<NetworkEvent> actionQueue = new LinkedBlockingQueue<>();
|
||||
GameController gameController = new GameController();
|
||||
String IP;
|
||||
@@ -116,7 +116,7 @@ public class ServerLauncher {
|
||||
}
|
||||
|
||||
RMIServer serverRMI = new RMIServer(gameController, 1099, actionQueue, playerList,IP);
|
||||
TCPServer serverTCP = new TCPServer(gameController, 8080, actionQueue, playerList);
|
||||
TCPServer serverTCP = new TCPServer(gameController, 8080, 8081,actionQueue, playerList);
|
||||
ServerLauncher launcher = new ServerLauncher(actionQueue, gameController, serverRMI, serverTCP);
|
||||
|
||||
playerList.setAction(()->{
|
||||
|
||||
Reference in New Issue
Block a user