Prev | Current Page 761 | Next

Frank Zammetti

"Practical DWR 2 Projects"

Stop thread from running and alert the client.
isActive = false;
ScriptBuffer script = new ScriptBuffer();
CHAPTER 8 n DWR FOR FUN AND PROFIT (A DWR GAME!) 452
script.appendScript("inMemoria.opponentWon();");
ScriptSession scriptSession = webContext.getScriptSession();
scriptSession.addScript(script);
currentState = STATE_WAITING;
inSession.setAttribute("opponent", this);
log.trace("outcomeComplete() - Exit (1)");
return;
}
}
// Reset for next tile pick. Note this won't matter if the opponent won.
flippedTile1 = -1;
flippedTile2 = -1;
currentState = STATE_PICK_TILE_1;
inSession.setAttribute("opponent", this);
log.trace("outcomeComplete() - Exit (2)");
} // End outcomeComplete().
This is, as you can see, the other remotable method in this class; all the others are private
and therefore not callable from the client. This is a pretty simple method as well. First, simply
compare the values of the two flipped tiles. If they match, bump up the value of the matches
field. If that value is now greater than 20, the opponent has won, in which case isActive is set
to false so that no further iterations occur. Then, again using the ScriptBuffer object, we
write out a call to the opponentWon() method of the InMemoria class.


Pages:
749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773