Skip to content
Snippets Groups Projects
Commit 5d355e2e authored by Stefano Grisendi's avatar Stefano Grisendi
Browse files

small changes to lobby creation

parent 902009c8
No related branches found
No related tags found
1 merge request!8Dev
Showing
with 54 additions and 18 deletions
...@@ -19,13 +19,13 @@ public class NetworkController { ...@@ -19,13 +19,13 @@ public class NetworkController {
private Kryo kryo; private Kryo kryo;
private Queue<Command> commandQueue; private Queue<Command> commandQueue;
private boolean devMode = true; private boolean devMode = false;
public NetworkController(){ public NetworkController(){
this.client = new Client(); this.client = new Client();
client.start(); client.start();
try { try {
String IP4_LAN_ADDRESS = "192.168.87.20"; String IP4_LAN_ADDRESS = "192.168.10.154";
client.connect(10000, IP4_LAN_ADDRESS, 54555, 54777); client.connect(10000, IP4_LAN_ADDRESS, 54555, 54777);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
......
...@@ -15,7 +15,6 @@ public class PlayerController { ...@@ -15,7 +15,6 @@ public class PlayerController {
private Lobby lobby; //Current lobby private Lobby lobby; //Current lobby
private ArrayList<Lobby> lobbies; //List of all lobbies private ArrayList<Lobby> lobbies; //List of all lobbies
private String playerName; // NB..! THIS IS TEMPORARY.. SHOULD BE IN MODEL.. private String playerName; // NB..! THIS IS TEMPORARY.. SHOULD BE IN MODEL..
public PlayerController(NetworkController networkController){ public PlayerController(NetworkController networkController){
...@@ -32,6 +31,7 @@ public class PlayerController { ...@@ -32,6 +31,7 @@ public class PlayerController {
}); });
net.sendToServer(new cPlayerJoin()); net.sendToServer(new cPlayerJoin());
net.sendToServer(new cLobbyCreate("test",4));
} }
...@@ -49,15 +49,11 @@ public class PlayerController { ...@@ -49,15 +49,11 @@ public class PlayerController {
// UpdatePlayerName code // UpdatePlayerName code
} }
public String getPlayerName(){
return this.playerName;
}
public void joinLobby(int id){ net.sendToServer(new cLobbyJoin(id)); } public void joinLobby(int id){ net.sendToServer(new cLobbyJoin(id)); }
public void lobbyGetList(){ net.sendToServer(new cLobbyGetList()); } public void lobbyGetList(){ net.sendToServer(new cLobbyGetList()); }
public void createLobby(int MAX_PLAYERS){ net.sendToServer(new cLobbyCreate(MAX_PLAYERS)); } public void createLobby(String name, int MAX_PLAYERS){ net.sendToServer(new cLobbyCreate(name, MAX_PLAYERS)); }
public void deleteLobby(int id){ net.sendToServer(new cLobbyDelete(id)); } public void deleteLobby(int id){ net.sendToServer(new cLobbyDelete(id)); }
...@@ -67,6 +63,10 @@ public class PlayerController { ...@@ -67,6 +63,10 @@ public class PlayerController {
public Player getPlayer(){ return player; } public Player getPlayer(){ return player; }
public String getPlayerName(){
return this.playerName;
}
public void setPlayer(Player player){ this.player = player; } public void setPlayer(Player player){ this.player = player; }
public void setLobby(Lobby lobby){ this.lobby = lobby; } public void setLobby(Lobby lobby){ this.lobby = lobby; }
......
...@@ -4,11 +4,19 @@ import com.esotericsoftware.kryonet.Connection; ...@@ -4,11 +4,19 @@ import com.esotericsoftware.kryonet.Connection;
import com.mygdx.game.controllers.PlayerController; import com.mygdx.game.controllers.PlayerController;
import com.mygdx.game.model.Lobby; import com.mygdx.game.model.Lobby;
import java.util.ArrayList;
public class cLobbyCreate extends Command { public class cLobbyCreate extends Command {
public cLobbyCreate() { super("cLobbyCreate"); } public cLobbyCreate() { super("cLobbyCreate"); }
public cLobbyCreate(int MAX_PLAYERS) { super("cLobbyCreate", (Integer) MAX_PLAYERS); } public cLobbyCreate(String name, int MAX_PLAYERS) {
super("cLobbyCreate");
ArrayList<Object> data = new ArrayList<Object>();
data.add(name);
data.add(MAX_PLAYERS);
this.data = data;
}
@Override @Override
public void execute(PlayerController playerController, Connection connection){ public void execute(PlayerController playerController, Connection connection){
......
...@@ -5,6 +5,7 @@ import java.util.ArrayList; ...@@ -5,6 +5,7 @@ import java.util.ArrayList;
public class Lobby { public class Lobby {
private int ID; private int ID;
private String name;
private int MAX_PLAYERS; private int MAX_PLAYERS;
private ArrayList<Player> players; private ArrayList<Player> players;
...@@ -15,14 +16,17 @@ public class Lobby { ...@@ -15,14 +16,17 @@ public class Lobby {
players = new ArrayList<Player>(); players = new ArrayList<Player>();
} }
public Lobby(int ID, int MAX_PLAYERS){ public Lobby(int ID, String name, int MAX_PLAYERS){
this.ID = ID; this.ID = ID;
this.name = name;
this.MAX_PLAYERS = MAX_PLAYERS; this.MAX_PLAYERS = MAX_PLAYERS;
players = new ArrayList<Player>(); players = new ArrayList<Player>();
} }
public int getID(){ return ID; } public int getID(){ return ID; }
public String getName(){ return name; }
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;
...@@ -35,9 +39,9 @@ public class Lobby { ...@@ -35,9 +39,9 @@ public class Lobby {
public String toString() { public String toString() {
return "Lobby{" + return "Lobby{" +
"ID=" + ID + "ID=" + ID +
", name='" + name + '\'' +
", MAX_PLAYERS=" + MAX_PLAYERS + ", MAX_PLAYERS=" + MAX_PLAYERS +
", players=" + players + ", players=" + players +
'}'; '}';
} }
} }
No preview for this file type
<component name="libraryTable">
<library name="Gradle: CheckersServer.core.core-1.0">
<CLASSES>
<root url="jar://$PROJECT_DIR$/core/build/libs/core-1.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="Gradle: CheckersServer.desktop.desktop-1.0">
<CLASSES>
<root url="jar://$PROJECT_DIR$/desktop/build/libs/desktop-1.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>
\ No newline at end of file
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<project version="4"> <project version="4">
<component name="ProjectModuleManager"> <component name="ProjectModuleManager">
<modules> <modules>
<module fileurl="file://$PROJECT_DIR$/.idea/CheckersServer.iml" filepath="$PROJECT_DIR$/.idea/CheckersServer.iml" /> <module fileurl="file://$PROJECT_DIR$/.idea/modules/CheckersServer.iml" filepath="$PROJECT_DIR$/.idea/modules/CheckersServer.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/modules/android/CheckersServer.android.iml" filepath="$PROJECT_DIR$/.idea/modules/android/CheckersServer.android.iml" /> <module fileurl="file://$PROJECT_DIR$/.idea/modules/android/CheckersServer.android.iml" filepath="$PROJECT_DIR$/.idea/modules/android/CheckersServer.android.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/modules/core/CheckersServer.core.iml" filepath="$PROJECT_DIR$/.idea/modules/core/CheckersServer.core.iml" /> <module fileurl="file://$PROJECT_DIR$/.idea/modules/core/CheckersServer.core.iml" filepath="$PROJECT_DIR$/.idea/modules/core/CheckersServer.core.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/modules/desktop/CheckersServer.desktop.iml" filepath="$PROJECT_DIR$/.idea/modules/desktop/CheckersServer.desktop.iml" /> <module fileurl="file://$PROJECT_DIR$/.idea/modules/desktop/CheckersServer.desktop.iml" filepath="$PROJECT_DIR$/.idea/modules/desktop/CheckersServer.desktop.iml" />
......
...@@ -66,10 +66,10 @@ public class NetworkController { ...@@ -66,10 +66,10 @@ public class NetworkController {
if (index!= -1) players.remove(index); if (index!= -1) players.remove(index);
} }
public Lobby createLobby(int MAX_PLAYERS){ public Lobby createLobby(String name, int MAX_PLAYERS){
if(lobbies.size() < MAX_LOBBIES){ if(lobbies.size() < MAX_LOBBIES){
lobby_id++; lobby_id++;
Lobby lobby = new Lobby(lobby_id, MAX_PLAYERS); Lobby lobby = new Lobby(lobby_id, name, MAX_PLAYERS);
lobbies.add(lobby); lobbies.add(lobby);
return lobby; return lobby;
} }
......
...@@ -6,6 +6,8 @@ import com.mygdx.game.controller.commands.Command; ...@@ -6,6 +6,8 @@ import com.mygdx.game.controller.commands.Command;
import com.mygdx.game.model.Lobby; import com.mygdx.game.model.Lobby;
import com.mygdx.game.model.Player; import com.mygdx.game.model.Player;
import java.util.ArrayList;
public class cLobbyCreate extends Command { public class cLobbyCreate extends Command {
public cLobbyCreate() { super("cLobbyCreate"); } public cLobbyCreate() { super("cLobbyCreate"); }
...@@ -14,9 +16,10 @@ public class cLobbyCreate extends Command { ...@@ -14,9 +16,10 @@ public class cLobbyCreate extends Command {
@Override @Override
public void execute(NetworkController net, Connection connection){ public void execute(NetworkController net, Connection connection){
if(data instanceof Integer){ if(data instanceof ArrayList){
int MAX_PLAYERS = (int) data; String name = (String) ((ArrayList) data).get(0);
data = net.createLobby(MAX_PLAYERS); int MAX_PLAYERS = (int) ((ArrayList) data).get(1);
data = net.createLobby(name, MAX_PLAYERS);
System.out.printf("Request to create lobby received. Returning Lobby w. ID: %d \n", ((Lobby)data).getID()); System.out.printf("Request to create lobby received. Returning Lobby w. ID: %d \n", ((Lobby)data).getID());
connection.sendTCP(this); connection.sendTCP(this);
} }
......
...@@ -6,6 +6,7 @@ import java.util.HashSet; ...@@ -6,6 +6,7 @@ import java.util.HashSet;
public class Lobby { public class Lobby {
private int ID; private int ID;
private String name;
private int MAX_PLAYERS; private int MAX_PLAYERS;
private ArrayList<Player> players; private ArrayList<Player> players;
...@@ -16,8 +17,9 @@ public class Lobby { ...@@ -16,8 +17,9 @@ public class Lobby {
players = new ArrayList<Player>(); players = new ArrayList<Player>();
} }
public Lobby(int ID, int MAX_PLAYERS){ public Lobby(int ID, String name, int MAX_PLAYERS){
this.ID = ID; this.ID = ID;
this.name = name;
this.MAX_PLAYERS = MAX_PLAYERS; this.MAX_PLAYERS = MAX_PLAYERS;
players = new ArrayList<Player>(); players = new ArrayList<Player>();
} }
...@@ -62,6 +64,7 @@ public class Lobby { ...@@ -62,6 +64,7 @@ public class Lobby {
public String toString() { public String toString() {
return "Lobby{" + return "Lobby{" +
"ID=" + ID + "ID=" + ID +
", name='" + name + '\'' +
", MAX_PLAYERS=" + MAX_PLAYERS + ", MAX_PLAYERS=" + MAX_PLAYERS +
", players=" + players + ", players=" + players +
'}'; '}';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment