X-Git-Url: https://troll.desast.re/troll.git/blobdiff_plain/33d43e0a726d9cb3256489d0b39feebbbb3304a4..927d39e66672341d9d1e281accf0633747ea715f:/src/main/java/com/codingame/game/Player.java?ds=sidebyside diff --git a/src/main/java/com/codingame/game/Player.java b/src/main/java/com/codingame/game/Player.java index 2716b17..db51bb4 100644 --- a/src/main/java/com/codingame/game/Player.java +++ b/src/main/java/com/codingame/game/Player.java @@ -1,31 +1,31 @@ package com.codingame.game; +import java.util.regex.Pattern; +import java.util.Scanner; +import java.util.InputMismatchException; +import java.util.NoSuchElementException; + import com.codingame.gameengine.core.AbstractMultiplayerPlayer; import com.codingame.gameengine.module.entities.Group; import com.codingame.gameengine.module.entities.Text; import com.codingame.gameengine.module.entities.Sprite; public class Player extends AbstractMultiplayerPlayer { - Group hud; + Group avatar; Text stoneCounter; - + Text message; Sprite castle; Text stone; - + + private String messageString = ""; + public String getMessageString() { return messageString; } private int castlePosition; - public int getCastlePosition() { - return castlePosition; - } - public void setCastlePosition(int pos) { - castlePosition = pos; - } + public int getCastlePosition() { return castlePosition; } + public void setCastlePosition(int pos) { castlePosition = pos; } private int stones; - public int getStones() - { - return stones; - } + public int getStones() { return stones; } public void consumeStones(int n) throws InvalidAction { if (n > stones) { throw new InvalidAction("attempted to throw more stones than they had."); @@ -48,12 +48,8 @@ public class Player extends AbstractMultiplayerPlayer { } private int multiplier; - public int getMultiplier() { - return multiplier; - } - public void setMultiplier(int m){ - multiplier = m; - } + public int getMultiplier() { return multiplier; } + public void setMultiplier(int m){ multiplier = m; } public void adjustScore(int trollPosition) { setScore(Math.abs(castlePosition - trollPosition)); @@ -64,7 +60,19 @@ public class Player extends AbstractMultiplayerPlayer { return 1; } + static final Pattern rest = Pattern.compile(".*"); + static final Pattern eol = Pattern.compile("\n"); public int getAction() throws TimeoutException, NumberFormatException { - return Integer.parseInt(getOutputs().get(0)); + Scanner s = new Scanner(getOutputs().get(0)); + messageString = ""; + try { + int st = s.nextInt(); + s.useDelimiter(eol); + if (s.hasNext(rest)) + messageString = s.next(rest); + return st; + } + catch (InputMismatchException e) { throw new NumberFormatException(); } + catch (NoSuchElementException e) { throw new NumberFormatException(); } } }