nicole
This commit is contained in:
parent
45b49327e3
commit
d3f6fceb6a
3 changed files with 35 additions and 13 deletions
|
|
@ -5,6 +5,7 @@ import com.epita.creeps.given.vo.geometry.Direction;
|
||||||
import com.epita.creeps.given.vo.geometry.Point;
|
import com.epita.creeps.given.vo.geometry.Point;
|
||||||
import com.epita.creeps.given.vo.response.CommandResponse;
|
import com.epita.creeps.given.vo.response.CommandResponse;
|
||||||
import com.epita.creeps.given.vo.response.InitResponse;
|
import com.epita.creeps.given.vo.response.InitResponse;
|
||||||
|
import com.epita.creeps.given.vo.response.StatisticsResponse;
|
||||||
import com.epita.creeps.units.Building;
|
import com.epita.creeps.units.Building;
|
||||||
import com.epita.creeps.units.Citizen;
|
import com.epita.creeps.units.Citizen;
|
||||||
import com.epita.creeps.units.Turret;
|
import com.epita.creeps.units.Turret;
|
||||||
|
|
@ -75,22 +76,28 @@ public class Program {
|
||||||
Unit.getUnits().add(citizen1);
|
Unit.getUnits().add(citizen1);
|
||||||
Unit.getUnits().add(citizen2);
|
Unit.getUnits().add(citizen2);
|
||||||
|
|
||||||
citizen1.move(Direction.UP).waitFinished();
|
StatisticsResponse statistics = Basics.getStatistics();
|
||||||
|
logger.debug(statistics.toString());
|
||||||
|
|
||||||
|
while (true) {
|
||||||
citizen1.fetchMessages();
|
for (var player : statistics.players) {
|
||||||
citizen2.move(Direction.UP);
|
if (player.name == login)
|
||||||
|
continue;
|
||||||
|
citizen1.sendMessage(player.name, "Nicole");
|
||||||
|
citizen2.sendMessage(player.name,"Ouvre");
|
||||||
citizen1.waitFinished();
|
citizen1.waitFinished();
|
||||||
citizen2.waitFinished();
|
citizen2.waitFinished();
|
||||||
|
citizen1.sendMessage(player.name, "Nicole");
|
||||||
citizen2.spawn("turret");
|
citizen2.sendMessage(player.name, "MAIS MOI JE VEUX FAIRE L'AMOUUUUR");
|
||||||
citizen1.move(Direction.RIGHT);
|
|
||||||
citizen1.waitFinished();
|
citizen1.waitFinished();
|
||||||
citizen2.waitFinished();
|
citizen2.waitFinished();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
List<Unit> turrets = Turret.getTurretUnits();
|
|
||||||
Turret t = (Turret) turrets.getFirst();
|
|
||||||
t.fire(t.getPosition().plus(new Point(4, 0))).waitFinished();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import com.epita.creeps.given.extra.Cartographer;
|
||||||
import com.epita.creeps.given.json.Json;
|
import com.epita.creeps.given.json.Json;
|
||||||
import com.epita.creeps.given.vo.report.*;
|
import com.epita.creeps.given.vo.report.*;
|
||||||
import com.epita.creeps.given.vo.response.InitResponse;
|
import com.epita.creeps.given.vo.response.InitResponse;
|
||||||
|
import com.epita.creeps.given.vo.response.StatisticsResponse;
|
||||||
import com.epita.creeps.units.Turret;
|
import com.epita.creeps.units.Turret;
|
||||||
import com.epita.creeps.units.Unit;
|
import com.epita.creeps.units.Unit;
|
||||||
import kong.unirest.core.HttpResponse;
|
import kong.unirest.core.HttpResponse;
|
||||||
|
|
@ -50,6 +51,18 @@ public class Basics {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static StatisticsResponse getStatistics() {
|
||||||
|
try {
|
||||||
|
CompletableFuture<HttpResponse<JsonNode>> resp = AsyncExec.asyncExec(() -> Unirest.get(srvUrl + "/statistics").asJson(), 0);
|
||||||
|
HttpResponse<JsonNode> response = resp.join();
|
||||||
|
return Json.parse(response.getBody().toString(), StatisticsResponse.class);
|
||||||
|
} catch (UnirestException e) {
|
||||||
|
logger.error("Cannot retrieve statistics.");
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Asks the server for a certain report
|
// Asks the server for a certain report
|
||||||
public static Report getReport (String reportId) {
|
public static Report getReport (String reportId) {
|
||||||
HttpResponse<JsonNode> response = null;
|
HttpResponse<JsonNode> response = null;
|
||||||
|
|
|
||||||
|
|
@ -98,8 +98,10 @@ public abstract class Unit {
|
||||||
}
|
}
|
||||||
return AsyncExec.thenAsyncExec(pendingAction, x -> {
|
return AsyncExec.thenAsyncExec(pendingAction, x -> {
|
||||||
CommandResponse cr = Json.parse(x.getBody().toString(), CommandResponse.class);
|
CommandResponse cr = Json.parse(x.getBody().toString(), CommandResponse.class);
|
||||||
if (cr.error != null)
|
if (cr.error != null) {
|
||||||
|
logger.debug("Server reponse: " + cr.toString());
|
||||||
throw new ServerReponseException("Error retrieving the report id");
|
throw new ServerReponseException("Error retrieving the report id");
|
||||||
|
}
|
||||||
String reportId = cr.reportId;
|
String reportId = cr.reportId;
|
||||||
return Basics.getReport(reportId);
|
return Basics.getReport(reportId);
|
||||||
}, 0);
|
}, 0);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue