-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClientThread.java
More file actions
151 lines (108 loc) · 3.16 KB
/
Copy pathClientThread.java
File metadata and controls
151 lines (108 loc) · 3.16 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
// class ClientThread extends Thread {
// private Socket socket;
// private int id;
// private char[] combination;
// private Writer out;
// private BufferedReader in;
// public ClientThread(Socket socket, int id, char[] combination) {
// this.socket = socket;
// this.id = id;
// this.combination = combination;
// }
// public void run() {
// try {
// manageRequest();
// } catch(UnknownHostException e) {
// System.out.println("Host desconocido");
// } catch(IOException e) {
// System.out.println("Juagador desconectado " + id);
// }
// }
// private void manageRequest() throws UnknownHostException, IOException {
// System.out.println("Tengo que adivinar: " + String.valueOf(combination));
// OutputStream outputStream = socket.getOutputStream();
// InputStreamReader inputStreamReader = new InputStreamReader(socket.getInputStream());
// out = new OutputStreamWriter(outputStream, "ASCII");
// in = new BufferedReader(inputStreamReader);
// if (!in.readLine().equals("JOIN_GAME")) {
// socket.close();
// }
// for (int i = 0; i < 15; i++) {
// // Espero turno
// while (Server.turn != id) {
// try {
// sleep(2000);
// } catch (InterruptedException e) {}
// }
// if (Server.someoneWon >= 0) {
// String msg = "LOSE\n" + Server.someoneWon + "\n";
// out.write(msg);
// out.flush();
// break;
// }
// String msg = "MOVE\nnull\n";
// out.write(msg);
// out.flush();
// String[] message = readClientRequest();
// chooseAction(message);
// Server.updateTurn();
// }
// }
// private String[] readClientRequest() {
// String action = null;
// String args = "null";
// try {
// while (action == null || action.length() < 1) {
// action = in.readLine();
// }
// args = in.readLine();
// } catch (IOException e) {
// System.out.println("No se ha podido leer");
// }
// return new String[] {action, args};
// }
// private void chooseAction(String[] message) {
// String action = message[0];
// String args = message[1];
// for (int i = 0; i < Server.actions.length; i++) {
// if (Server.actions[i].equals(action)) {
// switch (i) {
// case 0: // C_MOVES
// processClientMove(args);
// break;
// default:
// System.out.println("Invalid action");
// break;
// }
// return;
// }
// }
// System.out.println("Invalid action: " + action);
// }
// private void processClientMove(String move) {
// int black = 0;
// int white = 0;
// for (int i = 0; i < 4; i++) {
// if (move.charAt(i) == combination[i]) {
// black++;
// } else if (String.valueOf(combination).indexOf(move.charAt(i)) != -1) {
// white++;
// }
// }
// if (black == 4) { // CLIENTE GANA
// send("WIN\nGANASTE!!\n");
// Server.someoneWon = id;
// } else { // CLIENTE NO GANA
// String result = "B" + black + "W" + white;
// send("MOVE_RESPONSE\n" + result + "\n");
// }
// }
// private void send(String message) {
// try {
// out.write(message);
// out.flush();
// } catch (IOException e) {
// System.out.println("Error al enviar");
// }
// }
// }