aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorthevu312015-02-20 23:13:13 +0100
committerthevu312015-02-20 23:13:13 +0100
commita248465f92583f1a065074c4a63ddf14a2349fa5 (patch)
tree37c9eb149bdf07c7ce8d903dfa346ffda10a9292
parentdirectory structure (diff)
abstractify
-rw-r--r--src/nl/camilstaps/botleagues/Contestant.java58
1 files changed, 44 insertions, 14 deletions
diff --git a/src/nl/camilstaps/botleagues/Contestant.java b/src/nl/camilstaps/botleagues/Contestant.java
index 77fab8e..d639999 100644
--- a/src/nl/camilstaps/botleagues/Contestant.java
+++ b/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();
}
-
+
}