-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRPSclient.java
More file actions
51 lines (47 loc) · 1.48 KB
/
Copy pathRPSclient.java
File metadata and controls
51 lines (47 loc) · 1.48 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
import java.io.*;
import java.net.*;
import java.util.*;
public class RPSclient
{
public static Socket socket = null;
public static void main(String[] args)
{
try
{
socket = new Socket("localhost", 8558);
System.out.println("Connected to Server\n");
}
catch (IOException ioEx)
{
System.out.println("Unable connect to host.\n");
System.exit(1);
}
String player,result;
BufferedReader in;
PrintWriter out;
Scanner input = new Scanner(System.in);
try
{
in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
out = new PrintWriter(socket.getOutputStream(), true);
int round=0;
while(round<5)
{
System.out.println("************ROUND "+(round+1)+"*************");
System.out.println("\nOptions: " + in.readLine());
System.out.print("Choice is: ");
out.println(input.nextLine());
player = in.readLine();
System.out.println("Round Winner: " + player+"\n");
round++;
out.println(round);
}
result=in.readLine();
System.out.println(result);
}
catch (IOException ioEx)
{
ioEx.printStackTrace();
}
}
}