/*********************************************************************
 * ASSIGNMENT 4:
 * SpaceshipTester.java: various test cases for Spaceship.java
 * Author: Ben Mathew
 * Date: July 13, 2001
 *
 *********************************************************************/

//DISCLAIMER: Yeah, I know, the spaceships and planets in this file span
//all four of the Star Wars movies, and there is no consistency, so deal.

public class SpaceTester
{
  // hyperGood: checks the return value of a hyperjump()
  //            and prints out an appropriate message. 
  public static void hyperGood(int retVal)
  {
    switch(retVal)
    {
    case 0:
      System.out.println("Hyperjump successful");
      break;
    case 1:
      System.out.println("Hyperjump failed - please launch first");
      break;
    case 2:
      System.out.println("Hyperjump failed - invalid coordinates");
      break;
    case 3:
      System.out.println("Hyperjump failed - low fuel");
      break;
    default:
      System.out.println("Nothing encountered - abort");
    } // end switch
  } // end hypergood() 

  // moveGood: checks the return value of a move()
  //           and prints out an appropriate message. 
  public static void moveGood(int retVal)
  {
    switch(retVal)
    {
    case 0:
      System.out.println("Move completed");
      break;
    case 1:
      System.out.println("Move failed - please launch first");
      break;
    case 2:
      System.out.println("Move failed - invalid coordinates");
      break;
    case 3:
      System.out.println("Move failed - low fuel");
      break;
    default:
      System.out.println("Nothing encountered - abort");
    } // end switch
  } // end moveGood() 

  // launchGood: checks the return value of a launch()
  //             and prints out an appropriate message. 
  public static void launchGood(int retVal)
  {
    switch(retVal)
    {
    case 0:
      System.out.println("Launch successful");
      break;
    case 1:
      System.out.println("Launch failed - already launched");
      break;
    case 2:
      System.out.println("Launch failed - low fuel");
      break;
    default:
      System.out.println("Nothing encountered - abort");
    } // end switch
  } // end launchGood()

  // landGood: checks the return value of a land()
  //           and prints out an appropriate message. 
  public static void landGood(int retVal)
  {
    switch(retVal)
    {
    case 0:
      System.out.println("Landing successful");
      break;
    case 1:
      System.out.println("Landing failed - invalid planet");
      break;
    case 2:
      System.out.println("Landing failed - low fuel");
      break;
    default:
      System.out.println("Nothing encountered - abort");
    } // end switch
  } // end landGood()

  public static void main(String[] args)
  {
    // okay, let's start with the basics, using all the constructor
    // types for Planet and Spaceship classes, respectively

    Planet rebelBase = new Planet("Yavin-4", 2, 7);
    Planet naboo = new Planet();
    Planet desert = new Planet("Tatooine");

    Spaceship ssd = new Spaceship(9, 9);
    ssd.setName("Executor");

    System.out.println();
    System.out.println("Scanning for planets");
    // scanning for planets
    System.out.println(rebelBase);
    System.out.println(naboo);
    System.out.println(desert);
    System.out.println();

    System.out.println("The Executor is hyperjumping to Yavin-4");
    // oh no, the rebel base is under attack!!!
    hyperGood(ssd.hyperjump(2, 7));
    System.out.println(ssd);
    System.out.println();

    Spaceship xWing = new Spaceship(rebelBase);
    xWing.setName("Red 5");
    // red five, reporting in
    System.out.println(xWing);
    Spaceship yWing = new Spaceship(rebelBase);
    yWing.setName("Gold Leader");
    // gold leader, reporting in
    System.out.println(yWing);

    // get those fighters out of here!!
    xWing.move(4, -2);
    yWing.hyperjump(5,5);

    // give them launch orders first!!
    launchGood(xWing.launch());
    launchGood(yWing.launch());

    // oh no, Death Star approacing, what now?????
    Planet ds = new Planet("Death Star", 2, 7);
    System.out.println("Death Star approaching, estimated time to " +
                       "firing range: fifteen minutes.");
    System.out.println(ds);
    System.out.println();
    System.out.println("Evacuating all personnel from the Rebel Base");
    System.out.println();

    System.out.println("Red group, proceed to coordinate (1,1) to refuel.");
    System.out.println("  Then rendevous with the rest of the fleet");
    System.out.println("  orbiting the planet Tatooine.");
    System.out.println("Gold group, hyperjump directly to Naboo and");
    System.out.println("  make sure the system is secure.");
    System.out.println();

    // these should all succeed
    moveGood(xWing.move(-1, -6));
    hyperGood(yWing.hyperjump(5, 5));
    System.out.println(xWing.refuel());
    System.out.println(xWing);
    yWing.land(naboo);
    moveGood(xWing.move(9, 0));
    moveGood(xWing.move(0, 9));
    moveGood(xWing.move(-5, 0));
    moveGood(xWing.move(0, -6));
    moveGood(xWing.move(0, 1));
    System.out.println(xWing);

    Spaceship tie = new Spaceship();
    tie.setName("Black 2");
    // new enemy fighters detected!!
    System.out.println(tie);
    System.out.println("Rebel fighters land at the docking bays!");
    landGood(xWing.land(desert)); //should fail - low fuel
    landGood(yWing.land(naboo));
    // oh no, red five is a goner :(

    System.out.println("There's a new base detected on Hoth!");
    System.out.println("Gold Leader, move your group there.");
    Planet ice = new Planet("Hoth", 7, 1);
    System.out.println(ice);
    hyperGood(yWing.hyperjump(7, 1));
    launchGood(yWing.launch());
    landGood(yWing.land(ice));
    hyperGood(yWing.hyperjump(7, 1));
    landGood(yWing.land(ice));

    Spaceship transport = new Spaceship(ds);
    transport.setName("Millenium Falcon");
    launchGood(transport.launch());
    System.out.println(transport);
    System.out.println();
    System.out.println("Niennumb laughs like a fool and Lando blasts a couple of");
    System.out.println("concussion missiles into the Death Star and destroys it!\n");
    System.out.println("And there is much peace and rejoicing in the 10 x 10 grid.");

    // the end
  } // end main()
} // end SpaceTester
