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); }
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); }
public void joinGame(int gameIndex) throws RemoteException, FullGameException, GameNotFoundException, InvalidSessionException, AlreadyInGameException { final GameInfo info = mOpenGameListModel.getGameAt(gameIndex); srvAdapter.joinGame(usrMgr.getSession(), info); }