import java.io.*; import java.awt.Color; class GameThread extends java.lang.Thread { mancala board; GameThread(mancala board) { super("GameThread"); setPriority(getPriority()-1); this.board = board; } public void run() { String s, words[]; while(true) { if(!board.moveOk && !board.reading) { words = board.explode(s = board.readLine(), " "); if(s.equalsIgnoreCase("! MOVE")) { board.sendLine("+ Thanks!"); board.led.setColor(Color.green); board.moveOk = true; } if(words[1].equalsIgnoreCase("BOARD")) { board.sendLine("+ Thanks"); for(int i=0;i<6;i++) board.NearPits[i].setStones(Integer.parseInt(words[2+i])); board.NearMancala.setStones(Integer.parseInt(words[8])); for(int i=0;i<6;i++) board.FarPits[i].setStones(Integer.parseInt(words[14-i])); board.FarMancala.setStones(Integer.parseInt(words[15])); } if(words[1].equalsIgnoreCase("LASTMOVE")) { board.sendLine("+ Ok."); board.lastMove.setText(words[2]+" "+(board.leftOk ? words[3].substring(0,1) : "")); } if(words[0].equals("?") && words[1].equalsIgnoreCase("RESIGN")) { MsgBox mb = new MsgBox("Opponent wants to resign. Accept?", "Resignation", MsgBox.YES+MsgBox.NO); mb.show(); if(mb.result.equalsIgnoreCase("Yes")) board.sendLine("+ Resignation accepted."); else board.sendLine("- Resignation rejected."); } if(words[1].equalsIgnoreCase("ENDGAME")) { board.sendLine("+ Ok."); board.endGame(words); stop(); } } else { try { sleep(500); } catch(Exception e) { System.err.println("Exception "+e);return; } } } } }