/** * Toggle Debug mode, if debug is currently off switch the visible field of all game objects to * true.All game objects will be visible. Else switch all of them to false, except for spy and * rooms. */ public void toggleDebugMode() { if (debug == false) { briefCaseRoom.setSymbol("*"); for (Square[] locations : map) { for (Square location : locations) { location.setVisible(true); } } // Activate the PowerUps also, in case of ninja step on it for (PowerUp powerUp : powerUps) { powerUp.setVisible(true); } debug = true; } else { briefCaseRoom.setSymbol("R"); for (Square[] locations : map) { for (Square location : locations) { location.setVisible(false); } } spy.setVisible(true); for (Square[] locations : map) { for (Square location : locations) { if (isRoom(location)) { location.setVisible(true); } } } debug = false; assignSpyVisibility(); } }
/** * Move the spy to the directed direction. The spy can look it room, look for the gre4ka, get stab * if walk into ninja, and activate the power up if found. * * @param direction an integer from 1-4: 1-up, 2-left, 3-down, 4-right. * @return the status code: 1 - the player moved sucessfully, 2 - move failed, 3 - room empty, 4 - * the player got stabbed, 5 - the player activated Bullet power up, 6 - the player activated * Radar power up, 7 - the player activated Invincibility power up, 8- the spy is invicible, * he can not get stabbed or walk into another ninja. */ public int movePlayer(int direction) { int row = spy.getRow(); int col = spy.getCol(); // Check for spy invicibility status, decrement the turn number by 1 // each turn. if (spy.isInvincible()) { invincibilityTurns -= 1; if (invincibilityTurns <= 0) { spy.setInvincibility(false); } } switch (direction) { case 1: // Move up if (row - 1 >= 0) { if (!isRoom(map[row - 1][col])) { if (isNinja(map[row - 1][col])) { if (spy.isInvincible()) { // The spy can not get stabbed or walk into another // ninja. return 8; } else { stabSpy(); return 4; } } else if (map[row - 1][col] instanceof Bullet) { if (spy.getBullets() < 1) { spy.addBullet(); spy.setRow(row - 1); map[row - 1][col] = spy; map[row][col] = new Square(debug, row, col); return 5; } else if (spy.getBullets() == 1) { return 2; } } else if (map[row - 1][col] instanceof Radar) { briefCaseRoom.setSymbol("*"); spy.setRow(row - 1); map[row - 1][col] = spy; map[row][col] = new Square(debug, row, col); return 6; } else if (map[row - 1][col] instanceof Invincibility) { spy.setInvincibility(true); spy.setRow(row - 1); map[row - 1][col] = spy; map[row][col] = new Square(debug, row, col); return 7; } else { spy.setRow(row - 1); map[row - 1][col] = spy; map[row][col] = new Square(debug, row, col); } } else { return 2; } } else { return 2; } break; case 2: // Move left if (col - 1 >= 0) { if (!isRoom(map[row][col - 1])) { if (isNinja(map[row][col - 1])) { if (spy.isInvincible()) { // The spy can not get stabbed or walk into another // ninja. return 8; } else { stabSpy(); return 4; } } else if (map[row][col - 1] instanceof Bullet) { if (spy.getBullets() < 1) { spy.addBullet(); spy.setCol(col - 1); map[row][col - 1] = spy; map[row][col] = new Square(debug, row, col); return 5; } else if (spy.getBullets() == 1) { return 2; } } else if (map[row][col - 1] instanceof Radar) { briefCaseRoom.setSymbol("*"); spy.setCol(col - 1); map[row][col - 1] = spy; map[row][col] = new Square(debug, row, col); return 6; } else if (map[row][col - 1] instanceof Invincibility) { spy.setInvincibility(true); spy.setCol(col - 1); map[row][col - 1] = spy; map[row][col] = new Square(debug, row, col); return 7; } else { spy.setCol(col - 1); map[row][col - 1] = spy; map[row][col] = new Square(debug, row, col); } } else { return 2; } } else { return 2; } break; case 3: // Move down if (row + 1 <= 8) { if (!isRoom(map[row + 1][col])) { if (isNinja(map[row + 1][col])) { if (spy.isInvincible()) { // The spy can not get stabbed or walk into another // ninja. return 8; } else { stabSpy(); return 4; } } else if (map[row + 1][col] instanceof Bullet) { if (spy.getBullets() < 1) { spy.addBullet(); spy.setRow(row + 1); map[row + 1][col] = spy; map[row][col] = new Square(debug, row, col); return 5; } else if (spy.getBullets() == 1) { return 2; } } else if (map[row + 1][col] instanceof Radar) { briefCaseRoom.setSymbol("*"); spy.setRow(row + 1); map[row + 1][col] = spy; map[row][col] = new Square(debug, row, col); return 6; } else if (map[row + 1][col] instanceof Invincibility) { spy.setInvincibility(true); spy.setRow(row + 1); map[row + 1][col] = spy; map[row][col] = new Square(debug, row, col); return 7; } else { spy.setRow(row + 1); map[row + 1][col] = spy; map[row][col] = new Square(debug, row, col); } } else if (isRoom(map[row + 1][col])) { // The spy can only enter the room from this north side by // moving down. // Enter room, check for brief case. if (((Room) map[row + 1][col]).hasBriefCase()) { gameEndStatus = 1; } else { // Return code 3 if room is empty. return 3; } } else { return 2; } } else { return 2; } break; case 4: // Move right if (col + 1 <= 8) { if (!isRoom(map[row][col + 1])) { if (isNinja(map[row][col + 1])) { if (spy.isInvincible()) { // The spy can not get stabbed or walk into another // ninja. return 8; } else { stabSpy(); return 4; } } else if (map[row][col + 1] instanceof Bullet) { if (spy.getBullets() < 1) { spy.addBullet(); spy.setCol(col + 1); map[row][col + 1] = spy; map[row][col] = new Square(debug, row, col); return 5; } else if (spy.getBullets() == 1) { return 2; } } else if (map[row][col + 1] instanceof Radar) { briefCaseRoom.setSymbol("*"); spy.setCol(col + 1); map[row][col + 1] = spy; map[row][col] = new Square(debug, row, col); return 6; } else if (map[row][col + 1] instanceof Invincibility) { spy.setInvincibility(true); spy.setCol(col + 1); map[row][col + 1] = spy; map[row][col] = new Square(debug, row, col); return 7; } else { spy.setCol(col + 1); map[row][col + 1] = spy; map[row][col] = new Square(debug, row, col); } } else { return 2; } } else { return 2; } break; } return 1; }