Пример #1
0
 public void updateERSCounter() {
   ServerAccess.incrementERSCounter(new UpdateGameRequest(gameId, null));
   obj = ServerAccess.getCardGame(gameId);
   if (obj != null) {
     currentGame = (CardGame) obj;
   }
 }
Пример #2
0
  public void leaveGameLobby(CardGameType gameType, int lobbyId) {
    GameLobbyRequest glr = new GameLobbyRequest(player, lobbyId, gameType);
    isInLobby = false;
    setCurrentLobby(null, -1);
    ServerAccess.leaveLobby(glr);

    if (gameType == CardGameType.War) {
      obj = ServerAccess.getGameLobbyList(glr);
      if (obj != null) {
        warLobbies = (GameLobby[]) obj;
      }
    } else if (gameType == CardGameType.TexasHoldEm) {
      obj = ServerAccess.getGameLobbyList(glr);
      if (obj != null) {
        texasHoldemLobbies = (GameLobby[]) obj;
      }
    } else if (gameType == CardGameType.ERS) {
      obj = ServerAccess.getGameLobbyList(glr);
      if (obj != null) {
        ratscrewLobbies = (GameLobby[]) obj;
      }
    }

    return;
  }
Пример #3
0
 @SuppressWarnings("unchecked")
 public void removeFriend(String username) {
   Object isSuccess = ServerAccess.removeFriend(new NewFriendRequest(player, username));
   if (isSuccess != null && (boolean) isSuccess) {
     obj = ServerAccess.getFriends(player);
     if (obj != null) {
       friendList = (ArrayList<Friend>) obj;
     }
   }
 }
Пример #4
0
 // MAIN UPDATE FUNCTION
 public void updateGame() {
   // if (currentGame.updateReady()) {
   System.out.println("game is updating");
   // currentGame.update();
   ServerAccess.updateCardGameState(gameId, currentGame);
   obj = ServerAccess.getCardGame(gameId);
   if (obj != null) {
     currentGame = (CardGame) obj;
   }
   // }
 }
Пример #5
0
 @SuppressWarnings("unchecked")
 public boolean addChatEntry(String message) {
   ChatEntry newEntry = new ChatEntry(player.userName, message);
   Object isSuccess = ServerAccess.addMenuChatEntry(newEntry);
   if (isSuccess != null && (boolean) isSuccess) {
     obj = ServerAccess.getMenuChat();
     if (obj != null) {
       menuChat = (ArrayList<ChatEntry>) obj;
     }
     return (boolean) isSuccess;
   }
   return false;
 }
Пример #6
0
 /**
  * ******************************************************* Game mgmt model calls.
  * *******************************************************
  */
 public boolean enterGameFromLobby(int gameId) {
   obj = ServerAccess.getCardGame(gameId);
   if (obj != null) {
     currentGame = (CardGame) obj;
     setGameId(gameId);
     isInGame = true;
     gameType = currentLobbyType;
     leaveGameLobby(currentLobbyType, currentLobbyNumber);
     ServerAccess.incrementNumGames(new AchievementRequest(player, gameType));
     return true;
   }
   return false;
 }
Пример #7
0
 /**
  * ******************************************************* Account mgmt model calls.
  * *******************************************************
  */
 public boolean createAccountRequest(String username, String password, String email) {
   NewPlayerRequest accountRequest = new NewPlayerRequest(username, password, email);
   if (ServerAccess.createNewAccount(accountRequest) != null) {
     return true;
   }
   return false;
 }
Пример #8
0
  public boolean createGameRequest(CardGameType gameType) {

    if (gameType == CardGameType.War) {
      currentGame = new War(player);
    } else if (gameType == CardGameType.Blackjack) {
      currentGame = new BlackJack();
    }

    obj = ServerAccess.createNewGame(currentGame);
    if (obj != null && (gameId = (int) obj) != -1) {
      ServerAccess.incrementNumGames(new AchievementRequest(player, gameType));
      isInGame = true;
      return true;
    }
    return false;
  }
