Beispiel #1
0
  public void updateGameList() throws RemoteException, InvalidSessionException {
    final String user = usrMgr.getSession().getUser();
    final ArrayList<GameInfo> fullList = srvAdapter.fetchGameList(usrMgr.getSession());
    final ArrayList<GameInfo> currentList = new ArrayList<GameInfo>();
    final ArrayList<GameInfo> openList = new ArrayList<GameInfo>();
    final Calendar now = Calendar.getInstance();
    final Calendar now2h = Calendar.getInstance();
    now2h.add(Calendar.HOUR, -2);

    for (final GameInfo info : fullList) {
      if (info.getPlayers().contains(user)) {
        for (final Calendar c : info.getGameSessions()) {
          if (c.before(now) && c.after(now2h)) {
            currentList.add(info);
            break;
          }
        }
      } else if (info.getnFreeTerritories() > 0) {
        for (final Calendar c : info.getGameSessions()) {
          if (c.after(now2h)) {
            openList.add(info);
            break;
          }
        }
      }
    }

    mCurrentGameListModel.setData(currentList);
    mOpenGameListModel.setData(openList);
  }
Beispiel #2
0
  public void createGame(
      String name,
      String description,
      ArrayList<Calendar> gameSessions,
      int turnTime,
      int defTime,
      int negTime)
      throws RemoteException, InvalidGameInfoException, InvalidSessionException {

    if (name == null) throw new NullPointerException();
    if (description == null) throw new NullPointerException();
    if (gameSessions == null) throw new NullPointerException();
    if (name.isEmpty()) throw new EmptyStringException();
    if (turnTime <= 0) throw new NegativeValueException();
    if (defTime <= 0) throw new NegativeValueException();
    if (negTime <= 0) throw new NegativeValueException();

    final ArrayList<String> listPlayer = new ArrayList<String>();
    listPlayer.add(usrMgr.getSession().getUser());
    srvAdapter.createGame(
        usrMgr.getSession(),
        new GameInfo(
            UUID.randomUUID(),
            name,
            description,
            listPlayer,
            gameSessions,
            42,
            turnTime,
            defTime,
            negTime));
    this.updateGameList();
  }
Beispiel #3
0
 public void connectToGame(int gameIndex, GameEventListener gameListener)
     throws RemoteException, GameNotFoundException, InvalidSessionException, InvalidTimeException,
         NotCurrentPlayerGameException, AlreadyInGameException {
   final GameInfo info = mCurrentGameListModel.getGameAt(gameIndex);
   final Session session = usrMgr.getSession();
   final Game game = srvAdapter.playGame(session, info);
   mGameEngine = new GameEngine(game, session, srvAdapter, gameListener);
   cltAdapter.setCallback(mGameEngine);
 }
Beispiel #4
0
 public void disconnectFromGame()
     throws RemoteException, GameNotFoundException, InvalidSessionException, InvalidTimeException,
         NotCurrentPlayerGameException {
   try {
     srvAdapter.quitGame(usrMgr.getSession(), mGameEngine.getGame());
     mGameEngine = null;
   } catch (final RemoteException e) {
     mGameEngine = null;
     throw e;
   } catch (final GameNotFoundException e) {
     mGameEngine = null;
     throw e;
   } catch (final InvalidSessionException e) {
     mGameEngine = null;
     throw e;
   } catch (final InvalidTimeException e) {
     mGameEngine = null;
     throw e;
   } catch (final NotCurrentPlayerGameException e) {
     mGameEngine = null;
     throw e;
   }
 }
Beispiel #5
0
 public void joinGame(int gameIndex)
     throws RemoteException, FullGameException, GameNotFoundException, InvalidSessionException,
         AlreadyInGameException {
   final GameInfo info = mOpenGameListModel.getGameAt(gameIndex);
   srvAdapter.joinGame(usrMgr.getSession(), info);
 }