- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNetworkClientB.java
More file actions
Latest commit
111 lines (91 loc) · 2.67 KB
/
Copy pathNetworkClientB.java
File metadata and controls
111 lines (91 loc) · 2.67 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
importjava.rmi.RemoteException;
importjava.rmi.registry.LocateRegistry;
importjava.rmi.registry.Registry;
importjava.rmi.server.UnicastRemoteObject;
importjava.util.Scanner;
importedu.uab.cs203.Objectmon;
importedu.uab.cs203.Team;
importedu.uab.cs203.effects.StatusEffect;
importedu.uab.cs203.lab05.BasicTeam;
importedu.uab.cs203.lab09.Hashmon;
importedu.uab.cs203.network.GymClient;
importedu.uab.cs203.network.GymServer;
publicclassNetworkClientBextendsUnicastRemoteObjectimplementsGymClient {
/**
*
*/
privatestaticfinallongserialVersionUID = 1L;
privateTeam<Objectmon> team;
privatestaticScannerscan;
protectedNetworkClientB() throwsRemoteException {
this.team = newBasicTeam<>();
}
publicTeam<Objectmon> getTeam() throwsRemoteException {
returnteam;
}
publicObjectmonnetworkApplyDamage(Objectmonfrom, Objectmonto, intdamage)
throwsRemoteException {
for (Objectmonobj : getTeam()) {
if (to.equals(obj)) {
obj.setHp(obj.getHp() - damage);
returnobj;
}
}
returnnull;
}
publicvoidnetworkTick() throwsRemoteException {
Team<Objectmon> team = getTeam();
for (Objectmonitem : team) {
item.tick();
}
}
publicObjectmonnextObjectmon() throwsRemoteException {
for (Objectmonitem : team) {
if (!item.isFainted()) {
returnitem;
}
}
returnnull;
}
publicvoidprintMessage(Stringarg0) throwsRemoteException {
System.out.println(arg0);
}
@SuppressWarnings({ "rawtypes", "unchecked" })
publicvoidsetTeam(Teamteam) throwsRemoteException {
this.team = team;
}
publicstaticvoidmain(String[] args) throwsException {
GymClientclientB = newNetworkClientB();
GymServerserver = newNetworkServer();
StringfilePath = "objectdex_01.txt";
Hashmon.loadObjectdex(filePath);
Hashmonomon1 = newHashmon("hawlucha");
Hashmonomon2 = newHashmon("cacturne");
Hashmonomon3 = newHashmon("carnivine");
Team<Hashmon> teamB = newBasicTeam<>("Team B", 3);
teamB.add(omon1);
teamB.add(omon2);
teamB.add(omon3);
clientB.setTeam(teamB);
try {
Runtime.getRuntime().exec("rmiregistry 10003");
Registryregistry3 = LocateRegistry.createRegistry(10003);
registry3.bind("GymClientB", clientB);
RegistryremoteRegistry = LocateRegistry.getRegistry("localhost",
10001); // Client to Server
server = (GymServer) remoteRegistry.lookup("NetworkServer");
server.registerClientB("localhost", 10003, "GymClientB");
} catch (Exceptione) {
e.printStackTrace();
}
scan = newScanner(System.in);
while (true) {
Stringmsg = scan.nextLine();
if (msg.equals("y")) {
server.setTeamBReady(true);
} else {
server.setTeamBReady(false);
}
}
}
}