コード例 #1
0
ファイル: GameDBHelper.java プロジェクト: ldumancas/KeepScore
  private void saveGameWithinTransaction(Game game, boolean updateDateSaved) {

    long dateSaved = updateDateSaved ? System.currentTimeMillis() : game.getDateSaved();
    game.setDateSaved(dateSaved);

    if (game.getId() != -1) {
      // game was already saved, so try to overwrite

      updateGame(game.getId(), game.getDateStarted(), game.getDateSaved(), game.getName());
    } else {
      // else create a new row in the table

      int newGameId = getMaxGameId() + 1;

      ContentValues contentValues = new ContentValues();

      contentValues.put(COLUMN_DATE_STARTED, game.getDateStarted());
      contentValues.put(COLUMN_DATE_SAVED, dateSaved);
      contentValues.put(COLUMN_NAME, game.getName());
      contentValues.put(COLUMN_ID, newGameId);
      contentValues.put(COLUMN_AUTOSAVED, 1); // legacy "autosaved" column
      // that must be specified

      db.insert(TABLE_GAMES, null, contentValues);

      game.setId(newGameId);
      log.d("new game id is %s", newGameId);
    }

    savePlayerScores(game.getId(), game.getPlayerScores());
  }
コード例 #2
0
ファイル: GameManager.java プロジェクト: RMIT/ConnectN
 public void removeGame(Game g) {
   GameInfo gi = map.get(g.getId());
   gi.epArr[0].close();
   epMap.remove(gi.epArr[0]);
   if (gi.epArr[1] != null) {
     gi.epArr[1].close();
     epMap.remove(gi.epArr[1]);
   }
   map.remove(g.getId());
   onGameListUpdate();
 }
コード例 #3
0
ファイル: GameActivity.java プロジェクト: RvanW/SpookyWords
  @TargetApi(Build.VERSION_CODES.KITKAT)
  public void switchLocaleLanguage(View view) {
    // detect which language is currently set and switch to the alternative
    String lang;
    if (Objects.equals(Locale.getDefault().getLanguage(), "en")) {
      lang = "nl";
    } else {
      lang = "en";
    }

    Locale locale = new Locale(lang);
    Locale.setDefault(locale);
    Configuration config = new Configuration();
    config.locale = locale;
    getBaseContext()
        .getResources()
        .updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());

    // store the language in sharedpreferences
    SharedPreferences prefs =
        this.getSharedPreferences(
            getResources().getString(R.string.preference_file_key), Context.MODE_PRIVATE);
    prefs.edit().putString("system_lang", lang).apply();

    // refresh activity for locale changes to take effect
    Bundle extras = new Bundle();
    extras.putSerializable("gameID", game.getId());
    extras.putBoolean("flag_EN", dictionaryEnglish);
    extras.putSerializable("p1", player1);
    extras.putSerializable("p2", player2);
    Intent i = new Intent(this, GameActivity.class).putExtras(extras);
    startActivity(i);
    this.finish();
  }
コード例 #4
0
ファイル: GameManager.java プロジェクト: RMIT/ConnectN
  public Game create(String name, int nValue, int dropNumber, EndPoint ep) {
    GameInfo gi = new GameInfo(name, nValue, dropNumber, ep);
    Game g = gi.game;

    map.put(g.getId(), gi);
    epMap.put(ep, gi);
    onGameListUpdate();
    return g;
  }
コード例 #5
0
ファイル: GameManager.java プロジェクト: RMIT/ConnectN
  public boolean addEndPoint(Game g, EndPoint ep) {
    if (epMap.containsKey(ep)) return false;
    GameInfo gi = map.get(g.getId());

    if (gi == null) return false;

    gi.epArr[1] = ep;
    epMap.put(ep, gi);
    return true;
  }
コード例 #6
0
ファイル: GameDBHelper.java プロジェクト: ldumancas/KeepScore
  private List<Game> convertToGames(Cursor cursor) {
    List<Game> result = new ArrayList<Game>();

    Game currentGame = null;

    while (cursor.moveToNext()) {

      int currentId = cursor.getInt(0);

      if (currentGame == null || currentGame.getId() != currentId) { // new
        // Game

        currentGame = new Game();
        currentGame.setId(currentId);
        currentGame.setDateStarted(cursor.getLong(1));
        currentGame.setDateSaved(cursor.getLong(2));
        currentGame.setName(cursor.getString(3));
        result.add(currentGame);
      }

      List<PlayerScore> playerScores = new ArrayList<PlayerScore>();

      // build up all the PlayerScores
      do {

        if (cursor.getInt(0) != currentId) {
          cursor.moveToPrevious(); // went too far
          break;
        }

        PlayerScore playerScore = new PlayerScore();

        playerScore.setId(cursor.getInt(4));
        playerScore.setName(cursor.getString(5));
        playerScore.setScore(cursor.getLong(6));
        playerScore.setPlayerNumber(cursor.getInt(7));
        playerScore.setHistory(
            Delta.fromJoinedStrings(
                StringUtil.nullToEmpty(cursor.getString(8)),
                StringUtil.nullToEmpty(cursor.getString(9))));
        playerScore.setLastUpdate(cursor.getLong(10));
        playerScore.setPlayerColor(PlayerColor.deserialize(cursor.getString(11)));
        playerScores.add(playerScore);

      } while (cursor.moveToNext());

      Collections.sort(playerScores, PlayerScore.sortByPlayerNumber());

      currentGame.setPlayerScores(playerScores);
    }

    return result;
  }
コード例 #7
0
ファイル: GameDBHelper.java プロジェクト: ldumancas/KeepScore
  public void deleteGame(Game game) {
    synchronized (GameDBHelper.class) {
      try {
        db.beginTransaction();

        int id = game.getId();
        db.delete(TABLE_GAMES, COLUMN_ID + "=" + id, null);
        db.delete(TABLE_PLAYER_SCORES, COLUMN_GAME_ID + "=" + id, null);

        db.setTransactionSuccessful();
      } finally {
        db.endTransaction();
      }
    }
  }
コード例 #8
0
ファイル: Utilities.java プロジェクト: nezbo/whatgame
  public static void startGameIntent(int targetIndex, ArrayList<Game> games, Context c) {
    Game target = games.get(targetIndex);

    Intent next = new Intent("dk.nezbo.bggrandom.GAME");
    Bundle bundle = new Bundle();
    bundle.putInt("id", target.getId());
    if (targetIndex > 0)
      bundle.putIntegerArrayList("previous", Utilities.getIds(games, 0, targetIndex - 1));
    if (targetIndex < games.size() - 1)
      bundle.putIntegerArrayList(
          "next", Utilities.getIds(games, targetIndex + 1, games.size() - 1));
    next.putExtras(bundle);

    c.startActivity(next);
  }
コード例 #9
0
  /**
   * Loads the game metadata from the game manager interface. Create a game for each game metadata
   * object. Since they initially aren't running, they all point to null threads.
   */
  private void loadGames() {
    GameManagerInterface gameManager = FlatfileGameManager.getDefaultGameManager();
    if (gameManager == null) {
      LOGGER.severe("Could not load the games in our game manager, the game manager was null.");
    } else {

      // Initialize our maps
      gameToThreadMap = new HashMap<Game, GamePlayingThread>();
      idToGameMap = new HashMap<String, Game>();

      // Can only add things from non-null game metadata list
      List<GameMetadata> gameMetadatas = gameManager.getGames();
      if (gameMetadatas != null) {
        for (GameMetadata metadata : gameMetadatas) {
          Game game = new Game(metadata);
          gameToThreadMap.put(game, new GamePlayingThread(game));
          idToGameMap.put(game.getId(), game);
        }
      }
    }
  }
