Ejemplo n.º 1
0
  public Game makeGameFromInput(String gameTitle, String gameRanking, String gameRules) {
    Game currentGame = new Game();
    currentGame.setGameTitle(gameTitle);

    if (checkNumberFormat(gameRanking)) {
      currentGame.setFunRanking(Integer.parseInt(gameRanking));
    } else {
      return null;
    }

    String[] temp = gameRules.split("\n");
    ArrayList<String> tempRules = new ArrayList<String>();

    for (String tempWord : temp) {
      tempRules.add(tempWord);
    }
    currentGame.setGameRules(tempRules);

    return currentGame;
  }
Ejemplo n.º 2
0
  public void saveGameInformation(Game currentGame) {

    PrintWriter gameWriter;
    String saveFile = "save file.txt";

    try {
      // Creates the save file.
      gameWriter = new PrintWriter(saveFile);

      gameWriter.append(currentGame.getGameTitle() + "\n");
      gameWriter.append(currentGame.getFunRanking() + "\n");
      for (int count = 0; count < currentGame.getGameRules().size(); count++) {
        gameWriter.append(currentGame.getGameRules().get(count) + "\n");
      }
      gameWriter.append(" ;" + "\n");
      // Required to prevent corruption of data and maintain the security
      // of the file.
      gameWriter.close();
    } catch (FileNotFoundException noFileExists) {
      JOptionPane.showMessageDialog(appFrame, "Could not create the save file. :");
      JOptionPane.showMessageDialog(appFrame, noFileExists.getMessage());
    }
  }