Methods Summary |
---|
public synchronized void | addMove(borland.samples.apps.chess.client.ServerMessage smsg)
int index = smsg.msg.indexOf(' ");
String time = smsg.msg.substring(0,index);
String move = smsg.msg.substring(index+1);
if (whitetomove)
whiteTime = time;
else
blackTime = time;
if (!gameover)
if (whitetomove) {
movenum++;
whitetomove = false;
}
else
whitetomove = true;
setInfo();
if (move.startsWith("@")) {
index = move.indexOf(' ") ;
moves = moves + " " + move.substring(0,index);
move = move.substring(index+1);
}
if (move.endsWith("_")) {
whitesLastMove = move.substring(0,move.length() - 1);
moves = moves + " " + whitesLastMove ;
}
else {
index = whitesLastMove.length();
if (index > 0 && move.startsWith(whitesLastMove))
moves = moves + " " + move.substring(index);
else {
System.out.println(move + " doesn't begin like");
System.out.println(whitesLastMove + " =whites last move");
moves = moves + " " + move ;
}
}
//ServerMessage smsg = new ServerMessage(0,"Moved",movedata);
SendThread s;
for (int i=0;i< kibitzer.size();i++) {
s = (SendThread)kibitzer.elementAt(i);
System.out.println("send move to kibitzer " + s.portnum );
if (s.portnum != smsg.port )
s.addMsg(smsg);
}
|
public synchronized void | addObserver(SendThread user)
ServerMessage smsg = new ServerMessage(user.portnum,"Chat",user.name.user + " joins");
chat(smsg);
kibitzer.addElement(user);
ServerMessage msg = new ServerMessage(user.portnum,"MoveList", getMoves());
user.addMsg(msg);
//synchronized (user) {
// user.msgque.addElement(msg);
// user.notify();
//}
|
public synchronized void | chat(borland.samples.apps.chess.client.ServerMessage smsg)
for (int i=0;i<kibitzer.size();i++) {
SendThread s = (SendThread)kibitzer.elementAt(i);
smsg.port = 0;
s.addMsg(smsg);
//synchronized (s) {
// s.msgque.addElement(smsg);
// s.notify();
//}
}
|
public void | gameOver(java.lang.String result)
this.result = result;
gameover = true;
moves = " [Result \"" + result + "\"]" + moves;
chat(new ServerMessage(0,"Chat","Game Over " + result));
info = " " + result + " " + movenum + " Moves" ;
|
public void | gameResumed()
suspendCount--;
setInfo();
|
public boolean | gameSuspended()
suspendCount++;
setInfo();
if (kibitzer.size()==0 && suspendCount > 1)
return true;
return false;
|
public java.lang.String | getBlack()
return black;
|
public java.lang.String | getBlackId()
return blackId;
|
public java.lang.String | getMoves()
return "[White \"" + white + "\"] " +
"[Black \"" + black + "\"] " +
"[Blacktime " + blackTime + "] " +
"[Whitetime " + whiteTime + "] " +
"[Movetime " + moveTime + "] " +
moves ;
|
public java.lang.String | getOffer(java.lang.String offeree)
if (offerFlag == 0)
return null;
int value = offerFlag ;
if (offeree.equals(black))
value = offerFlag / 2;
System.out.println("Offer was " + value);
if (value == Game.DRAWOFFER )
return "OfferDraw";
else
if (value == Game.ABORTOFFER )
return "OfferAbort";
return null;
|
public java.lang.String | getPlayers()
return white + " - " + black ;
|
public java.lang.String | getWhite()
return white;
|
public java.lang.String | getWhiteId()
return whiteId;
|
public boolean | isOver()
return gameover;
|
public synchronized boolean | removeObserver(SendThread user)
if (kibitzer.size() > 0)
kibitzer.removeElement(user);
if (kibitzer.size()==0 && gameover)
return true; //okay to delete game
else {
ServerMessage msg = new ServerMessage(user.portnum,"Chat",user.name.user + " parts");
chat(msg);
return false;
}
|
public void | setInfo()
if (gameover)
return;
String suspend = "";
if (suspendCount > 0)
suspend = " (Suspended)";
String tomove = " Black to move";
int move = movenum;
if (whitetomove) {
move++;
tomove = " White to move";
}
info = ": Move " + move + tomove + suspend;
|
public void | setOffer(java.lang.String offerer, int Offer)
offerFlag = Offer;
if (offerer.equals(white))
offerFlag = Offer * 2;
|
public java.lang.String | toString()
return white + " - " + black + info;
|