Major model/view split. Compiles and runs, but viewer is sub-par.
[troll.git] / src / main / java / com / codingame / game / Player.java
1 package com.codingame.game;
2
3 import java.util.List;
4
5 import java.util.regex.Pattern;
6 import java.util.Scanner;
7 import java.util.InputMismatchException;
8 import java.util.NoSuchElementException;
9
10 import com.codingame.gameengine.core.AbstractMultiplayerPlayer;
11 import com.codingame.gameengine.module.entities.Group;
12 import com.codingame.gameengine.module.entities.Text;
13 import com.codingame.gameengine.module.entities.Sprite;
14
15 public class Player extends AbstractMultiplayerPlayer {
16     Model.Player model;
17     View.Player view;
18
19     private String messageString = "";
20     public String getMessageString() { return messageString; }
21
22     @Override
23     public int getExpectedOutputLines() {
24         return 1;
25     }
26
27     static final Pattern rest = Pattern.compile(".*");
28     static final Pattern eol = Pattern.compile("\n");
29     public int getAction() throws TimeoutException, NumberFormatException {
30         Scanner s = new Scanner(getOutputs().get(0));
31         messageString = "";
32         try {
33             int st = s.nextInt();
34             s.useDelimiter(eol);
35             if (s.hasNext(rest))
36                 messageString = s.next(rest);
37             return st;
38         }
39         catch (InputMismatchException e) { throw new NumberFormatException(); }
40         catch (NoSuchElementException e) { throw new NumberFormatException(); }
41     }
42 }