コード例 #10
0
ファイル: UpdateController.java プロジェクト: Heigvd/Wegas
  @GET
  @Path("RestoreDebugTeams")
  public String restoreDebugTeams() {
    List<Game> findNoDebugTeamGames = this.findNoDebugTeamGames();
    int counter = 0;

    for (Game g : findNoDebugTeamGames) {
      logger.error("Restore Game: " + g.getName() + "/" + g.getId());
      DebugTeam dt = new DebugTeam();
      g.addTeam(dt);
      this.getEntityManager().persist(dt);
      g.getGameModel().propagateDefaultInstance(dt, true);
      this.getEntityManager().flush();
      if (++counter == 25) {
        break;
      }
    }

    Long remaining = this.countOrphans();
    return "OK" + (remaining > 0 ? "(still " + remaining + ")" : "");
  }
コード例 #11
0
ファイル: UpdateController.java プロジェクト: Heigvd/Wegas
  private String deleteDuplicata() {

    StringBuilder sb = new StringBuilder();

    String sql =
        "SELECT vi.gameScope, vi.game FROM VariableInstance vi WHERE vi.gameScope IS NOT NULL GROUP BY vi.gameScope.id, vi.game.id HAVING count(vi) > 1";
    Query createQuery = this.getEntityManager().createQuery(sql);

    List resultList = createQuery.getResultList();
    int i = 0;
    for (Object o : resultList) {
      Object[] array = (Object[]) o;
      GameScope scope = (GameScope) array[0];
      Game game = (Game) array[1];
      // VariableInstance variableInstance = scope.getVariableInstance(game);
      // System.out.println("DELETE: " + variableInstance);

      sb.append("DELETE: ");
      sb.append(i++);
      sb.append(". ");

      String sql2 =
          "SELECT vi from VariableInstance vi WHERE vi.gameScope.id = :scopeId and vi.game.id = :gameId";

      TypedQuery<VariableInstance> query2 =
          this.getEntityManager().createQuery(sql2, VariableInstance.class);
      query2.setHint(QueryHints.CACHE_USAGE, CacheUsage.DoNotCheckCache);
      // @QueryHint(name = QueryHints.CACHE_USAGE, value = CacheUsage.CheckCacheThenDatabase)

      query2.setParameter("scopeId", scope.getId());
      query2.setParameter("gameId", game.getId());

      List<VariableInstance> list = query2.getResultList();

      sb.append(list.get(0));
      sb.append(" SCOPE - TEAM " + scope.getId() + "   " + game.getId());

      sb.append(("<br />"));

      if (list.size() != 2) {
        sb.append("   -> NOT 2 but " + list.size());
      } else {

        VariableInstance get = list.get(0);
        VariableInstance get2 = list.get(1);
        if (get instanceof BooleanInstance) {
          if (((BooleanInstance) get).getValue() != ((BooleanInstance) get2).getValue()) {
            sb.append(("   -> NOT EQUALS"));
          } else {
            this.getEntityManager().remove(get2);
          }
        } else if (get instanceof NumberInstance) {
          if (((NumberInstance) get).getValue() != ((NumberInstance) get2).getValue()) {
            sb.append(("   -> NOT EQUALS"));
          } else {
            this.getEntityManager().remove(get2);
          }
        } else if (get instanceof StringInstance) {
          if (!((StringInstance) get).getValue().equals(((StringInstance) get2).getValue())) {
            sb.append(("   -> NOT EQUALS"));
          } else {
            this.getEntityManager().remove(get2);
          }
        }
      }
      sb.append(("<br />"));
    }
    return sb.toString();
  }
コード例 #12
0
ファイル: GameManager.java プロジェクト: RMIT/ConnectN
 public boolean isMaster(Game g, EndPoint ep) {
   GameInfo gi = map.get(g.getId());
   return gi.epArr[0].equals(ep);
 }
コード例 #13
0
ファイル: GameManager.java プロジェクト: RMIT/ConnectN
 public void dispatch(Game g, EndPoint ep, Message msg) {
   map.get(g.getId()).bus.dispatch(ep, msg);
 }
コード例 #14
0
ファイル: GameManager.java プロジェクト: RMIT/ConnectN
 public void subscribe(Game g, EndPoint ep, Class msgType) {
   map.get(g.getId()).bus.subscribe(ep, msgType);
 }