Advertisement
Guest User

Untitled

a guest
May 22nd, 2015
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.09 KB | None | 0 0
  1. /**
  2.  * KIT101 Assignment 2
  3.  *
  4.  * Wabbit Season -- Organiser Class
  5.  *
  6.  * @author ???
  7.  * @version ???
  8.  *
  9.  * Stage Reached: ???
  10.  */
  11.  
  12. import java.util.Scanner;
  13.  
  14. public class WabbitSeason {
  15.  
  16.   // Final instance variables
  17.  
  18.  
  19.   // Non-final instance variables
  20.   private boolean tracing = false;
  21.   private boolean isRabbit;
  22.   private ToonBot tb;
  23.   private Scanner scanner;
  24.   private String Target, input;
  25.   private int shotsTaken = 0;
  26.  
  27.  
  28.   public WabbitSeason() {
  29.     // constructor body
  30.     tb = new ToonBot(false);
  31.     scanner = new Scanner(System.in);
  32.    
  33.     setTracing(true);
  34.     tb.setTracing(true);
  35.   }
  36.  
  37.  
  38.   public void explain() {
  39.     // method body
  40.     System.out.println("Wabbit Season! You have to track down and recapture a cartoon animal.");
  41.   }
  42.  
  43.  
  44.   public void play()
  45.   {
  46.     // method body
  47.     explain();
  48.    
  49.     boolean playAgain = true;
  50.     while (playAgain) {
  51.       System.out.print("\nWould you like to track down a Rabbit or a Duck? ");
  52.       Target = scanner.next();
  53.       int area = tb.getCurrentArea();
  54.       tb.newGame(isRabbit);
  55.      
  56.       boolean gameOver = false;
  57.       while (gameOver == false)
  58.       {
  59.         System.out.println("You are tracking " + tb.getTarget());
  60.        
  61.         Result near = tb.targetNear();
  62.         switch(near) {
  63.           case NEAR:
  64.             System.out.println("You are in area " + tb.getCurrentArea());
  65.             System.out.println("To your north is: " + tb.nextArea('n') + ". To your east is: " + tb.nextArea('e') + ". To your south is: " + tb.nextArea('s') + ",and to your west is: " + tb.nextArea('w'));
  66.             System.out.println("You have hit your target " + tb.getShotCount() + " times " + "and shot a dart into the wrong area " + shotsTaken++ + " times");
  67.             System.out.println("\nYou can hear movement nearby.");
  68.             break;
  69.           case FAR:
  70.             System.out.println("You are in area " + tb.getCurrentArea());
  71.             System.out.println("To your north is: " + tb.nextArea('n') + ". To your east is: " + tb.nextArea('e') + ". To your south is: " + tb.nextArea('s') + ",and to your west is: " + tb.nextArea('w'));
  72.             System.out.println("You have hit your target " + tb.getShotCount() + " times " + "and shot a dart into the wrong area " + shotsTaken++ + " times");
  73.             break;
  74.           case ENRAGED:
  75.             System.out.println("You are still enraged and not able to pay attention to your surroundings.");
  76.             break;
  77.         }
  78.          
  79.         System.out.print("\nPlease choose from (W)alk, (S)hoot, (R)eset, or (Q)uit: ");
  80.         input = scanner.next();
  81.        
  82.        
  83.         if (input.equalsIgnoreCase("w"))
  84.         {
  85.           System.out.println("You chose " + input);
  86.          
  87.           System.out.print("\nWhich area would you like to walk into? ");
  88.           int areaToMove = scanner.nextInt();
  89.           Result r = tb.tryWalk(areaToMove);
  90.           switch(r) {
  91.             case SUCCESS:
  92.        
  93.               break;
  94.             case ENRAGED:
  95.              
  96.               break;
  97.             case FAILURE:
  98.              
  99.               break;
  100.             case IMPOSSIBLE:
  101.              
  102.               break;
  103.           }
  104.          
  105.         }
  106.         else if (input.equalsIgnoreCase("s"))
  107.         {
  108.           System.out.println("you chose " + input) ;  
  109.         }
  110.         else if (input.equalsIgnoreCase("r"))
  111.         {
  112.           tb.newGame(isRabbit);
  113.         }
  114.         else if (input.equalsIgnoreCase("q"))
  115.         {
  116.           gameOver = true;
  117.         }
  118.       }
  119.      
  120.       System.out.println("\nWould you like to play Wabbit Season again (y/n)?");
  121.       input = scanner.nextLine();
  122.       if (input == "y")
  123.       {
  124.         playAgain = true;
  125.       }
  126.       else
  127.       {
  128.         playAgain = false;
  129.         System.out.print("\nThanks for playing Wabbit Season");
  130.       }
  131.      
  132.     }
  133.    
  134.   }
  135.  
  136.  
  137.   public void setTracing(boolean onOff) {
  138.     tracing = onOff;
  139.   }
  140.  
  141.   public void trace(String message) {
  142.     if (tracing) {
  143.       System.out.println("WabbitSeason: " + message);
  144.     }
  145.   }
  146.  
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement