1 package com.codingame.game;
3 import java.util.regex.Pattern;
4 import java.util.Scanner;
5 import java.util.InputMismatchException;
6 import java.util.NoSuchElementException;
8 import com.codingame.gameengine.core.AbstractMultiplayerPlayer;
9 import com.codingame.gameengine.module.entities.Group;
10 import com.codingame.gameengine.module.entities.Text;
11 import com.codingame.gameengine.module.entities.Sprite;
13 public class Player extends AbstractMultiplayerPlayer {
20 private String messageString = "";
21 public String getMessageString() { return messageString; }
23 private int castlePosition;
24 public int getCastlePosition() { return castlePosition; }
25 public void setCastlePosition(int pos) { castlePosition = pos; }
28 public int getStones() { return stones; }
29 public void consumeStones(int n) throws InvalidAction {
31 throw new InvalidAction("attempted to throw more stones than they had.");
33 setStones(stones - n);
35 public void setStones(int n) {
38 stoneCounter.setText("No stones!");
39 stoneCounter.setFillColor(0xff7777);
41 else if (stones == 1) {
42 stoneCounter.setText("1 stone");
43 stoneCounter.setFillColor(0xffbb77);
46 stoneCounter.setText(stones + " stones");
50 private int multiplier;
51 public int getMultiplier() { return multiplier; }
52 public void setMultiplier(int m){ multiplier = m; }
54 public void adjustScore(int trollPosition) {
55 setScore(Math.abs(castlePosition - trollPosition));
59 public int getExpectedOutputLines() {
63 static final Pattern rest = Pattern.compile(".*");
64 static final Pattern eol = Pattern.compile("\n");
65 public int getAction() throws TimeoutException, NumberFormatException {
66 Scanner s = new Scanner(getOutputs().get(0));
72 messageString = s.next(rest);
75 catch (InputMismatchException e) { throw new NumberFormatException(); }
76 catch (NoSuchElementException e) { throw new NumberFormatException(); }