-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGameServer.java
More file actions
33 lines (27 loc) · 877 Bytes
/
GameServer.java
File metadata and controls
33 lines (27 loc) · 877 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import java.io.FileNotFoundException;
import java.net.ServerSocket;
import java.net.Socket;
public class GameServer {
private static final int PORT = 9231;
public static void main(String[] args) throws Exception {
CardGame game;
try {
game = new CardGame("./src/start.txt");
}
catch(FileNotFoundException | InvalidGameParameterException e) {
System.err.println(e.getMessage());
return;
}
try (ServerSocket welcomeSocket = new ServerSocket(PORT);) {
System.out.println("Server waiting for players to connect\n");
int currentPlayers = 0;
int totalPlayers = game.getNumberOfPlayers();
while(currentPlayers < totalPlayers) {
Socket newPlayerSocket = welcomeSocket.accept();
game.addPlayer(newPlayerSocket);
++currentPlayers;
}
}
game.run();
}
}