SHARE
TWEET

Untitled

a guest Sep 14th, 2017 92 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Spy implements Character{
  2.  
  3.     int row;
  4.     int col;
  5.    
  6.     int currentLives = 3; //stores the number of remaining lives, by default starts at 3.
  7.     static int ammoLeft = 1;     //stores the number of remaining shots, default 1. Not a boolean, because a player may pick up the ammo powerup before firing.
  8.  
  9.     boolean alive=true; //an entity is either alive (true, on the field) or dead (false, removed from play)
  10.     public int icon = '4'; //each object that can occupy a mapsquare will get an int for debugging purposes
  11.  
  12.     public Spy(int r, int c){//and if the game ever calls for modifying the start params, we can do that by deleting the above fields' values, and replacing them with arguments in the contructor.
  13.         this.row = r;
  14.         this.col = c;
  15.     }
  16.    
  17.     //The player should only be able to do one view and one move/shoot action thing per turn
  18.     public void movePlayer(Mapsquare[][] board, int direction, Character Spy){  //the player uses the UI to control the movement of their Spy
  19.         move(board, direction, Spy);//This method may be unnecessary. If it isn't, it'll take the direction number 'n' from the UI and call Spy.move(n)
  20.     }
  21.    
  22.     private void playerView(int direction, Ninja Ninja, Powerup Powerup, Mapsquare board[][]){  //the player has the option to view the squares ahead of them
  23.         switch(direction){
  24.         case 1://north call check on row-1, row-2 mapsquares, assuming that row=y-axis, col=x-axis
  25.             if (CheckSquare.checkSquare( (row-1), col, Ninja, board) == true){
  26.                 System.out.println((row-1)+", "+(col)+" contains a Ninja!");
  27.             }
  28.             if (CheckSquare.checkSquare( (row-2), col, Ninja, board)== true){
  29.                 System.out.println((row-2)+", "+(col)+" contains a Ninja!");
  30.             }
  31.            
  32.             break;
  33.  
  34.         case 2: //east call check on col-1, col-2 msquares
  35.             if (CheckSquare.checkSquare( (row), (col-1), Ninja, board) == true){
  36.                 System.out.println((row)+", "+(col-1)+" contains a Ninja!");
  37.             }
  38.             if (CheckSquare.checkSquare( (row), (col-2), Ninja, board)== true){
  39.                 System.out.println((row)+", "+(col-2)+" contains a Ninja!");
  40.             }
  41.            
  42.             break;
  43.  
  44.         case 3: //south call check on row+1, row+1 msquares
  45.             if (CheckSquare.checkSquare( (row+1), col, Ninja, board) == true){
  46.                 System.out.println((row-1)+", "+(col)+" contains a Ninja!");
  47.             }
  48.             if (CheckSquare.checkSquare( (row+2), col, Ninja, board)== true){
  49.                 System.out.println((row-2)+", "+(col)+" contains a Ninja!");
  50.             }
  51.            
  52.             break;
  53.  
  54.         case 4: //west call check on col+1, col+2 msquares
  55.             if (CheckSquare.checkSquare( (row), (col+1), Ninja, board) == true){
  56.                 System.out.println((row)+", "+(col-1)+" contains a Ninja!");
  57.             }
  58.             if (CheckSquare.checkSquare( (row), (col+2), Ninja, board)== true){
  59.                 System.out.println((row)+", "+(col-2)+" contains a Ninja!");
  60.             }
  61.            
  62.             break;
  63.         }
  64.     }
  65.  
  66.     private void shootGun(Mapsquare[][] board, int direction){    //the player can, ammunition permitting, attack a straight line, killing the first ninja that they hit
  67.         switch(direction){
  68.         //check squares in a line until you find either a ninja or a board edge.
  69.         case 1: //north call check on row-- mapsquares,
  70.             for(int n = (row-1); n >= 0; n--)
  71.                 if(board[n][col].c!=new emptychar(n, col)){
  72.                     board[n][col].c.kill();
  73.                     break;
  74.             }
  75.            
  76.             break;
  77.  
  78.         case 2: //east call check on col-- msquares
  79.             for(int n = (col-1); n >= 0; n--)
  80.                 if(board[row][n].c != new emptychar(row, n)){
  81.                     board[row][n].c.kill();
  82.                     break;
  83.             }
  84.            
  85.             break;
  86.  
  87.  
  88.         case 3: //south call check on row++ msquares
  89.             for(int n = (row+1); n <= 8; n++)
  90.                 if(board[n][col].c!=new emptychar(n, col)){
  91.                     board[col][n].c.kill();
  92.                     break;
  93.             }
  94.            
  95.             break;
  96.  
  97.  
  98.         case 4: //west call check on col++ msquares
  99.             for(int n = (col+1); n <= 8; n++)
  100.                 if(board[row][n].c != new emptychar(row, n)){
  101.                     board[row][n].c.kill();
  102.                     break;
  103.             }
  104.            
  105.             break;
  106.         }
  107.  
  108.         Spy.ammoLeft--;
  109.     }
  110.    
  111.     private void respawn(){      //if the player is killed but has lives remaining, they will be replaced on the game field
  112.         if(this.alive==false && this.currentLives >0){
  113.             //respawn code - reset the world to starting status, minus any pickups acquired.
  114.         }
  115.         else{
  116.             System.out.println("Game Over");
  117.             //Driver.breakLoop(); //the assumes that we have a method in Driver, which only contains the break command, for just such an occasion.
  118.         }  
  119.     }
  120.    
  121.     private void pickup(Powerup power){
  122.             power.kill();
  123.             power.powerupFunction();
  124.     }
  125.    
  126.     public void kill() {
  127.         this.alive=false;
  128.         this.currentLives--;
  129.        
  130.     }
  131.        
  132.     public void move(Mapsquare[][] board, int direction, Character Spy) {
  133.         switch(direction){
  134.         case 1:
  135.             //System.out.println("move north");
  136.             board[row][col].c=new emptychar(row, col);
  137.             board[row-1][col].c=Spy;
  138.             row=row-1;
  139.             break;
  140.  
  141.     case 2:
  142.             //System.out.println("move south");
  143.             board[row][col].c=new emptychar(row, col);
  144.             board[row+1][col].c=Spy;
  145.             row=row+1;
  146.             break;
  147.  
  148.     case 3:
  149.             //System.out.println("move west");
  150.             board[row][col].c=new emptychar(row, col);
  151.             board[row][col-1].c=Spy;
  152.             col=col-1;
  153.             break;
  154.  
  155.     case 4:
  156.             //System.out.println("move east");
  157.             board[row][col].c=new emptychar(row, col);
  158.             board[row][col+1].c=Spy;
  159.             col=col+1;
  160.             break;
  161.  
  162.         }
  163.  
  164.     }
  165.  
  166.     public void setLocation(int[][] board, int r, int c) {
  167.         this.row = r;
  168.         this.col = c;
  169.        
  170.     }
  171.  
  172.  
  173.     public String returnLocation() {
  174.         return ("r: " + row + ", col: " + col);
  175.  
  176.        
  177.     }
  178. }
RAW Paste Data
Top