1 7 8 package poker.presentation.main; 9 10 import com.lutris.appserver.server.httpPresentation.HttpPresentation; 12 import com.lutris.appserver.server.httpPresentation.HttpPresentationComms; 13 import org.w3c.dom.html.HTMLDivElement; 16 import org.w3c.dom.html.HTMLInputElement; 17 import org.w3c.dom.html.HTMLImageElement; 18 import org.w3c.dom.html.HTMLTableRowElement; 19 import org.w3c.dom.Node ; 20 21 import java.util.Vector ; 22 23 import poker.Poker; 24 import poker.spec.*; 25 26 28 29 public class FirstDealPresentation implements HttpPresentation { 30 31 34 private static Vector dealtCards = new Vector (0); 35 36 private static int pointer = 0; 37 38 39 public void run(HttpPresentationComms comms) 40 throws Exception { 41 42 FirstDealHTML firstDeal; 43 firstDeal = (FirstDealHTML)comms.xmlcFactory.create(FirstDealHTML.class); 44 45 this.startGame(comms, firstDeal); 46 this.getCards(comms, firstDeal); 47 this.checkHand(comms, firstDeal); 48 49 HTMLDivElement div = null; 50 HTMLTableRowElement row = null; 51 Node parent = null; 52 if(this.isLastDeal(comms)) { 53 div = firstDeal.getElementIsNotLastDeal1(); 54 parent = div.getParentNode(); 55 parent.removeChild(div); 56 57 firstDeal.setTextIsLastDeal2("Click on NEW HAND to play another round"); 58 firstDeal.setTextIsNotLastDeal2(""); 59 60 row = firstDeal.getElementIsNotLastDeal3(); 61 parent = row.getParentNode(); 62 parent.removeChild(row); 63 64 row = firstDeal.getElementIsNotLastDeal4(); 65 parent = row.getParentNode(); 66 parent.removeChild(row); 67 68 row = firstDeal.getElementIsNotLastDeal5(); 69 parent = row.getParentNode(); 70 parent.removeChild(row); 71 } 72 else { 73 div = firstDeal.getElementIsLastDeal1(); 74 parent = div.getParentNode(); 75 parent.removeChild(div); 76 77 firstDeal.setTextIsLastDeal2(""); 78 firstDeal.setTextIsNotLastDeal2("Select the cards you wish to keep, then press DRAW!"); 79 80 row = firstDeal.getElementIsLastDeal3(); 81 parent = row.getParentNode(); 82 parent.removeChild(row); 83 84 row = firstDeal.getElementIsLastDeal4(); 85 parent = row.getParentNode(); 86 parent.removeChild(row); 87 88 row = firstDeal.getElementIsLastDeal5(); 89 parent = row.getParentNode(); 90 parent.removeChild(row); 91 } 92 93 if(this.isBankrupt(comms)) { 94 div = firstDeal.getElementIsNotBankrupt(); 95 parent = div.getParentNode(); 96 parent.removeChild(div); 97 } 98 else { 99 div = firstDeal.getElementIsBankrupt(); 100 parent = div.getParentNode(); 101 parent.removeChild(div); 102 } 103 104 comms.response.writeDOM(firstDeal); 105 } 106 107 108 109 static public void getCards(HttpPresentationComms comms0, FirstDealHTML firstDeal0) throws Exception { 110 PokerGame game = (PokerGame) comms0.session.getSessionData().get("game"); 111 Vector theseCards = game.getCardsInHand(); 112 Vector usedCards = game.getCardsUsed(); 113 Vector dropCards = game.getDropCards(); 114 String but[] ={ "DROP", "DROP", "DROP", "DROP", "DROP" }; 115 116 Dealer dealer = DealerFactory.getDealer("poker.business.DealerImpl"); 117 String flag; 118 119 if (game.getPlayRound() == 3) { 120 theseCards = dealer.drawMoreCards(theseCards, dropCards); 121 for (int i = 0; i < 5; i ++) { 122 flag = (String )dropCards.elementAt(i); 123 if (flag.equals("DROP")) { 124 dropCards.setElementAt("DEALT", i); 125 } 126 else { 127 dropCards.setElementAt("HELD", i); 128 } 129 } 130 } 131 132 Integer card[] = new Integer [5]; 133 String [] drop = new String [5]; 134 135 for (int i = 0; i < 5; i++) { 136 HTMLImageElement image = null; 137 HTMLInputElement input = null; 138 card[i] = (Integer ) theseCards.elementAt(i); 139 String srcImage = "../media/" + card[i].toString() + ".gif"; 140 drop[i] = (String )dropCards.elementAt(i); 141 142 switch (i) { 144 case 0 : { 145 image = firstDeal0.getElementCard1(); 146 image.setSrc(srcImage); 147 image = firstDeal0.getElementCard11(); 148 image.setSrc(srcImage); 149 150 input = firstDeal0.getElementBut1(); 151 if (drop[i] != "DROP") { 152 but[i] = "DROP"; 153 } 154 input.setValue(but[i]); 155 break; 156 } 157 case 1 : { 158 image = firstDeal0.getElementCard2(); 159 image.setSrc(srcImage); 160 image = firstDeal0.getElementCard22(); 161 image.setSrc(srcImage); 162 163 input = firstDeal0.getElementBut2(); 164 if (drop[i] != "DROP") { 165 but[i] = "DROP"; 166 } 167 input.setValue(but[i]); 168 break; 169 } 170 case 2 : { 171 image = firstDeal0.getElementCard3(); 172 image.setSrc(srcImage); 173 image = firstDeal0.getElementCard33(); 174 image.setSrc(srcImage); 175 176 input = firstDeal0.getElementBut3(); 177 if (drop[i] != "DROP") { 178 but[i] = "DROP"; 179 } 180 input.setValue(but[i]); 181 break; 182 } 183 case 3 : { 184 image = firstDeal0.getElementCard4(); 185 image.setSrc(srcImage); 186 image = firstDeal0.getElementCard44(); 187 image.setSrc(srcImage); 188 189 input = firstDeal0.getElementBut4(); 190 if (drop[i] != "DROP") { 191 but[i] = "DROP"; 192 } 193 input.setValue(but[i]); 194 break; 195 } 196 case 4 : { 197 image = firstDeal0.getElementCard5(); 198 image.setSrc(srcImage); 199 image = firstDeal0.getElementCard55(); 200 image.setSrc(srcImage); 201 202 input = firstDeal0.getElementBut5(); 203 if (drop[i] != "DROP") { 204 but[i] = "DROP"; 205 } 206 input.setValue(but[i]); 207 break; 208 } 209 } 210 } 211 } 212 213 public void startGame(HttpPresentationComms comms0, FirstDealHTML firstDeal0) throws Exception { 214 Dealer dealer = DealerFactory.getDealer("poker.business.DealerImpl"); 215 PokerGame game = (PokerGame)comms0.session.getSessionData().get("game"); 216 Poker mainApp = (Poker)comms0.session.getSessionData().get("app"); 217 GameManager gameManager = mainApp.getGameManager(); 218 if ((game.getBet() < game.getSmallestBet()) | (game.getSmallestBet() == 0)) { 219 game.setSmallestBet(game.getBet()); 220 } 221 if (game.getBet() > game.getLargestBet()) { 222 game.setLargestBet(game.getBet()); 223 } 224 if (game.getPlayRound() == 3) { 225 game.setPlayRound(4); 226 } 227 String dl = (String )comms0.request.getParameter("DROP1"); 228 if ((dl != null) & (game.getPlayRound() < 4)) { 229 game.setPlayRound(3); 230 } 231 if (game.getPlayRound() == 1) { 232 game.setCardsInHand(dealer.dealFiveCards()); 233 game.setPlayRound(2); 234 } 235 String d[] = { "DROP", "DROP", "DROP", "DROP", "DROP" }; 236 String iS = ""; 237 for (int i=0; i < 5; i++) { 238 iS = Integer.toString(i+1); 239 if ((String )comms0.request.getParameter("DROP" + iS) != null) { 240 d[i] = (String )comms0.request.getParameter("DROP" + iS); 241 } 242 } 243 244 Vector dropCards = game.getDropCards(); 245 246 for (int i = 0; i < 5; i++) { 247 String n = Integer.toString(i+1); 248 if (d[i].equals("HOLD")) { 249 dropCards.setElementAt("HOLD" ,i); 250 } 251 if (d[i].equals("DROP")){ 252 dropCards.setElementAt("DROP" ,i); 253 } 254 } 255 256 firstDeal0.setTextName(game.getName()); 257 firstDeal0.setTextCash(Integer.toString(game.getCash())); 258 firstDeal0.setTextBet(Integer.toString(game.getBet())); 259 firstDeal0.setTextRank(Integer.toString(gameManager.getRank(game.getCash()))); 260 firstDeal0.setTextHandsPlayed(Integer.toString(game.getTotalPlayed())); 261 firstDeal0.setTextWon(Integer.toString(game.getTotalWon())); 262 263 } 265 266 267 static public void checkHand(HttpPresentationComms comms0, FirstDealHTML firstDeal0) throws Exception { 268 Dealer dealer = DealerFactory.getDealer("poker.business.DealerImpl"); 269 PokerGame game = (PokerGame)comms0.session.getSessionData().get("game"); 270 Vector theseCards = game.getCardsInHand(); 271 String handTotal = dealer.checkHand(theseCards); 272 int payRate = dealer.getPayout(handTotal); 273 String message = handTotal + ", pays $" + 274 new Integer (payRate * game.getBet()).toString() + " (" + 275 new Integer (payRate).toString() + " to 1)"; 276 firstDeal0.setTextResult(message); 277 278 if (game.getPlayRound() > 2) { 279 if (game.getCash() == 0) { 280 Poker app =(Poker)comms0.session.getSessionData().get("app"); 281 GameManager g = app.getGameManager(); 282 g.setTotalBankrupt(+1); 283 } 284 Poker mainApp = (Poker)comms0.session.getSessionData().get("app"); 285 GameManager g = mainApp.getGameManager(); 286 if (game.getPlayRound() == 3) { 287 if (payRate > 0) { 288 game.setTotalWon(game.getTotalWon() + 1); 289 } 290 if (payRate > 0) { 291 g.setTotalHandsWon(1); 292 } 293 g.setTotalDollars(-(game.getBet() * payRate)); 294 game.setCash(game.getCash() + (game.getBet() * payRate)); 295 firstDeal0.setTextCash(Integer.toString(game.getCash())); 296 } 297 g.updateGame(game); 298 } 299 } 300 301 302 static public boolean isLastDeal( HttpPresentationComms comms0 ) throws Exception { 303 PokerGame game = (PokerGame)comms0.session.getSessionData().get("game"); 304 if (game.getPlayRound() > 2){ 305 return true; 306 } 307 else { 308 return false; 309 } 310 } 311 312 313 static public boolean isBankrupt( HttpPresentationComms comms0 ) throws Exception { 314 PokerGame game = (PokerGame)comms0.session.getSessionData().get("game"); 315 if ((game.getCash() == 0) & (game.getPlayRound() == 3)) { 316 return true; 317 } 318 else { 319 return false; 320 } 321 } 322 323 324 static public void getMarker( HttpPresentationComms comms0, FirstDealHTML firstDeal0 ) throws Exception { 325 PokerGame game = (PokerGame)comms0.session.getSessionData().get("game"); 326 Vector drops = game.getDropCards(); 327 String marker = (String )drops.elementAt(pointer); 328 HTMLImageElement image = null; 329 330 switch (pointer) { 331 case 0: { 332 image = firstDeal0.getElementGetMarker1(); 333 break; 334 } 335 case 1: { 336 image = firstDeal0.getElementGetMarker2(); 337 break; 338 } 339 case 2: { 340 image = firstDeal0.getElementGetMarker3(); 341 break; 342 } 343 case 3: { 344 image = firstDeal0.getElementGetMarker4(); 345 break; 346 } 347 case 4: { 348 image = firstDeal0.getElementGetMarker5(); 349 break; 350 } 351 } 352 353 if ( (marker.equals("DROP")) | (marker.equals("DEALT")) ) { 354 image.setSrc("../media/draw_n.gif"); 355 image.setName("\"but" + Integer.toString(pointer+1)); 356 } 357 else { 358 image.setSrc("../media/hold_n.gif"); 359 image.setName("\"but" + Integer.toString(pointer+1)); 360 } 361 362 pointer++; 363 if (pointer == 5) { 364 pointer = 0; 365 } 366 } 367 368 } 369 | Popular Tags |