/** Connect a new user on the server */ @RequestMapping("/connect/{name}") @ResponseBody public Partie connect(@PathVariable final String name) throws IOException { Logger.getLogger(LOGGER_NAME).info("connect(): " + name); Partie partie = gameHandler.generateNewUser(name); gameHandler.save(); return partie; }
@RequestMapping("/users/{name}/fight") @ResponseBody public FightResult userFight(@PathVariable final String name) throws IOException { Logger.getLogger(LOGGER_NAME).info("userFight(): " + name); User user = gameHandler.findUser(name); // Retrieve user User opponent = gameHandler.findOpponent(user); // Match-making algorithm if (opponent == null) { // return no opponent found gameHandler.updateUserStatsAndSave(user); return new FightResult(FightResult.NO_OPPONENT_FOUND, user); } Logger.getLogger(LOGGER_NAME).info("userFight(): " + name + " vs " + opponent.name); boolean wonFight = gameHandler.resolveFight(user, opponent); // Resolve fight gameHandler.save(); Logger.getLogger(LOGGER_NAME).info("userFight(): won " + wonFight); return new FightResult(wonFight ? FightResult.VICTORY : FightResult.DEFEAT, user); }