Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.

Commit 8b8721a

Browse files
Added CLI
Added CLI and ViewInterface Refactored client messageParser Added Manifest for client jar Added resources
1 parent e23a717 commit 8b8721a

16 files changed

Lines changed: 859 additions & 188 deletions

File tree

src/main/java/it/polimi/ingsw/model/Game.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ public Game restoreState() throws IOException {
263263
int x, y;
264264
ObjectMapper objectMapper = new ObjectMapper();
265265
Game restoredGame = objectMapper.readerFor(Game.class).readValue(file);
266+
//FIXME: manage file path
266267
for (Player player : restoredGame.players) {
267268
/*for (Worker worker : player.getWorkers()) { //TODO: we should do the opposite, use the occupiedBy in cell to set the position in Worker
268269
x = worker.getPosition().getCoordX();

src/main/java/it/polimi/ingsw/model/dataClass/GodData.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ public String getDescriptionStrategy() {
3535
}
3636

3737

38-
3938
@Override
4039
public boolean equals(Object o) {
4140
if (this == o) return true;

src/main/java/it/polimi/ingsw/network/client/Client.java

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,36 @@
11
package it.polimi.ingsw.network.client;
22

33
import it.polimi.ingsw.network.message.Message;
4+
import it.polimi.ingsw.view.ViewInterface;
5+
import it.polimi.ingsw.view.cli.CLI;
46

7+
import javax.swing.text.View;
58
import java.io.IOException;
9+
import java.util.List;
610
import java.util.Scanner;
711

812
public class Client {
913
private String username;
10-
private final String ipAddress;
14+
private String ipAddress;
1115
private NetworkHandler networkHandler;
1216
private boolean currentPlayer;
17+
private ViewInterface view;
1318

14-
public static void main(String[] args) throws IOException {
15-
System.out.println("Choose username");
16-
Scanner in = new Scanner(System.in);
17-
String username = in.nextLine();
18-
String ip = "127.0.0.1"; // TODO: just for speed up socket testing, we will change this
19-
System.out.println("IP: " + ip);
20-
Client client = new Client(username, ip);
19+
public static void main(String[] args) {
20+
ViewInterface viewInterface;
21+
if(args.length == 0 || !args[0].equals("--GUI"))
22+
viewInterface = new CLI();
23+
else
24+
viewInterface = new CLI(); //FIXME: implement gui
25+
26+
List<String> loginData = viewInterface.loginScreen();
27+
Client client = new Client(loginData.get(1), loginData.get(0), viewInterface);
2128
client.startConnection();
2229
//TODO: Here I ask the user if he wants to use the Cli/Gui
2330
}
2431

25-
public Client(String username, String ipAddress) {
32+
public Client(String username, String ipAddress, ViewInterface viewInterface) {
33+
this.view = viewInterface;
2634
this.username = username;
2735
this.ipAddress = ipAddress;
2836
}
@@ -39,10 +47,18 @@ public void setCurrentPlayer(boolean currentPlayer) {
3947
this.currentPlayer = currentPlayer;
4048
}
4149

50+
public void setUsername(String username) {
51+
this.username = username;
52+
networkHandler.login(username);
53+
}
54+
public void setIpAddress(String ipAddress) {
55+
this.ipAddress = ipAddress;
56+
}
57+
4258
/*
4359
The view asks the user for his Username and IpAddress (we need this because of quarantine), then it'll call this method to start the connection
4460
*/
45-
public void startConnection() throws IOException {
61+
public void startConnection() {
4662
networkHandler = new NetworkHandler(this);
4763
new Thread(networkHandler).start();
4864
networkHandler.login(this.username);
@@ -53,17 +69,17 @@ public void sendMessage(Message message) { //View -> Client -> handler -> JsonPa
5369
networkHandler.sendMessage(message);
5470
}
5571

56-
public void setUsername(String username) {
57-
this.username = username;
58-
networkHandler.login(username);
59-
}
6072

6173
public void stopConnection() throws IOException {
6274
networkHandler.closeConnection();
6375
}
6476

77+
public ViewInterface getView() {
78+
return this.view;
79+
}
80+
6581
public synchronized void notify(Message message) { //These come from the server to the Client
66-
System.out.println("Message Received from server, message content is " + message.getContent());
82+
//System.out.println("Message Received from server, message content is " + message.getContent());
6783
//TODO: We could have another message parser class instead of a method, here the client will call methods of the view to display the info inside the message (errors, gameboard, etc)
6884
}
6985
}

0 commit comments

Comments
 (0)