diff options
author | thevu31 | 2015-02-20 23:13:13 +0100 |
---|---|---|
committer | thevu31 | 2015-02-20 23:13:13 +0100 |
commit | 8443f9833513b35824182ab5738a773ab661dbcf (patch) | |
tree | e474edc34349e6a4cbe2224051ab8436280eee37 /GameController | |
parent | directory structure (diff) |
abstractify
Diffstat (limited to 'GameController')
-rw-r--r-- | GameController/src/nl/camilstaps/botleagues/Contestant.java | 58 |
1 files changed, 44 insertions, 14 deletions
diff --git a/GameController/src/nl/camilstaps/botleagues/Contestant.java b/GameController/src/nl/camilstaps/botleagues/Contestant.java index 77fab8e..d639999 100644 --- a/GameController/src/nl/camilstaps/botleagues/Contestant.java +++ b/GameController/src/nl/camilstaps/botleagues/Contestant.java @@ -1,5 +1,11 @@ package nl.camilstaps.botleagues; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; + /** * A contestant is a process, a unique identifier and has a score. * @@ -13,50 +19,74 @@ public class Contestant implements Comparable<Contestant> { private final int uid; /** The score */ private int score = 0; - + /** * Create a new contestant with default uid -1 * - * @param p the process to link this contestant to + * @param p + * the process to link this contestant to */ public Contestant(Process p) { process = p; this.uid = -1; } - + /** * Create a new contestant with a custom uid * - * @param p the process to link this contestant to - * @param uid the uid + * @param p + * the process to link this contestant to + * @param uid + * the uid */ public Contestant(Process p, int uid) { process = p; this.uid = uid; } - + /** * Set a new score + * * @param new_score */ public void setScore(int new_score) { score = new_score; } - + /** * Get the current score + * * @return */ public int getScore() { return score; } - + /** - * Get the process - * @return + * writes the guess + * + * @throws IOException */ - public Process getProcess() { - return process; + + public void writeGuess() throws IOException { + BufferedWriter writer = new BufferedWriter(new OutputStreamWriter( + process.getOutputStream())); + writer.write("Guess\n"); + writer.flush(); + + } + + /** + * + * @return answer + * @throws NumberFormatException + * @throws IOException + */ + public int getAnswer() throws NumberFormatException, IOException { + BufferedReader reader = new BufferedReader(new InputStreamReader( + process.getInputStream())); + int answer = Integer.parseInt(reader.readLine()); + return answer; } @Override @@ -67,10 +97,10 @@ public class Contestant implements Comparable<Contestant> { public int compareTo(Contestant arg0) { return ((Integer) getScore()).compareTo(arg0.getScore()); } - + @Override public String toString() { return "Contestant " + uid + " (" + score + "): " + process.toString(); } - + } |