forked from khoa698/kalahbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample-code.txt
38 lines (36 loc) · 1.05 KB
/
example-code.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// example code:
try
{
String s;
while (true)
{
System.err.println();
s = recvMsg();
System.err.print("Received: " + s);
try {
MsgType mt = Protocol.getMessageType(s);
switch (mt)
{
case START: System.err.println("A start.");
boolean first = Protocol.interpretStartMsg(s);
System.err.println("Starting player? " + first);
break;
case STATE: System.err.println("A state.");
Board b = new Board(6,6);
Protocol.MoveTurn r = Protocol.interpretStateMsg (s, b);
System.err.println("This was the move: " + r.move);
System.err.println("Is the game over? " + r.end);
if (!r.end) System.err.println("Is it our turn again? " + r.again);
System.err.print("The board:\n" + b);
break;
case END: System.err.println("An end. Bye bye!"); return;
}
} catch (InvalidMessageException e) {
System.err.println(e.getMessage());
}
}
}
catch (IOException e)
{
System.err.println("This shouldn't happen: " + e.getMessage());
}