Guest User

RedGhost

a guest
Jun 19th, 2017
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.42 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class RedGhost extends Ghost {
  4.    Location targetTile, cornerTile, redLoc;
  5.    boolean scatterMode, frightenedMode, chaseMode;
  6.    boolean inHouse;
  7.    int dotsEaten = 0;
  8.    int dotLimit = 0;
  9.   String colory;
  10.  
  11.  
  12.  
  13.  
  14.   public RedGhost() {
  15.    
  16.     red = loadImage("redghost.png");
  17.     putSelfInGrid();
  18.     scatterMode = false;
  19.    
  20.     //setChaseMode();
  21.     //moveToPac();
  22.   }
  23.  
  24.   public RedGhost(String col) {
  25.      red = loadImage("redghost.png");
  26.     putSelfInGrid();
  27.     scatterMode = false;
  28.     colory = col;
  29.   }
  30.    
  31.  
  32.   public boolean scatter() {
  33.     return scatterMode;
  34.   }
  35.  
  36.   void setScatterMode() {
  37.     scatterMode = true;
  38.     //frigthenedMode = false;
  39.     chaseMode = false;
  40.   }
  41.  
  42.   void setChaseMode() {
  43.     chaseMode = true;
  44.     //frigthenedMode = false;
  45.     //scatteredMode = false;
  46.   }
  47.  
  48.   void setfrightenedMode() {
  49.     frightenedMode = true;
  50.     scatterMode = false;
  51.     chaseMode = false;
  52.   }
  53.  
  54.   public boolean frightened() {
  55.     return frightenedMode;
  56.   }
  57.  
  58.   public boolean chase() {
  59.     return chaseMode;
  60.   }
  61.  
  62.   public int getDotsEaten() {
  63.     return dotsEaten;
  64.   }
  65.  
  66.   public void setDotsEaten() {
  67.     dotsEaten++;
  68.   }
  69.  
  70.   public boolean insideGhostHouse() {
  71.     return inHouse;
  72.   }
  73.  
  74.   public Location getLocation() {
  75.     return maze[r][c];
  76.   }
  77.  
  78.   public void moveToPac() {
  79.     if (getLocation() != pac.getLocation()) {
  80.       moveCloser(pac.getLocation());
  81.     }
  82.   }
  83.  
  84.   void setCornerTile() {
  85.     cornerTile = maze[width - 32][0];
  86.   }
  87.  
  88.   void setTargetTile() {
  89.     targetTile = pac.getLocation();
  90.   }
  91.  
  92.   void beEaten() {
  93.     removeSelfFromGrid();
  94.   }
  95.  
  96.   void removeSelfFromGrid() {
  97.   }
  98.  
  99. void putSelfInGrid() {
  100.  
  101.   r = 16;
  102.   c = 13;
  103.   //color col = color(255, 0, 0);
  104.   //fill(col);
  105.   //ellipse(xPixel() , yPixel(), 16 , 16);
  106.   //System.out.println ("xpix: " + xPixel() + " ypix: " + yPixel());
  107.    maze[16][13].setOccupied(true);
  108.    
  109.   }
  110.  
  111.   public int getR() { return r; }
  112.   public int getC() { return c; }
  113.  
  114.   public void setR(int changeBy) {
  115.     r = changeBy;
  116. }
  117.   public void setC(int changeBy) {
  118.     c = changeBy;
  119. }
  120.  
  121. public void moveTo (Location l) {
  122.      maze[r][c].setOccupied(false);
  123.      r = l.getR();
  124.      c = l.getC();
  125.      maze[r][c].setOccupied(true);
  126.  
  127. }
  128.   public void moveCloser (Location l) {
  129.     ArrayList<Location> locs = new ArrayList<Location>();
  130.     locs.clear();
  131.        for (int i = 0; i < xShift.length; i ++) {
  132.          if(r + xShift[i] > 0 && r + xShift[i] < 36 && c + yShift[i] > 0 && c + yShift[i] < 28) {
  133.          if ( maze[r + xShift[i]][c + yShift[i]].isValid()) {
  134.            locs.add(maze[r + xShift[i]][c + yShift[i]]);
  135.          }
  136.          }
  137.        }
  138.        java.util.Collections.sort(locs);
  139.        System.out.println(locs);
  140.    for (Location loc: locs) {
  141.         moveTo(loc);
  142.         if (loc.equals(locPac)) {
  143.           System.out.println ("game over");
  144.         }
  145.    }
  146.     }
  147.    
  148.     void set( RedGhost ghost) {
  149.        r = ghost.getR();
  150.        c = ghost.getC();
  151.        colory = ghost.colory;
  152.     }
  153.    
  154.     String toString() {
  155.       return colory;
  156.     }
  157.    void moveRandom() {
  158.     Random gen = new Random();
  159.     r = gen.nextInt(36);
  160.     c = gen.nextInt(28);
  161.     while (!maze[r][c].isValid()) {
  162.        r = gen.nextInt(36);
  163.        c = gen.nextInt(28);    
  164.     }
  165.     moveTo(maze[r][c]);
  166.   }
  167.   }
Advertisement
Add Comment
Please, Sign In to add comment