-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRMIClient43.java
163 lines (133 loc) · 5.49 KB
/
RMIClient43.java
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
152
153
154
155
156
157
158
159
160
161
162
163
//package RMI;
/*
* RMIClient43.java
*
* Version: 1.1
*
*/
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.Scanner;
/**
* RMIClient43 is the Client.
*
* @author Shweta Yakkali
* @author Aishwarya Desai
*/
public class RMIClient43 extends UnicastRemoteObject {
static ServerInterface4 stub;
StringBuffer dashes;
String guesses = "";
Scanner scanner = new Scanner(System.in);
Boolean done = false;
char letter = ' ';
String wordselected;
int score = 0;
String scoring;
int chances = 8;
String result;
public RMIClient43() throws RemoteException, NotBoundException, MalformedURLException, FileNotFoundException {
super();
stub = (ServerInterface4) Naming.lookup("rmi://localhost:5000/RMIServer4");
wordselected = stub.displayword();
}
int clientid;
static Boolean flag = false;
public RMIClient43(int clientid) throws RemoteException {
this.clientid = clientid;
}
static int ctr = 0;
/**
* The main method.
*
* @param args command line arguments (ignored)
*/
public static void main(String args[]) throws NotBoundException, MalformedURLException, RemoteException, FileNotFoundException, IOException {
//ServerInterface stub = (ServerInterface) Naming.lookup("rmi://localhost:5000/RMIServer");
RMIClient43 client = new RMIClient43();
System.out.println("Client3 Conected \n ");
String serverOutput;
serverOutput = stub.counterCheck(3);
if (serverOutput.contains("Start ")) {
client.clientmethod();
} else {
System.out.println("wait for your turn");
}
//System.out.println("client2 here!");
System.exit(0);
}
/**
* The clientmethod contains the client logic.
*
*/
public void clientmethod() {
try {
while (!done) {
dashes = stub.makeDashes(wordselected);
while (!done) {
System.out.println("Here is your word :" + dashes);
guesses = stub.displayguesses(guesses);
System.out.println("Guesses so far :" + stub.displayguesses(guesses));
System.out.println("Enter a letter : ");
String guess = scanner.next();
if (guess.length() < 1) { // user can give only one character at a time.
done = stub.checkwithwordselected(guess);
if (done == true) {
System.out.println("You Win!");
} else {
System.out.println("\n you lose!");
}
} else {
letter = guess.charAt(0);
scoring = stub.goodbadguesscheck(letter, guesses, dashes);
System.out.println(stub.goodbadguesscheck(letter, guesses, dashes));
if (scoring.contains("good ")) {
score = score + 10;
dashes = stub.returndashes(dashes);
System.out.println("if dashes " + dashes);
} else {
--chances;
score = score - 5;
//dashes = stub.returndashes2(dashes);
System.out.println("else dashes " + dashes);
}
System.out.println(" Score is :" + score);
//dashes = stub.returndashes2(dashes);
chances = stub.displaychances(chances);
System.out.println(" Chances left are :" + chances);
if (chances == 0) { // due to incorrect guesses chances over
System.out.println(stub.scoreandword());
done = true; // terminates the while loop
}
if (stub.wonthegame(dashes)) {
System.out.println(stub.returnscore() + score);
done = stub.returndone();
}
}
guesses = guesses + letter;
}
break;
}
System.out.println("Final score of Player 3 is:" + " " + score);
int ctr = stub.putscore(score, 3);
System.out.println("waiting for other players to finish");
while (ctr != 4) {
//System.out.println(ctr+" ctr value in client2");
ctr = stub.putscore(score, 3);
}
if (ctr == 4) {
System.out.println("enter if");
String display = stub.comparescore();
System.out.println("winner is Player: " + display);
}
} catch (Exception e) {
//System.out.println()
e.printStackTrace();
}
}
}