1 package poker.business; 2 3 import java.util.Vector ; 4 import java.sql.SQLException ; 5 import poker.data.user.*; 6 import poker.data.game.*; 7 import poker.business.GameList; 8 import poker.spec.*; 9 20 public class GameManagerImpl implements GameManager,java.io.Serializable { 21 22 private PokerGame game; 23 private GameList gameList = new GameList(0); 24 private PitBossListImpl pitBossList = new PitBossListImpl(); 25 private String appName = "Poker"; 26 27 33 public void setUseDB(boolean useDB) throws Exception { 34 try { 35 gameList.setUseDB(useDB); 36 pitBossList.setUseDB(useDB); 38 } catch (Exception e) { 39 throw e; 40 } 41 } 42 43 46 public String getTotalBankrupt(){ 47 int total = 0; 50 total = pitBossList.getPitBossVDO(appName).getTotalBankrupt(); 51 return new Integer (total).toString(); 52 } 53 54 57 public String getHouseProfit(){ 58 int total = 0; 59 total = pitBossList.getPitBossVDO(appName).getTotalDollars(); 60 return new Integer (total).toString(); 61 } 62 63 66 public String getTotalPlayers(){ 67 String ret= new Integer (gameList.getCount()).toString(); 68 return ret; 69 } 70 71 74 public String getTotalHandsDealt(){ 75 int total = 0; 76 total = pitBossList.getPitBossVDO(appName).getTotalHandsDealt(); 77 return new Integer (total).toString(); 78 } 79 80 83 public String getTotalHandsWon(){ 84 int total = 0; 85 total = pitBossList.getPitBossVDO(appName).getTotalHandsWon(); 86 return new Integer (total).toString(); 87 } 88 89 92 public String getTotalHandsLost(){ 93 int totalWon = 0; 94 int totalPlayed = 0; 95 totalWon = pitBossList.getPitBossVDO(appName).getTotalHandsWon(); 96 totalPlayed = 97 pitBossList.getPitBossVDO(appName).getTotalHandsDealt(); 98 return new Integer (totalPlayed - totalWon).toString(); 99 } 100 101 104 public synchronized void setTotalHandsWon(int n) { 105 synchronized(pitBossList) { 106 n = n + pitBossList.getPitBossVDO(appName).getTotalHandsWon(); 107 pitBossList.getPitBossVDO(appName).setTotalHandsWon(n); 108 } 109 } 110 111 114 public synchronized void setTotalBankrupt(int n){ 115 synchronized(pitBossList){ 116 n = n + pitBossList.getPitBossVDO(appName).getTotalBankrupt(); 117 pitBossList.getPitBossVDO(appName).setTotalBankrupt(n); 118 } 119 } 120 121 124 public synchronized void setHandsDealt(int n){ 125 synchronized(pitBossList){ 126 n = n +pitBossList.getPitBossVDO(appName).getTotalHandsDealt(); 127 pitBossList.getPitBossVDO(appName).setTotalHandsDealt(n); 128 } 129 } 130 131 134 public synchronized void setDollars(int n){ 135 synchronized(pitBossList){ 136 n = n + pitBossList.getPitBossVDO(appName).getTotalDollars(); 137 pitBossList.getPitBossVDO(appName).setTotalDollars(n); 138 } 139 } 140 141 144 public synchronized void setTotalDollars(int n){ 145 setDollars(n); 146 } 147 148 151 public synchronized Vector getGameList(){ 152 GameList gameListCopy = this.gameList.getCopy(); 153 return gameListCopy; 154 } 155 156 159 public synchronized int getCount(){ 160 return gameList.getCount(); 161 } 162 163 166 public synchronized Vector getTopTen(){ 167 Vector topTen = null; 168 169 topTen = gameList.getTopTen(); 170 171 return topTen; 172 173 } 174 175 178 public synchronized boolean getIsNameUsed(String name){ 179 boolean isUsed = false; 180 181 if (gameList.getIsNameUsed(name)) { isUsed = true; } 182 183 return isUsed; 184 } 185 186 189 public synchronized boolean authenticate(String name, String pw){ 190 boolean isAuth = false; 191 192 if (gameList.authenticate(name, pw)) { 193 isAuth = true; 194 } 195 return isAuth; 196 } 197 198 201 public synchronized PokerGame getGame(String name) { 202 PokerGame thisGame = null; 203 204 thisGame = gameList.getGame(name); 205 206 return thisGame; 207 } 208 209 212 public synchronized void addGame(PokerGame newGame){ 213 synchronized(gameList){ 218 gameList.addGame(newGame); 219 } 220 } 221 222 225 public synchronized int getRank(int cash){ 226 int rank = gameList.getRank(cash); 227 return rank; 228 } 229 230 233 public synchronized void removeGame(String name){ 234 gameList.removeGame(name); 235 } 236 237 240 public synchronized void updateGame(PokerGame thisGame){ 241 gameList.updateGame(thisGame); 242 } 243 244 } 245 | Popular Tags |