Early termination
[troll.git] / src / main / java / com / codingame / game / Player.java
1 package com.codingame.game;
2
3 import com.codingame.gameengine.core.AbstractMultiplayerPlayer;
4 import com.codingame.gameengine.module.entities.Group;
5 import com.codingame.gameengine.module.entities.Text;
6 import com.codingame.gameengine.module.entities.Sprite;
7
8 public class Player extends AbstractMultiplayerPlayer {
9     Group hud;
10     Text stoneCounter;
11
12     Sprite castle;
13     Text stone;
14     
15
16     private int castlePosition;
17     public int getCastlePosition() {
18         return castlePosition;
19     }
20     public void setCastlePosition(int pos) {
21         castlePosition = pos;
22     }
23
24     private int stones;
25     public int getStones()
26     {
27         return stones;
28     }
29     public void consumeStones(int n) throws InvalidAction {
30         if (n > stones) {
31             throw new InvalidAction("attempted to throw more stones than they had.");
32         }
33         setStones(stones - n);
34     }
35     public void setStones(int n) {
36         stones = n;
37         if (stones <= 0) {
38             stoneCounter.setText("No stones!");
39             stoneCounter.setFillColor(0xff7777);
40         }
41         else if (stones == 1) {
42             stoneCounter.setText("1 stone");
43             stoneCounter.setFillColor(0xffbb77);
44         }
45         else {
46             stoneCounter.setText(stones + " stones");
47         }
48     }
49
50     private int multiplier;
51     public int getMultiplier() {
52         return multiplier;
53     }
54     public void setMultiplier(int m){
55         multiplier = m;
56     }
57
58     public void adjustScore(int trollPosition) {
59         setScore(Math.abs(castlePosition - trollPosition));
60     }
61
62     @Override
63     public int getExpectedOutputLines() {
64         return 1;
65     }
66
67     public int getAction() throws TimeoutException, NumberFormatException {
68         return Integer.parseInt(getOutputs().get(0));
69     }
70 }