001: /*
002: * Poker
003: *
004: * Enhydra super-servlet presentation object
005: *
006: */
007:
008: package poker.presentation.main;
009:
010: // Enhydra SuperServlet imports
011: import com.lutris.appserver.server.httpPresentation.HttpPresentation;
012: import com.lutris.appserver.server.httpPresentation.HttpPresentationComms;
013: import org.w3c.dom.html.HTMLTextAreaElement;
014: import org.w3c.dom.html.HTMLInputElement;
015: import org.w3c.dom.html.HTMLImageElement;
016:
017: import poker.Poker;
018: import poker.spec.PokerGame;
019: import poker.spec.GameManager;
020:
021: import java.util.Vector;
022:
023: public class PlaceBetPresentation implements HttpPresentation {
024:
025: public void run(HttpPresentationComms comms) throws Exception {
026:
027: PlaceBetHTML placeBet;
028: placeBet = (PlaceBetHTML) comms.xmlcFactory
029: .create(PlaceBetHTML.class);
030: /*
031: * Catch Null pointer exception ( we canot make a instances of classes from business layer when we run poker_pres )
032: * We need to allow poker_pres to be dynamic , so if the requested url is /poker_pres/..... the response
033: * will be default HTML page
034: */
035: try {
036: this .initGame(comms, placeBet);
037: } catch (NullPointerException e) {
038: placeBet.setTextMessage("This is a default HTML page");
039: }
040:
041: comms.response.writeDOM(placeBet);
042:
043: }
044:
045: static public void initGame(HttpPresentationComms comms0,
046: PlaceBetHTML placeBet0) throws Exception {
047: PokerGame game = (PokerGame) comms0.session.getSessionData()
048: .get("game");
049: Poker mainApp = (Poker) comms0.session.getSessionData().get(
050: "app");
051: GameManager gameManager = mainApp.getGameManager();
052:
053: game.setPlayRound(1);
054:
055: Vector freshDrops = new Vector(0);
056: for (int i = 0; i < 5; i++) {
057: freshDrops.addElement("DROP");
058: }
059: game.setDropCards(freshDrops);
060:
061: placeBet0.setTextCash(Integer.toString(game.getCash()));
062: placeBet0.setTextName(game.getName());
063: placeBet0.setTextRank(Integer.toString(gameManager.getRank(game
064: .getCash())));
065: placeBet0.setTextWon(Integer.toString(game.getTotalWon()));
066: placeBet0.setTextHandsPlayed(Integer.toString(game
067: .getTotalPlayed()));
068:
069: HTMLImageElement image = null;
070: image = placeBet0.getElementDeck1();
071: image.setSrc("../media/" + game.getDeck() + ".jpg");
072: image = placeBet0.getElementDeck2();
073: image.setSrc("../media/" + game.getDeck() + ".jpg");
074: image = placeBet0.getElementDeck3();
075: image.setSrc("../media/" + game.getDeck() + ".jpg");
076: image = placeBet0.getElementDeck4();
077: image.setSrc("../media/" + game.getDeck() + ".jpg");
078: image = placeBet0.getElementDeck5();
079: image.setSrc("../media/" + game.getDeck() + ".jpg");
080:
081: HTMLInputElement input = null;
082: input = placeBet0.getElementBetInput();
083: input.setValue(Integer.toString(game.getDefaultBet()));
084:
085: if (game.getDefaultBet() > 0) {
086: input = placeBet0.getElementCheckInput();
087: input.setChecked(true);
088: input.setValue("on");
089: } else {
090: input = placeBet0.getElementCheckInput();
091: input.setChecked(false);
092: input.setValue("off");
093: }
094:
095: if (game.getLastError() != "") {
096: placeBet0.setTextMessage(game.getLastError());
097: game.setLastError("");
098: } else {
099: placeBet0.setTextMessage("");
100: }
101: }
102:
103: }
|