Пример #9
0
 public float getServerWinRatio(CardGameType gameType, Player player) {
   obj = ServerAccess.getWinRatio(new AchievementRequest(player, gameType));
   if (obj != null) {
     return (float) obj;
   } else {
     return 0;
   }
 }
Пример #10
0
 public int getServerNumberOfGames(CardGameType gameType, Player player) {
   obj = ServerAccess.getNumGames(new AchievementRequest(player, gameType));
   if (obj != null) {
     return (int) obj;
   } else {
     return 0;
   }
 }
Пример #11
0
 public boolean requestPassword(String username, String emailAddress) {
   obj = ServerAccess.retrievePassword(new NewPlayerRequest(username, "pass", emailAddress));
   if (obj == null) {
     return false;
   } else {
     return true;
   }
 }
Пример #12
0
 public boolean setNewPassword(String oldPassword, String newPassword) {
   obj = ServerAccess.setPassword(new SetPasswordRequest(player, oldPassword, newPassword));
   if (obj == null) {
     return false;
   } else {
     return true;
   }
 }
Пример #13
0
 /**
  * ******************************************************* Game chat mgmt model calls.
  * *******************************************************
  */
 public void addGameChatEntry(String message, int i) {
   if (!isInGame || currentGame == null) {
     return;
   }
   ChatEntry newEntry;
   if (i == 0) {
     newEntry = new ChatEntry(player.userName, message);
   } else {
     newEntry = new ChatEntry("Dealer", message);
   }
   currentGame.addChatEntry(newEntry);
   obj = ServerAccess.updateCardGameState(gameId, currentGame);
   if (obj != null) {
     obj = ServerAccess.getCardGame(gameId);
     if (obj != null) {
       currentGame = (CardGame) obj;
     }
   }
 }
Пример #14
0
  public void startGameFromLobby() {
    GameLobbyRequest glr = null;
    if (currentLobbyType == CardGameType.War) {
      glr = new GameLobbyRequest(player, currentLobbyNumber, CardGameType.War);
    } else if (currentLobbyType == CardGameType.TexasHoldEm) {
      glr = new GameLobbyRequest(player, currentLobbyNumber, CardGameType.TexasHoldEm);

    } else if (currentLobbyType == CardGameType.ERS) {
      glr = new GameLobbyRequest(player, currentLobbyNumber, CardGameType.ERS);
    }
    ServerAccess.startGameFromLobby(glr);
  }
Пример #15
0
  public boolean joinPersistantTable(int tableNumber, CardGameType gameType) {
    if (gameType == CardGameType.Blackjack) {
      GameLobbyRequest glr = new GameLobbyRequest(player, tableNumber, CardGameType.Blackjack);
      Object obj = ServerAccess.joinPersistantLobby(glr);
      if (obj != null && (int) obj != -1) {
        gameId = (int) obj;

        obj = ServerAccess.getCardGame(gameId);
        if (obj != null) {
          isInGame = true;
          currentGame = (CardGame) obj;
          System.out.println("hey there");
          gameType = CardGameType.Blackjack;
          return true;
        }
      } else {
        return false;
      }
    }
    return false;
  }
