001: package poker.presentation.main;
002:
003: import java.io.*;
004: import java.net.*;
005: import com.lutris.http.*;
006: import com.lutris.appserver.server.httpPresentation.*;
007: import com.lutris.appserver.server.user.*;
008: import com.lutris.util.*;
009: import poker.spec.*;
010: import poker.Poker;
011:
012: /**
013: * Presentation Object that processes the bet request and redirects
014: * to the appropriate page.
015: *
016: * EnhyDraw!, beta 4, 5/21/99
017: *
018: * Copyright 1999, Larry Wolcot & Daryl Tempesta
019: * ALL rights reserved. Not for commercial use
020: * without written permission from both authors.
021: *
022: */
023: public class BetProcessorPresentation implements HttpPresentation {
024:
025: static final String continuePage = "main/FirstDealPresentation.po";
026: static final String errorPage = "main/PlaceBetPresentation.po";
027: static final String debugArg = "debug";
028: static final String helpArg = "help";
029:
030: public void run(HttpPresentationComms comms) throws Exception {
031: String bet = comms.request.getParameter("bet");
032: String def = comms.request.getParameter("default");
033: String quit = comms.request.getParameter("QUIT");
034: if (quit != null) {
035: if (quit.equals("QUIT")) {
036: throw new ClientPageRedirectException(comms.request
037: .getAppFileURIPath("main/QuitPresentation.po"));
038: }
039: }
040: if (def == null) {
041: def = "empty";
042: }
043: PokerGame game;
044: game = (PokerGame) comms.session.getSessionData().get("game");
045: String redirect = "";
046: /*
047: * Catch Null pointer exception ( we canot make a instances of classes from business layer when we run poker_pres )
048: * We need to allow poker_pres to be dynamic
049: */
050: try {
051:
052: try {
053: game.setBet(new Integer(bet).intValue());
054: } catch (NumberFormatException e) {
055:
056: game.setLastError("Invalid bet value!!");
057: throw new ClientPageRedirectException(comms.request
058: .getAppFileURIPath(errorPage));
059: }
060: String pp = comms.request.getApplicationPath();
061: if (!pp.endsWith("/"))
062: pp += "/";
063:
064: HttpPresentationOutputStream out = comms.response
065: .getOutputStream();
066: boolean validBet = false;
067:
068: int this Bet = 0;
069: if (bet != null) {
070: this Bet = new Integer(bet).intValue();
071: }
072:
073: if (game.getPlayRound() > 1) {
074: redirect = continuePage;
075: } else {
076: if ((this Bet > game.getCash()) || (this Bet == 0)) {
077: redirect = errorPage;
078: game.setLastError("Invalid bet value!!");
079: game.setPlayRound(0);
080: } else {
081: Poker mainApp;
082: mainApp = (Poker) comms.session.getSessionData()
083: .get("app");
084: GameManager g = mainApp.getGameManager();
085: g.setTotalDollars(this Bet);
086: g.setHandsDealt(1);
087: redirect = continuePage;
088: game.setBet(this Bet);
089: game.setTotalPlayed(game.getTotalPlayed() + 1);
090: game.setCash(game.getCash() - this Bet);
091: if (def.equals("on")) {
092: game.setDefaultBet(this Bet);
093: }
094: g.updateGame(game);
095: }
096: }
097: } catch (NullPointerException e) {
098: throw new ClientPageRedirectException(comms.request
099: .getAppFileURIPath(errorPage));
100:
101: }
102:
103: throw new ClientPageRedirectException(comms.request
104: .getAppFileURIPath(redirect));
105: }
106: }
|