1 package poker.presentation.main; 2 3 import java.io.*; 4 import java.net.*; 5 import com.lutris.http.*; 6 import com.lutris.appserver.server.httpPresentation.*; 7 import com.lutris.appserver.server.user.*; 8 import com.lutris.util.*; 9 import poker.spec.*; 10 import poker.Poker; 11 12 23 public class BetProcessorPresentation implements HttpPresentation{ 24 25 static final String continuePage = "main/FirstDealPresentation.po"; 26 static final String errorPage = "main/PlaceBetPresentation.po"; 27 static final String debugArg = "debug"; 28 static final String helpArg = "help"; 29 30 31 32 public void run(HttpPresentationComms comms) throws Exception { 33 String bet = comms.request.getParameter("bet"); 34 String def = comms.request.getParameter("default"); 35 String quit = comms.request.getParameter("QUIT"); 36 if (quit != null){ 37 if (quit.equals("QUIT")){ 38 throw new ClientPageRedirectException( 39 comms.request.getAppFileURIPath("main/QuitPresentation.po")); 40 } 41 } 42 if (def == null) {def = "empty";} 43 PokerGame game; 44 game = (PokerGame)comms.session.getSessionData().get("game"); 45 String redirect = ""; 46 50 try{ 51 52 try{ 53 game.setBet(new Integer (bet).intValue()); 54 }catch(NumberFormatException e){ 55 56 game.setLastError("Invalid bet value!!"); 57 throw new ClientPageRedirectException( 58 comms.request.getAppFileURIPath(errorPage)); 59 } 60 String pp = comms.request.getApplicationPath(); 61 if (!pp.endsWith("/")) 62 pp += "/"; 63 64 HttpPresentationOutputStream out =comms.response.getOutputStream(); 65 boolean validBet = false; 66 67 int thisBet = 0; 68 if (bet != null){ 69 thisBet = new Integer (bet).intValue(); 70 } 71 72 if (game.getPlayRound() > 1) { 73 redirect = continuePage; 74 } else { 75 if ((thisBet > game.getCash()) || (thisBet == 0)){ 76 redirect = errorPage; 77 game.setLastError("Invalid bet value!!"); 78 game.setPlayRound(0); 79 } else { 80 Poker mainApp; 81 mainApp = (Poker)comms.session.getSessionData().get("app"); 82 GameManager g = mainApp.getGameManager(); 83 g.setTotalDollars(thisBet); 84 g.setHandsDealt(1); 85 redirect = continuePage; 86 game.setBet(thisBet); 87 game.setTotalPlayed(game.getTotalPlayed() + 1); 88 game.setCash(game.getCash() - thisBet); 89 if (def.equals("on")){ 90 game.setDefaultBet(thisBet); 91 } 92 g.updateGame(game); 93 } 94 } 95 }catch (NullPointerException e){ 96 throw new ClientPageRedirectException( 97 comms.request.getAppFileURIPath(errorPage)); 98 99 } 100 101 throw new ClientPageRedirectException( 102 comms.request.getAppFileURIPath(redirect)); 103 } 104 } 105 | Popular Tags |