public void act() // sean { if (!played) { burningSteppes.playLoop(); played = !played; } // makeSmokeFireball(); counterDelay++; if (Greenfoot.isKeyDown("h") && delay > 10) { clickSound.play(); Menu menu = new Menu(getThisWorld()); Greenfoot.setWorld(menu); delay = 0; } if (getObjects(Ninja.class).size() != 0 && counterDelay >= 10) { healthCounter.setValue(ninja.getNINJAHP()); shurikenCounter.setValue(ninja.getSHURIKENNUMBER()); powerCounter.setValue(ninja.getPOWERBAR()); checkDoor(); counterDelay -= 10; /**/ // TEMPORAY FUNCTIONS FOR HAYDEN TO CHANGE LEVELS TO MAKE THEM /**/ /**/ // TEMPORAY FUNCTIONS FOR HAYDEN TO CHANGE LEVELS TO MAKE THEM /**/ } delay++; fireballDelay++; }
/* public void makeSmokeFireball() { if (delay > 100) { int randomNumber = Greenfoot.getRandomNumber(1000); if (randomNumber < 50) { SmokeFireball smokeFireball = new SmokeFireball(); addObject(smokeFireball, 500, 475); delay = 0; } if (randomNumber >= 50 && randomNumber < 100) { SmokeFireball smokeFireball = new SmokeFireball(); addObject(smokeFireball, 95, 661); delay = 0; } if (randomNumber >= 100 && randomNumber < 150) { SmokeFireball smokeFireball = new SmokeFireball(); addObject(smokeFireball, 160, 493); delay = 0; } if (randomNumber >= 150 && randomNumber < 200) { SmokeFireball smokeFireball = new SmokeFireball(); addObject(smokeFireball, 637, 423); delay = 0; } if (randomNumber >= 200 && randomNumber < 250) { SmokeFireball smokeFireball = new SmokeFireball(); addObject(smokeFireball, 422, 285); delay = 0; } } } */ public void checkDoor() // sean { if (ninja.checkInfernoDoor() == true) { burningSteppes.stop(); Greenfoot.setWorld(new Inferno2(ninja)); } }
public Inferno1(Ninja ninja) // sean { super(); burningSteppes.setVolume(40); this.ninja = ninja; ninja.addPowerUp(4); prepare(); }
/** * Put 6 ninjas into different random positions on the map or randomize current ninjas locations. * * @param initial if first fill up the map with 6 ninjas, set this to true. */ private void assignNinjas(boolean initial) { int rRow; int rCol; if (initial) { for (int i = 0; i < 6; i++) { do { rRow = random.nextInt(8); rCol = random.nextInt(8); } while (isOccupied(rRow, rCol)); Ninja ninja = new Ninja(rRow, rCol); map[rRow][rCol] = ninja; if (debug) { ninja.setVisible(true); } // Store the ninja to the array, and mark the new location as // occupied. ninjas.add(ninja); occupiedLocations.add(map[rRow][rCol]); } } else { // If there are ninjas surrond the original position, move them. for (Square location : surroundSpy) { if (isNinja(map[location.getRow()][location.getCol()])) { do { rRow = random.nextInt(8); rCol = random.nextInt(8); if (isNinja(map[rRow][rCol])) { occupiedLocations.add(map[rRow][rCol]); } } while (isOccupied(rRow, rCol)); map[rRow][rCol] = map[location.getRow()][location.getCol()]; Ninja ninja = (Ninja) map[rRow][rCol]; map[location.getRow()][location.getCol()] = new Square(debug, rRow, rCol); ninja.setRow(rRow); ninja.setCol(rCol); if (debug) { ninja.setVisible(true); } occupiedLocations.add(map[rRow][rCol]); } } } }
@Before public void setup() { String app = "Ninja"; String challenge = "Basic realm=\"" + app + "\""; when(ninjaProperties.getWithDefault(NinjaConstant.applicationName, app)).thenReturn(app); basicAuthFilter = new BasicAuthFilter( ninja, ninjaProperties, new UsernamePasswordValidator() { @Override public boolean validateCredentials(String username, String password) { return "james".equals(username) && "bond".equals(password); } }); when(ninja.getUnauthorizedResult(context)).thenReturn(result); when(result.status(Result.SC_401_UNAUTHORIZED)).thenReturn(result); when(result.addHeader(Result.WWW_AUTHENTICATE, challenge)).thenReturn(result); }
private void prepare() // sean { InfernoDoor door = new InfernoDoor(); addObject(door, 663 - 50 + 35 + 5, 651 - 50); for (int i = 0; i < 14; i++) for (int j = 0; j < 2; j++) { InfernoFence infernoFence = new InfernoFence(); addObject(infernoFence, 25 + j * 700, 50 * i + 25); } for (int i = 1; i < 14; i++) for (int j = 0; j < 2; j++) { InfernoFence infernoFence = new InfernoFence(); addObject(infernoFence, 50 * i + 25, 25 + j * (700 - 50)); } for (int i = 0; i < 9; i++) { InfernoFence infernoFence = new InfernoFence(); addObject(infernoFence, 50 * i + 25, 125); } for (int i = 0; i < 9; i++) { InfernoFence infernoFence = new InfernoFence(); addObject(infernoFence, 50 * i + 175 + 100, 225); } Firebat firebat2 = new Firebat(8, 3); addObject(firebat2, 511, 625); Firebat firebat3 = new Firebat(8, 3); addObject(firebat3, 588, 534); Firebat firebat4 = new Firebat(8, 3); addObject(firebat4, 629, 489); Firebat firebat5 = new Firebat(8, 3); addObject(firebat5, 203, 608); Firebat firebat6 = new Firebat(8, 3); addObject(firebat6, 484, 388); Firebat firebat7 = new Firebat(8, 3); addObject(firebat7, 320, 350); InfernoFence infernoFence = new InfernoFence(); addObject(infernoFence, 133, 417); InfernoFence infernoFence3 = new InfernoFence(); addObject(infernoFence3, 164, 571); InfernoFence infernoFence5 = new InfernoFence(); addObject(infernoFence5, 429, 360); InfernoFence infernoFence6 = new InfernoFence(); addObject(infernoFence6, 325, 669); InfernoFence infernoFence7 = new InfernoFence(); addObject(infernoFence7, 452, 571); InfernoFence infernoFence8 = new InfernoFence(); addObject(healthCounter, 866, 120); healthCounter.setValue(ninja.getNINJAHP()); addObject(shurikenCounter, 866, 201); shurikenCounter.setValue(ninja.getSHURIKENNUMBER()); addObject(powerCounter, 866, 161); powerCounter.setValue(ninja.getPOWERBAR()); addObject(levelCounter, 950, 15); levelCounter.setValue(31); addObject(ninja, 75, 75); ninja.setLocation(100, 75); HealthGlobe healthglobe = new HealthGlobe(); addObject(healthglobe, 668, 57); healthglobe.setLocation(674, 54); HealthGlobe healthglobe2 = new HealthGlobe(); addObject(healthglobe2, 638, 138); healthglobe2.setLocation(672, 110); instaPower instapower = new instaPower(); addObject(instapower, 87, 624); instapower.setLocation(76, 623); addShuriken addshuriken = new addShuriken(); addObject(addshuriken, 76, 181); addShuriken addshuriken2 = new addShuriken(); addObject(addshuriken2, 466, 123); addshuriken2.setLocation(675, 277); instaPower instapower2 = new instaPower(); addObject(instapower2, 429, 627); instapower2.setLocation(431, 625); makeAllIcons(); meleeMinions = getObjects(MeleeMinion.class); for (int i = 0; i < meleeMinions.size(); i++) { TempText8 text = new TempText8(meleeMinions.get(i)); addObject(text, meleeMinions.get(i).getX(), meleeMinions.get(i).getY() - 20); } }
public void gameover() { // Hayden ninja.setHP(ninja.getArmor()); burningSteppes.stop(); Greenfoot.setWorld(new Inferno1(ninja)); }
/** * Move the all the ninjas in the game to random directions. * * @return true if all ninjas moved successfully, false if foud a spy near by and stabbed him. */ public boolean moveNinja() { // Check if the ninja has stepped on any power up last turn, assign them // back to their location. reAssignPowerUps(); for (Ninja ninja : ninjas) { int row = ninja.getRow(); int col = ninja.getCol(); Square location = null; ArrayList<Square> validLocations = getValidLocations(ninja); // Remove all the rooms and ninjas locations from possible moves. Iterator<Square> iterator = validLocations.iterator(); while (iterator.hasNext()) { Square loc = iterator.next(); if (isRoom(loc) || isNinja(loc)) { iterator.remove(); } } // The ninja can not stab the spy if the spy has invincibility. if (!spy.isInvincible()) { // If there's the spy next to this ninja, stab him! if (checkForSpy(ninja)) { return false; } } else { // Remove the spy location from ninja's possible moves when the // spy is invincible. Iterator<Square> iter = validLocations.iterator(); while (iter.hasNext()) { Square loc = iter.next(); if (loc instanceof Spy) { iter.remove(); } } } // If the ninja got place in the dead end corner and has no where to // move, it can stay in the same position. if (validLocations.size() < 3) { validLocations.add(map[row][col]); } // Choose one random direction from possible locations. int index = random.nextInt(validLocations.size()); location = validLocations.get(index); int Lrow = location.getRow(); int Lcol = location.getCol(); if (isPowerUp(location)) { // If the ninja step on the power up, save the power up and // display the ninja. powerUps.add((PowerUp) location); map[Lrow][Lcol] = ninja; ninja.setRow(Lrow); ninja.setCol(Lcol); map[row][col] = new Square(debug, row, col); } else if (location == map[row][col]) { // If the ninja stay in the same postion, do nothing. map[row][col] = ninja; } else { map[Lrow][Lcol] = ninja; ninja.setRow(Lrow); ninja.setCol(Lcol); if (!isPowerUp(map[row][col])) { map[row][col] = new Square(debug, row, col); } } } return true; }
/** * Hard mode: If the spy is on the ninja's line of sight, the ninja will chase the spy until the * line of sight is broke. If no spy on the line of sight, the ninja will move randomly. * * @return true if all ninjas moved successfully, false if foud a spy near by and stabbed him. */ public boolean moveSmartNinja() { // Check if the ninja has stepped on any power up last turn, assign them // back to their location. reAssignPowerUps(); Square roomLoc = null; int spyRow = spy.getRow(); int spyCol = spy.getCol(); for (Ninja ninja : ninjas) { ArrayList<Square> validLocations = getValidLocations(ninja); int ninjaRow = ninja.getRow(); int ninjaCol = ninja.getCol(); Square location = null; // Remove all the rooms and ninjas locations from possible moves. Iterator<Square> iterator = validLocations.iterator(); while (iterator.hasNext()) { Square loc = iterator.next(); if (isRoom(loc) || isNinja(loc)) { iterator.remove(); } } // The ninja can not stab the spy if the spy has invincibility. if (!spy.isInvincible()) { // If there's the spy next to this ninja, stab him! if (checkForSpy(ninja)) { return false; } } else { // Remove the spy location from ninja's possible moves when the // spy is invincible. Iterator<Square> iter = validLocations.iterator(); while (iter.hasNext()) { Square loc = iter.next(); if (loc instanceof Spy) { iter.remove(); } } } // If the ninja got place in the dead end corner and has no where to // move, it can stay in the same position. if (validLocations.size() < 3) { validLocations.add(map[ninjaRow][ninjaCol]); } // If the ninja is in the same row or the same column, evaluate // which (row or column) and // find if they are above or below you if (spyRow == ninjaRow || spyCol == ninjaCol) { // scenario 1: ninja and spy are in the same column, spy is // above the ninja if (spyCol == ninjaCol && spyRow < ninjaRow) { for (Square room : roomLocations) { if (ninjaRow < room.getRow() && room.getRow() < spyRow) { roomLoc = room; } } if (spyRow < roomLoc.getRow() && roomLoc.getRow() < ninjaRow) { moveNinja(); } else if (validLocations.contains(map[ninjaRow - 1][ninjaCol])) { // This is SUPPOSED to move the ninja to the // location // one spot closer to // the spy and handle the power up properly if (isPowerUp(map[ninjaRow - 1][ninjaCol])) { powerUps.add((PowerUp) map[ninjaRow - 1][ninjaCol]); map[ninjaRow - 1][ninjaCol] = ninja; ninja.setRow(ninjaRow - 1); ninja.setCol(ninjaCol); map[ninjaRow][ninjaCol] = new Square(debug, ninjaRow, ninjaCol); } else { map[ninjaRow - 1][ninjaCol] = ninja; ninja.setRow(ninjaRow - 1); ninja.setCol(ninjaCol); if (!isPowerUp(map[ninjaRow][ninjaCol])) { map[ninjaRow][ninjaCol] = new Square(debug, ninjaRow, ninjaCol); } } } } // scenario 2: ninja and spy are in the same col, spy is below // the ninja if (spyCol == ninjaCol && spyRow > ninjaRow) { for (Square room : roomLocations) { if (ninjaRow < room.getRow() && room.getRow() < spyRow) { roomLoc = room; } } if (ninjaRow < roomLoc.getRow() && roomLoc.getRow() < spyRow) { moveNinja(); } else if (validLocations.contains(map[ninjaRow + 1][ninjaCol])) { if (isPowerUp(map[ninjaRow + 1][ninjaCol])) { powerUps.add((PowerUp) map[ninjaRow + 1][ninjaCol]); map[ninjaRow + 1][ninjaCol] = ninja; ninja.setRow(ninjaRow + 1); ninja.setCol(ninjaCol); map[ninjaRow][ninjaCol] = new Square(debug, ninjaRow, ninjaCol); } else { map[ninjaRow + 1][ninjaCol] = ninja; ninja.setRow(ninjaRow + 1); ninja.setCol(ninjaCol); if (!isPowerUp(map[ninjaRow][ninjaCol])) { map[ninjaRow][ninjaCol] = new Square(debug, ninjaRow, ninjaCol); } } } } // scenario 3: ninja and spy are in the same row, spy is to the // left of the ninja if (spyRow == ninjaRow && spyCol < ninjaCol) { for (Square room : roomLocations) { if (ninjaRow < room.getRow() && room.getRow() < spyRow) { roomLoc = room; } } if (spyCol < roomLoc.getCol() && roomLoc.getCol() < ninjaCol) { moveNinja(); } else if (validLocations.contains(map[ninjaRow][ninjaCol - 1])) { if (isPowerUp(map[ninjaRow][ninjaCol - 1])) { powerUps.add((PowerUp) map[ninjaRow][ninjaCol - 1]); map[ninjaRow][ninjaCol - 1] = ninja; ninja.setRow(ninjaRow); ninja.setCol(ninjaCol - 1); map[ninjaRow][ninjaCol] = new Square(debug, ninjaRow, ninjaCol); } else { map[ninjaRow][ninjaCol - 1] = ninja; ninja.setRow(ninjaRow); ninja.setCol(ninjaCol - 1); if (!isPowerUp(map[ninjaRow][ninjaCol])) { map[ninjaRow][ninjaCol] = new Square(debug, ninjaRow, ninjaCol); } } } // scenario 4: ninja and spy are in the same row, spy is to // the right of the ninja if (spyRow == ninjaRow && spyCol > ninjaCol) { for (Square room : roomLocations) { if (ninjaRow < room.getRow() && room.getRow() < spyRow) { roomLoc = room; } } if (spyCol < roomLoc.getCol() && roomLoc.getCol() < ninjaCol) { moveNinja(); } else if (validLocations.contains(map[ninjaRow][ninjaCol + 1])) { if (isPowerUp(map[ninjaRow][ninjaCol + 1])) { powerUps.add((PowerUp) map[ninjaRow][ninjaCol + 1]); map[ninjaRow][ninjaCol + 1] = ninja; ninja.setRow(ninjaRow); ninja.setCol(ninjaCol + 1); map[ninjaRow][ninjaCol] = new Square(debug, ninjaRow, ninjaCol); } else { map[ninjaRow][ninjaCol + 1] = ninja; ninja.setRow(ninjaRow); ninja.setCol(ninjaCol + 1); if (!isPowerUp(map[ninjaRow][ninjaCol])) { map[ninjaRow][ninjaCol] = new Square(debug, ninjaRow, ninjaCol); } } } } } } else { int index = random.nextInt(validLocations.size()); location = validLocations.get(index); int Lrow = location.getRow(); int Lcol = location.getCol(); if (isPowerUp(location)) { // If the ninja step on the power up, save the power up // and // display the ninja. powerUps.add((PowerUp) location); map[Lrow][Lcol] = ninja; ninja.setRow(Lrow); ninja.setCol(Lcol); map[ninjaRow][ninjaCol] = new Square(debug, ninjaRow, ninjaCol); } else if (location == map[ninjaRow][ninjaCol]) { // If the ninja stay in the same postion, do nothing. map[ninjaRow][ninjaCol] = ninja; } else { map[Lrow][Lcol] = ninja; ninja.setRow(Lrow); ninja.setCol(Lcol); if (!isPowerUp(map[ninjaRow][ninjaCol])) { map[ninjaRow][ninjaCol] = new Square(debug, ninjaRow, ninjaCol); } } } } return true; }