Source Code Cross Referenced for FirstDealPresentation.java in  » J2EE » Enhydra-Demos » poker » presentation » main » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » Enhydra Demos » poker.presentation.main 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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; //import com.lutris.appserver.server.httpPresentation.HttpPresentationException;
013:        //import com.lutris.util.KeywordValueException;
014:        import org.w3c.dom.html.HTMLDivElement;
015:        import org.w3c.dom.html.HTMLInputElement;
016:        import org.w3c.dom.html.HTMLImageElement;
017:        import org.w3c.dom.html.HTMLTableRowElement;
018:        import org.w3c.dom.Node;
019:
020:        import java.util.Vector;
021:
022:        import poker.Poker;
023:        import poker.spec.*;
024:
025:        //import poker.data.game.*;
026:
027:        public class FirstDealPresentation implements  HttpPresentation {
028:
029:            /*
030:             *  This Vector keeps track of the cards already dealt (no 2 cards are the same!)
031:             */
032:            private static Vector dealtCards = new Vector(0);
033:
034:            private static int pointer = 0;
035:
036:            public void run(HttpPresentationComms comms) throws Exception {
037:
038:                FirstDealHTML firstDeal;
039:                firstDeal = (FirstDealHTML) comms.xmlcFactory
040:                        .create(FirstDealHTML.class);
041:
042:                this .startGame(comms, firstDeal);
043:                this .getCards(comms, firstDeal);
044:                this .checkHand(comms, firstDeal);
045:
046:                HTMLDivElement div = null;
047:                HTMLTableRowElement row = null;
048:                Node parent = null;
049:                if (this .isLastDeal(comms)) {
050:                    div = firstDeal.getElementIsNotLastDeal1();
051:                    parent = div.getParentNode();
052:                    parent.removeChild(div);
053:
054:                    firstDeal
055:                            .setTextIsLastDeal2("Click on NEW HAND to play another round");
056:                    firstDeal.setTextIsNotLastDeal2("");
057:
058:                    row = firstDeal.getElementIsNotLastDeal3();
059:                    parent = row.getParentNode();
060:                    parent.removeChild(row);
061:
062:                    row = firstDeal.getElementIsNotLastDeal4();
063:                    parent = row.getParentNode();
064:                    parent.removeChild(row);
065:
066:                    row = firstDeal.getElementIsNotLastDeal5();
067:                    parent = row.getParentNode();
068:                    parent.removeChild(row);
069:                } else {
070:                    div = firstDeal.getElementIsLastDeal1();
071:                    parent = div.getParentNode();
072:                    parent.removeChild(div);
073:
074:                    firstDeal.setTextIsLastDeal2("");
075:                    firstDeal
076:                            .setTextIsNotLastDeal2("Select the cards you wish to keep, then press DRAW!");
077:
078:                    row = firstDeal.getElementIsLastDeal3();
079:                    parent = row.getParentNode();
080:                    parent.removeChild(row);
081:
082:                    row = firstDeal.getElementIsLastDeal4();
083:                    parent = row.getParentNode();
084:                    parent.removeChild(row);
085:
086:                    row = firstDeal.getElementIsLastDeal5();
087:                    parent = row.getParentNode();
088:                    parent.removeChild(row);
089:                }
090:
091:                if (this .isBankrupt(comms)) {
092:                    div = firstDeal.getElementIsNotBankrupt();
093:                    parent = div.getParentNode();
094:                    parent.removeChild(div);
095:                } else {
096:                    div = firstDeal.getElementIsBankrupt();
097:                    parent = div.getParentNode();
098:                    parent.removeChild(div);
099:                }
100:
101:                comms.response.writeDOM(firstDeal);
102:            }
103:
104:            static public void getCards(HttpPresentationComms comms0,
105:                    FirstDealHTML firstDeal0) throws Exception {
106:                PokerGame game = (PokerGame) comms0.session.getSessionData()
107:                        .get("game");
108:                Vector theseCards = game.getCardsInHand();
109:                Vector usedCards = game.getCardsUsed();
110:                Vector dropCards = game.getDropCards();
111:                String but[] = { "DROP", "DROP", "DROP", "DROP", "DROP" };
112:
113:                Dealer dealer = DealerFactory
114:                        .getDealer("poker.business.DealerImpl");
115:                String flag;
116:
117:                if (game.getPlayRound() == 3) {
118:                    theseCards = dealer.drawMoreCards(theseCards, dropCards);
119:                    for (int i = 0; i < 5; i++) {
120:                        flag = (String) dropCards.elementAt(i);
121:                        if (flag.equals("DROP")) {
122:                            dropCards.setElementAt("DEALT", i);
123:                        } else {
124:                            dropCards.setElementAt("HELD", i);
125:                        }
126:                    }
127:                }
128:
129:                Integer card[] = new Integer[5];
130:                String[] drop = new String[5];
131:
132:                for (int i = 0; i < 5; i++) {
133:                    HTMLImageElement image = null;
134:                    HTMLInputElement input = null;
135:                    card[i] = (Integer) theseCards.elementAt(i);
136:                    String srcImage = "../media/" + card[i].toString() + ".gif";
137:                    drop[i] = (String) dropCards.elementAt(i);
138:
139:                    //      page.data.set("drop" + n, drop[i]);  ? gde ovo smestiti na html strani
140:                    switch (i) {
141:                    case 0: {
142:                        image = firstDeal0.getElementCard1();
143:                        image.setSrc(srcImage);
144:                        image = firstDeal0.getElementCard11();
145:                        image.setSrc(srcImage);
146:
147:                        input = firstDeal0.getElementBut1();
148:                        if (drop[i] != "DROP") {
149:                            but[i] = "DROP";
150:                        }
151:                        input.setValue(but[i]);
152:                        break;
153:                    }
154:                    case 1: {
155:                        image = firstDeal0.getElementCard2();
156:                        image.setSrc(srcImage);
157:                        image = firstDeal0.getElementCard22();
158:                        image.setSrc(srcImage);
159:
160:                        input = firstDeal0.getElementBut2();
161:                        if (drop[i] != "DROP") {
162:                            but[i] = "DROP";
163:                        }
164:                        input.setValue(but[i]);
165:                        break;
166:                    }
167:                    case 2: {
168:                        image = firstDeal0.getElementCard3();
169:                        image.setSrc(srcImage);
170:                        image = firstDeal0.getElementCard33();
171:                        image.setSrc(srcImage);
172:
173:                        input = firstDeal0.getElementBut3();
174:                        if (drop[i] != "DROP") {
175:                            but[i] = "DROP";
176:                        }
177:                        input.setValue(but[i]);
178:                        break;
179:                    }
180:                    case 3: {
181:                        image = firstDeal0.getElementCard4();
182:                        image.setSrc(srcImage);
183:                        image = firstDeal0.getElementCard44();
184:                        image.setSrc(srcImage);
185:
186:                        input = firstDeal0.getElementBut4();
187:                        if (drop[i] != "DROP") {
188:                            but[i] = "DROP";
189:                        }
190:                        input.setValue(but[i]);
191:                        break;
192:                    }
193:                    case 4: {
194:                        image = firstDeal0.getElementCard5();
195:                        image.setSrc(srcImage);
196:                        image = firstDeal0.getElementCard55();
197:                        image.setSrc(srcImage);
198:
199:                        input = firstDeal0.getElementBut5();
200:                        if (drop[i] != "DROP") {
201:                            but[i] = "DROP";
202:                        }
203:                        input.setValue(but[i]);
204:                        break;
205:                    }
206:                    }
207:                }
208:            }
209:
210:            public void startGame(HttpPresentationComms comms0,
211:                    FirstDealHTML firstDeal0) throws Exception {
212:                Dealer dealer = DealerFactory
213:                        .getDealer("poker.business.DealerImpl");
214:                PokerGame game = (PokerGame) comms0.session.getSessionData()
215:                        .get("game");
216:                Poker mainApp = (Poker) comms0.session.getSessionData().get(
217:                        "app");
218:                GameManager gameManager = mainApp.getGameManager();
219:                if ((game.getBet() < game.getSmallestBet())
220:                        | (game.getSmallestBet() == 0)) {
221:                    game.setSmallestBet(game.getBet());
222:                }
223:                if (game.getBet() > game.getLargestBet()) {
224:                    game.setLargestBet(game.getBet());
225:                }
226:                if (game.getPlayRound() == 3) {
227:                    game.setPlayRound(4);
228:                }
229:                String dl = (String) comms0.request.getParameter("DROP1");
230:                if ((dl != null) & (game.getPlayRound() < 4)) {
231:                    game.setPlayRound(3);
232:                }
233:                if (game.getPlayRound() == 1) {
234:                    game.setCardsInHand(dealer.dealFiveCards());
235:                    game.setPlayRound(2);
236:                }
237:                String d[] = { "DROP", "DROP", "DROP", "DROP", "DROP" };
238:                String iS = "";
239:                for (int i = 0; i < 5; i++) {
240:                    iS = Integer.toString(i + 1);
241:                    if ((String) comms0.request.getParameter("DROP" + iS) != null) {
242:                        d[i] = (String) comms0.request
243:                                .getParameter("DROP" + iS);
244:                    }
245:                }
246:
247:                Vector dropCards = game.getDropCards();
248:
249:                for (int i = 0; i < 5; i++) {
250:                    String n = Integer.toString(i + 1);
251:                    if (d[i].equals("HOLD")) {
252:                        dropCards.setElementAt("HOLD", i);
253:                    }
254:                    if (d[i].equals("DROP")) {
255:                        dropCards.setElementAt("DROP", i);
256:                    }
257:                }
258:
259:                firstDeal0.setTextName(game.getName());
260:                firstDeal0.setTextCash(Integer.toString(game.getCash()));
261:                firstDeal0.setTextBet(Integer.toString(game.getBet()));
262:                firstDeal0.setTextRank(Integer.toString(gameManager
263:                        .getRank(game.getCash())));
264:                firstDeal0.setTextHandsPlayed(Integer.toString(game
265:                        .getTotalPlayed()));
266:                firstDeal0.setTextWon(Integer.toString(game.getTotalWon()));
267:
268:                //gameManager.updateGame(game);
269:            }
270:
271:            static public void checkHand(HttpPresentationComms comms0,
272:                    FirstDealHTML firstDeal0) throws Exception {
273:                Dealer dealer = DealerFactory
274:                        .getDealer("poker.business.DealerImpl");
275:                PokerGame game = (PokerGame) comms0.session.getSessionData()
276:                        .get("game");
277:                Vector theseCards = game.getCardsInHand();
278:                String handTotal = dealer.checkHand(theseCards);
279:                int payRate = dealer.getPayout(handTotal);
280:                String message = handTotal + ",   pays $"
281:                        + new Integer(payRate * game.getBet()).toString()
282:                        + " (" + new Integer(payRate).toString() + " to 1)";
283:                firstDeal0.setTextResult(message);
284:
285:                if (game.getPlayRound() > 2) {
286:                    if (game.getCash() == 0) {
287:                        Poker app = (Poker) comms0.session.getSessionData()
288:                                .get("app");
289:                        GameManager g = app.getGameManager();
290:                        g.setTotalBankrupt(+1);
291:                    }
292:                    Poker mainApp = (Poker) comms0.session.getSessionData()
293:                            .get("app");
294:                    GameManager g = mainApp.getGameManager();
295:                    if (game.getPlayRound() == 3) {
296:                        if (payRate > 0) {
297:                            game.setTotalWon(game.getTotalWon() + 1);
298:                        }
299:                        if (payRate > 0) {
300:                            g.setTotalHandsWon(1);
301:                        }
302:                        g.setTotalDollars(-(game.getBet() * payRate));
303:                        game
304:                                .setCash(game.getCash()
305:                                        + (game.getBet() * payRate));
306:                        firstDeal0
307:                                .setTextCash(Integer.toString(game.getCash()));
308:                    }
309:                    g.updateGame(game);
310:                }
311:            }
312:
313:            static public boolean isLastDeal(HttpPresentationComms comms0)
314:                    throws Exception {
315:                PokerGame game = (PokerGame) comms0.session.getSessionData()
316:                        .get("game");
317:                if (game.getPlayRound() > 2) {
318:                    return true;
319:                } else {
320:                    return false;
321:                }
322:            }
323:
324:            static public boolean isBankrupt(HttpPresentationComms comms0)
325:                    throws Exception {
326:                PokerGame game = (PokerGame) comms0.session.getSessionData()
327:                        .get("game");
328:                if ((game.getCash() == 0) & (game.getPlayRound() == 3)) {
329:                    return true;
330:                } else {
331:                    return false;
332:                }
333:            }
334:
335:            static public void getMarker(HttpPresentationComms comms0,
336:                    FirstDealHTML firstDeal0) throws Exception {
337:                PokerGame game = (PokerGame) comms0.session.getSessionData()
338:                        .get("game");
339:                Vector drops = game.getDropCards();
340:                String marker = (String) drops.elementAt(pointer);
341:                HTMLImageElement image = null;
342:
343:                switch (pointer) {
344:                case 0: {
345:                    image = firstDeal0.getElementGetMarker1();
346:                    break;
347:                }
348:                case 1: {
349:                    image = firstDeal0.getElementGetMarker2();
350:                    break;
351:                }
352:                case 2: {
353:                    image = firstDeal0.getElementGetMarker3();
354:                    break;
355:                }
356:                case 3: {
357:                    image = firstDeal0.getElementGetMarker4();
358:                    break;
359:                }
360:                case 4: {
361:                    image = firstDeal0.getElementGetMarker5();
362:                    break;
363:                }
364:                }
365:
366:                if ((marker.equals("DROP")) | (marker.equals("DEALT"))) {
367:                    image.setSrc("../media/draw_n.gif");
368:                    image.setName("\"but" + Integer.toString(pointer + 1));
369:                } else {
370:                    image.setSrc("../media/hold_n.gif");
371:                    image.setName("\"but" + Integer.toString(pointer + 1));
372:                }
373:
374:                pointer++;
375:                if (pointer == 5) {
376:                    pointer = 0;
377:                }
378:            }
379:
380:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.