001: package poker.business;
002:
003: import java.util.Vector;
004: import java.sql.SQLException;
005: import poker.data.user.*;
006: import poker.data.game.*;
007: import poker.business.GameList;
008: import poker.spec.*;
009:
010: /**
011: *
012: * EnhyDraw!, beta 4, 5/21/99
013: *
014: * Copyright 1999, Larry Wolcot & Daryl Tempesta
015: * ALL rights reserved. Not for commercial use
016: * without written permission from both authors.
017: *
018: * This class is a basic wrapper for the BDO's (like GameList)
019: * It manages all of the active cardGames, PitBoss Statistics, etc.
020: */
021: public class GameManagerImpl implements GameManager,
022: java.io.Serializable {
023:
024: private PokerGame game;
025: private GameList gameList = new GameList(0);
026: private PitBossListImpl pitBossList = new PitBossListImpl();
027: private String appName = "Poker";
028:
029: /**
030: * Set the useDB flag in the GameList object. If useDB is false,
031: * the GameList object will use a standard Vector (in memory)
032: * to hold all of the active PokerGame objects. if useDB is set to
033: * true, it will mirror the Vector's elements into the database.
034: */
035: public void setUseDB(boolean useDB) throws Exception {
036: try {
037: gameList.setUseDB(useDB);
038: //PitBoss persistance is not finished
039: pitBossList.setUseDB(useDB);
040: } catch (Exception e) {
041: throw e;
042: }
043: }
044:
045: /**
046: * Total number of players sent to the poor house!
047: */
048: public String getTotalBankrupt() {
049: //String ret = new Integer(totalBankrupt).toString();
050: //return ret;
051: int total = 0;
052: total = pitBossList.getPitBossVDO(appName).getTotalBankrupt();
053: return new Integer(total).toString();
054: }
055:
056: /**
057: * Total dollars the house has won/lost
058: */
059: public String getHouseProfit() {
060: int total = 0;
061: total = pitBossList.getPitBossVDO(appName).getTotalDollars();
062: return new Integer(total).toString();
063: }
064:
065: /**
066: * Check the active gameList and return total number of players
067: */
068: public String getTotalPlayers() {
069: String ret = new Integer(gameList.getCount()).toString();
070: return ret;
071: }
072:
073: /**
074: * Total number hands dealt
075: */
076: public String getTotalHandsDealt() {
077: int total = 0;
078: total = pitBossList.getPitBossVDO(appName).getTotalHandsDealt();
079: return new Integer(total).toString();
080: }
081:
082: /**
083: * Total number of hands won by all players
084: */
085: public String getTotalHandsWon() {
086: int total = 0;
087: total = pitBossList.getPitBossVDO(appName).getTotalHandsWon();
088: return new Integer(total).toString();
089: }
090:
091: /**
092: * Total number of hands lost by all players
093: */
094: public String getTotalHandsLost() {
095: int totalWon = 0;
096: int totalPlayed = 0;
097: totalWon = pitBossList.getPitBossVDO(appName)
098: .getTotalHandsWon();
099: totalPlayed = pitBossList.getPitBossVDO(appName)
100: .getTotalHandsDealt();
101: return new Integer(totalPlayed - totalWon).toString();
102: }
103:
104: /**
105: * Incriment totalHandsWon by n
106: */
107: public synchronized void setTotalHandsWon(int n) {
108: synchronized (pitBossList) {
109: n = n
110: + pitBossList.getPitBossVDO(appName)
111: .getTotalHandsWon();
112: pitBossList.getPitBossVDO(appName).setTotalHandsWon(n);
113: }
114: }
115:
116: /**
117: * Incriment totalBankrupt by n
118: */
119: public synchronized void setTotalBankrupt(int n) {
120: synchronized (pitBossList) {
121: n = n
122: + pitBossList.getPitBossVDO(appName)
123: .getTotalBankrupt();
124: pitBossList.getPitBossVDO(appName).setTotalBankrupt(n);
125: }
126: }
127:
128: /**
129: * Incriment totalHandsDealt by n
130: */
131: public synchronized void setHandsDealt(int n) {
132: synchronized (pitBossList) {
133: n = n
134: + pitBossList.getPitBossVDO(appName)
135: .getTotalHandsDealt();
136: pitBossList.getPitBossVDO(appName).setTotalHandsDealt(n);
137: }
138: }
139:
140: /**
141: * Incriment totalDollars (won) by n
142: */
143: public synchronized void setDollars(int n) {
144: synchronized (pitBossList) {
145: n = n
146: + pitBossList.getPitBossVDO(appName)
147: .getTotalDollars();
148: pitBossList.getPitBossVDO(appName).setTotalDollars(n);
149: }
150: }
151:
152: /**
153: * same as setDollars
154: */
155: public synchronized void setTotalDollars(int n) {
156: setDollars(n);
157: }
158:
159: /**
160: * Return a (COPY)list of active games
161: */
162: public synchronized Vector getGameList() {
163: GameList gameListCopy = this .gameList.getCopy();
164: return gameListCopy;
165: }
166:
167: /**
168: * Return the size() of gameList
169: */
170: public synchronized int getCount() {
171: return gameList.getCount();
172: }
173:
174: /**
175: * return the top ten players ranked by cash won
176: */
177: public synchronized Vector getTopTen() {
178: Vector topTen = null;
179:
180: topTen = gameList.getTopTen();
181:
182: return topTen;
183:
184: }
185:
186: /**
187: * Check to see if this name has been used
188: */
189: public synchronized boolean getIsNameUsed(String name) {
190: boolean isUsed = false;
191:
192: if (gameList.getIsNameUsed(name)) {
193: isUsed = true;
194: }
195:
196: return isUsed;
197: }
198:
199: /**
200: * Authenticate user against gameList object
201: */
202: public synchronized boolean authenticate(String name, String pw) {
203: boolean isAuth = false;
204:
205: if (gameList.authenticate(name, pw)) {
206: isAuth = true;
207: }
208: return isAuth;
209: }
210:
211: /**
212: * Return the game that belongs to user name String
213: */
214: public synchronized PokerGame getGame(String name) {
215: PokerGame this Game = null;
216:
217: this Game = gameList.getGame(name);
218:
219: return this Game;
220: }
221:
222: /**
223: * Add a game to the gameList
224: */
225: public synchronized void addGame(PokerGame newGame) {
226: //lock gameList object for TOTAL threadsave opps
227: //This is OK for less intense apps like this one,
228: //but not the best way to go for high transaction
229: //DB volumes
230: synchronized (gameList) {
231: gameList.addGame(newGame);
232: }
233: }
234:
235: /**
236: * get rank of current dollars compared to the gameList
237: */
238: public synchronized int getRank(int cash) {
239: int rank = gameList.getRank(cash);
240: return rank;
241: }
242:
243: /**
244: * remove thisGame from the gameList
245: */
246: public synchronized void removeGame(String name) {
247: gameList.removeGame(name);
248: }
249:
250: /**
251: * Make sure the DB gets updated if this is a DODS object
252: */
253: public synchronized void updateGame(PokerGame thisGame) {
254: gameList.updateGame(thisGame);
255: }
256:
257: }
|