/*
 * This class is eventually going to control all the flow
 * of Minesweeper.  All input/output of the program will 
 * be through this class.  
 */
public class GameController{

  private int level_;

  public GameController(){
  }

  public void startGame(){

    System.out.println("Hello!  Welcome to Danah's Minesweeper");
    if (this.askLevel()){
      this.createGame();
      this.startFlow();
    }
    else {
      System.out.println("Oh well, thanks for trying!");
    }

  }
    
  /* 
   * The goal of this method is to ask the user what level
   * they want to play.  It is important to make certain that
   * the input is accurate and that we act accordingly.
   *
   * The boolean tells the controller whether or not we want
   * to actually play
   */
  public boolean askLevel(){

    System.out.println("What level would you like to play?");
    System.out.println("1=Beginner, 2=Intermediate, 3=Advanced (0 for no play)");
    level_ = ReadInput.getInt();
System.out.println("more stuff = " + ReadInput.isMoreStuff());
    ReadInput.flushLine(); // flush the rest of the line!

    System.out.println("You have chosen level " + level_);

    /* Since 0 is no play, we check for no play and return whether
     * or not we got a zero.  I don't know what to do if they type 
     * something that is not correct...
     */
    if (level_ != 0){
      return true;
    }
    else return false;
  }

  /*
   * Given the level of the game, this method creates the
   * actual board.  [Right now, it only prints out the very
   * basics since we don't have a board class]
   */
  public void createGame(){
    /* eventually, this will create a real game but for now
     * I will just print out an array of the appropriate size
     */
    
    int xSize, ySize;
    
    if (level_ == 1){
      xSize = 8;
      ySize = 8;
    }
    else if (level_ == 2){
      xSize = 16;
      ySize = 16;
    }
    else if (level_ == 3){
      xSize = 16;
      ySize = 30;
    }
    else {
      System.out.println("What size x,y would you like? [x y]");
      xSize = ReadInput.getInt();
      ySize = ReadInput.getInt();
      ReadInput.flushLine(); // flush the rest of the line!
    }

    /* This should end up being moved to a print function */
    System.out.println(""); // this gives clearer space
    for (int y=0; y<ySize; y++){
      for (int x=0; x<xSize; x++){
	System.out.print(" x ");
      }
      System.out.println("");
    }
    System.out.println(""); // this ends it so it does not cram into the bottom
  }

  /* 
   * Eventually, this will deal with the flow of control.
   * Right now, we are just asking the questions and doing
   * nothing with the responses.
   */
  public void startFlow(){
    
    int option, x, y;
    System.out.println("What would you like to do next?");
    System.out.println("Options: 1=Uncover, 2=Flag, 3=Clear");
    option = ReadInput.getInt();
    ReadInput.flushLine(); // flush the rest of the line!

    System.out.println("What x and y positions? [x y]");
    x = ReadInput.getInt();
    y = ReadInput.getInt();
    ReadInput.flushLine(); // flush the rest of the line!

    /*
     * While this is not the eventual goal, it lets me know
     * what I am _wanting_ to do.
     */
    if (option == 1){
      System.out.println("You would like to uncover node (" + x + "," + y + ")");
    }
    else if (option == 2){
      System.out.println("You would like to flag node (" + x + "," + y + ")");
    }
    
    else if (option == 3){
      System.out.println("You would like to clear node (" + x + "," + y + ")");
    }
    else {
      System.out.println("You did not choose a valid commmand");
    }
    

  }


 }
