Upgrade to engine 3.15.0
[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 avatar;
10     Text stoneCounter;
11     Sprite castle;
12     Text stone;
13     
14
15     private int castlePosition;
16     public int getCastlePosition() {
17         return castlePosition;
18     }
19     public void setCastlePosition(int pos) {
20         castlePosition = pos;
21     }
22
23     private int stones;
24     public int getStones()
25     {
26         return stones;
27     }
28     public void consumeStones(int n) throws InvalidAction {
29         if (n > stones) {
30             throw new InvalidAction("attempted to throw more stones than they had.");
31         }
32         setStones(stones - n);
33     }
34     public void setStones(int n) {
35         stones = n;
36         if (stones <= 0) {
37             stoneCounter.setText("No stones!");
38             stoneCounter.setFillColor(0xff7777);
39         }
40         else if (stones == 1) {
41             stoneCounter.setText("1 stone");
42             stoneCounter.setFillColor(0xffbb77);
43         }
44         else {
45             stoneCounter.setText(stones + " stones");
46         }
47     }
48
49     private int multiplier;
50     public int getMultiplier() {
51         return multiplier;
52     }
53     public void setMultiplier(int m){
54         multiplier = m;
55     }
56
57     public void adjustScore(int trollPosition) {
58         setScore(Math.abs(castlePosition - trollPosition));
59     }
60
61     @Override
62     public int getExpectedOutputLines() {
63         return 1;
64     }
65
66     public int getAction() throws TimeoutException, NumberFormatException {
67         return Integer.parseInt(getOutputs().get(0));
68     }
69 }