Пример #16
0
  @SuppressWarnings("unchecked")
  public boolean attemptLogin(String username, String password) {
    NewPlayerRequest loginRequest = new NewPlayerRequest(username, password, null);
    obj = ServerAccess.loginRequest(loginRequest);
    if (obj != null) {
      player = (Player) obj;

      isLoggedIn = true;

      obj = ServerAccess.getFriends(player);
      if (obj != null) {
        friendList = (ArrayList<Friend>) obj;
      }

      obj = ServerAccess.getMenuChat();
      if (obj != null) {
        menuChat = (ArrayList<ChatEntry>) obj;
      }

      /* Server calls to initialize stats */
      updateAchievements();
      obj = ServerAccess.getGameLobbyList(new GameLobbyRequest(null, 0, CardGameType.War));
      if (obj != null) {
        warLobbies = (GameLobby[]) obj;
      }

      obj = ServerAccess.getGameLobbyList(new GameLobbyRequest(null, 0, CardGameType.ERS));
      if (obj != null) {
        ratscrewLobbies = (GameLobby[]) obj;
      }

      obj = ServerAccess.getGameLobbyList(new GameLobbyRequest(null, 0, CardGameType.TexasHoldEm));
      if (obj != null) {
        texasHoldemLobbies = (GameLobby[]) obj;
      }

      obj = ServerAccess.getBlackJackTables();
      if (obj != null) {
        blackJackTables = (BlackJack[]) obj;
      }

      /*
       * Initialize thread that will periodically ask server for updates
       * to update model
       */
      UpdateChecker updateChecker = new UpdateChecker(this);
      Thread t = new Thread(updateChecker);
      t.start();

      return true;
    }
    return false;
  }
Пример #17
0
  public boolean logout() {
    if (isInGame && gameType == CardGameType.Blackjack) {
      System.out.println("??");
      ((BlackJack) currentGame).removePlayer(player);
      updateGame();
    } else if (isInLobby) {
      leaveGameLobby(currentLobbyType, currentLobbyNumber);
    }

    Object isSuccess = ServerAccess.logoutRequest(player);
    if (isSuccess == null) {
      return false;
    }
    isLoggedIn = false;
    return (boolean) isSuccess;
  }
Пример #18
0
  /**
   * ******************************************************* Achievement model calls.
   * *******************************************************
   */
  public ArrayList<String> getLeaderboards(CardGameType gameType) {
    String criteria = null;
    if (gameType == CardGameType.War) {
      criteria = "wins_war";
    } else if (gameType == CardGameType.TexasHoldEm) {
      criteria = "wins_holdem";
    } else if (gameType == CardGameType.Blackjack) {
      criteria = "wins_blackjack";
    } else if (gameType == CardGameType.ERS) {
      // criteria = "wins_ers";
    } else {
      return new ArrayList<String>();
    }

    Object obj = ServerAccess.getLeaderboard(criteria);
    if (obj != null) {
      return (ArrayList<String>) obj;
    }
    return new ArrayList<String>();
  }
Пример #19
0
  /**
   * ******************************************************* Game lobby mgmt model calls.
   * *******************************************************
   */
  public void joinGameLobby(CardGameType gameType, int lobbyId) {
    GameLobbyRequest glr = new GameLobbyRequest(player, lobbyId, gameType);

    if (gameType == CardGameType.War) {
      /* Check for space in lobby */
      if (warLobbies[lobbyId].getPlayers().size() < 2) {
        isInLobby = true;
        setCurrentLobby(gameType, lobbyId);
        ServerAccess.joinLobby(glr);

        obj = ServerAccess.getGameLobbyList(glr);
        if (obj != null) {
          warLobbies = (GameLobby[]) obj;
        }
      }
    } else if (gameType == CardGameType.TexasHoldEm) {
      if (texasHoldemLobbies[lobbyId].getPlayers().size() < 4) {
        isInLobby = true;
        setCurrentLobby(gameType, lobbyId);
        ServerAccess.joinLobby(glr);

        obj = ServerAccess.getGameLobbyList(glr);
        if (obj != null) {
          texasHoldemLobbies = (GameLobby[]) obj;
        }
      }
    } else if (gameType == CardGameType.ERS) {
      System.out.println("hello");
      if (ratscrewLobbies[lobbyId].getPlayers().size() < 2) {
        isInLobby = true;
        setCurrentLobby(gameType, lobbyId);
        ServerAccess.joinLobby(glr);

        obj = ServerAccess.getGameLobbyList(glr);
        if (obj != null) {
          ratscrewLobbies = (GameLobby[]) obj;
        }
      }
    }
    return;
  }
Пример #20
0
 public void incrementNumberOfWins(CardGameType gameType) {
   ServerAccess.incrementNumWins(new AchievementRequest(player, gameType));
 }