package WheelOfFortune.storage;


import java.io.*;
import java.util.*;

// Source file: U:\\cse308\\asn8\\src\\storage\\PuzzlePackage.java


public class PuzzlePackage {
 private String filename;
 private int numPuzzles;
   
 /**
  * @roseuid 4189360300D9
  */
 public PuzzlePackage(String filename) {
  this.filename = filename;
  numPuzzles = 0;
  try {
  BufferedReader br = getBR();
  String numLine = br.readLine();
  StringTokenizer st = new StringTokenizer(numLine," :",false);
  st.nextToken();
  String numString = st.nextToken();
  numPuzzles = Integer.parseInt(numString);
  }
  catch(Exception e) {  }
 }
 
 /**
  * @return int
  * @roseuid 418935BB0298
  */
 public int getNumPuzzles() {
  return numPuzzles;
 }
 
 public Puzzle getPuzzle(int index) {
  BufferedReader br = getBR();
  Puzzle p = null;
  try {
  br.readLine(); //skip over numPuzzles header line
  for(int i = 0;i < index;++i) br.readLine();
  String puzString = br.readLine();
  StringTokenizer st = new StringTokenizer(puzString,"\\",false);
  String solution = st.nextToken();
  String category = st.nextToken();
  p = new Puzzle(solution,category);
  }
  catch(Exception e) { }
  return p;
 }

 public BufferedReader getBR() {
  BufferedReader br = null;
  try {
   FileReader f = null;
   f = new FileReader(filename);

   br = new BufferedReader(f);
  }
  catch(Exception e) { }
  return br;
 }
}