示例#1
0
  public static Puzzle parsePuzzle(File file) throws Exception {
    Puzzle puzzle = new Puzzle();

    String[] data = readData(file, "#");
    // remove empty space at the end of each line
    for (int j = 0; j < data.length; j++) {
      data[j] = data[j].trim();
    }
    // Set Puzzle Size
    String size = data[0];
    puzzle.setSize(Integer.valueOf(size));

    // Set Puzzle Category
    puzzle.setGameCategory(data[1]);

    // Set Puzzle Number
    puzzle.setPuzzleNumber(data[2]);

    // Parse QuestionAndAnswer Section
    QuestionAndAnswer across[] = new QuestionAndAnswer[puzzle.getSize() * puzzle.getSize() + 1];
    QuestionAndAnswer down[] = new QuestionAndAnswer[puzzle.getSize() * puzzle.getSize() + 1];
    int i = 3;
    while (i < data.length && data[i] != null) {
      parseQuestionAndAnswer(data[i], across, down);
      i++;
    }

    puzzle.setAcross(across);
    puzzle.setDown(down);
    puzzle.setPuzzleID();
    puzzle.setSolution();

    return puzzle;
  }