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
Branches
No related tags found
1 merge request!8Dev
Showing
with 54 additions and 18 deletions
......@@ -19,13 +19,13 @@ public class NetworkController {
private Kryo kryo;
private Queue<Command> commandQueue;
private boolean devMode = true;
private boolean devMode = false;
public NetworkController(){
this.client = new Client();
client.start();
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);
} catch (IOException e) {
e.printStackTrace();
......
......@@ -15,7 +15,6 @@ public class PlayerController {
private Lobby lobby; //Current lobby
private ArrayList<Lobby> lobbies; //List of all lobbies
private String playerName; // NB..! THIS IS TEMPORARY.. SHOULD BE IN MODEL..
public PlayerController(NetworkController networkController){
......@@ -32,6 +31,7 @@ public class PlayerController {
});
net.sendToServer(new cPlayerJoin());
net.sendToServer(new cLobbyCreate("test",4));
}
......@@ -49,15 +49,11 @@ public class PlayerController {
// UpdatePlayerName code
}
public String getPlayerName(){
return this.playerName;
}
public void joinLobby(int id){ net.sendToServer(new cLobbyJoin(id)); }
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)); }
......@@ -67,6 +63,10 @@ public class PlayerController {
public Player getPlayer(){ return player; }
public String getPlayerName(){
return this.playerName;
}
public void setPlayer(Player player){ this.player = player; }
public void setLobby(Lobby lobby){ this.lobby = lobby; }
......
......@@ -4,11 +4,19 @@ import com.esotericsoftware.kryonet.Connection;
import com.mygdx.game.controllers.PlayerController;
import com.mygdx.game.model.Lobby;
import java.util.ArrayList;
public class cLobbyCreate extends Command {
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
public void execute(PlayerController playerController, Connection connection){
......
......@@ -5,6 +5,7 @@ import java.util.ArrayList;
public class Lobby {
private int ID;
private String name;
private int MAX_PLAYERS;
private ArrayList<Player> players;
......@@ -15,14 +16,17 @@ public class Lobby {
players = new ArrayList<Player>();
}
public Lobby(int ID, int MAX_PLAYERS){
public Lobby(int ID, String name, int MAX_PLAYERS){
this.ID = ID;
this.name = name;
this.MAX_PLAYERS = MAX_PLAYERS;
players = new ArrayList<Player>();
}
public int getID(){ return ID; }
public String getName(){ return name; }
@Override
public boolean equals(Object o) {
if (this == o) return true;
......@@ -35,9 +39,9 @@ public class Lobby {
public String toString() {
return "Lobby{" +
"ID=" + ID +
", name='" + name + '\'' +
", MAX_PLAYERS=" + MAX_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 @@
<project version="4">
<component name="ProjectModuleManager">
<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/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" />
......
......@@ -66,10 +66,10 @@ public class NetworkController {
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){
lobby_id++;
Lobby lobby = new Lobby(lobby_id, MAX_PLAYERS);
Lobby lobby = new Lobby(lobby_id, name, MAX_PLAYERS);
lobbies.add(lobby);
return lobby;
}
......
......@@ -6,6 +6,8 @@ import com.mygdx.game.controller.commands.Command;
import com.mygdx.game.model.Lobby;
import com.mygdx.game.model.Player;
import java.util.ArrayList;
public class cLobbyCreate extends Command {
public cLobbyCreate() { super("cLobbyCreate"); }
......@@ -14,9 +16,10 @@ public class cLobbyCreate extends Command {
@Override
public void execute(NetworkController net, Connection connection){
if(data instanceof Integer){
int MAX_PLAYERS = (int) data;
data = net.createLobby(MAX_PLAYERS);
if(data instanceof ArrayList){
String name = (String) ((ArrayList) data).get(0);
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());
connection.sendTCP(this);
}
......
......@@ -6,6 +6,7 @@ import java.util.HashSet;
public class Lobby {
private int ID;
private String name;
private int MAX_PLAYERS;
private ArrayList<Player> players;
......@@ -16,8 +17,9 @@ public class Lobby {
players = new ArrayList<Player>();
}
public Lobby(int ID, int MAX_PLAYERS){
public Lobby(int ID, String name, int MAX_PLAYERS){
this.ID = ID;
this.name = name;
this.MAX_PLAYERS = MAX_PLAYERS;
players = new ArrayList<Player>();
}
......@@ -62,6 +64,7 @@ public class Lobby {
public String toString() {
return "Lobby{" +
"ID=" + ID +
", name='" + name + '\'' +
", MAX_PLAYERS=" + MAX_PLAYERS +
", players=" + players +
'}';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment