Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javafx.geometry.Pos;
- import java.util.Random;
- public class Monster {
- private int health = 100;
- private boolean alive = true;
- private int moveCol;
- private int moveRow;
- private Position monsterLocation;
- private int direction = 1;
- public static final int NORTH = 0;
- public static final int EAST = 1;
- public static final int SOUTH = 2;
- public static final int WEST = 3;
- private TowerDefenceLevel level;
- public Monster(int rowStart, int colStart, TowerDefenceLevel level){
- monsterLocation = new Position(rowStart,colStart);
- this.level = level;
- }
- public int getHealth() {
- return health;
- }
- public Position getPosition() {
- return monsterLocation;
- }
- public void setHealth(int damage){
- health = health - damage;
- }
- public boolean frontIsClear() {
- if (){
- }
- int row = monsterLocation.getRow();
- int col = monsterLocation.getCol();
- if (direction == NORTH)
- row = row -1;
- else if (direction == SOUTH)
- row = row +1;
- else if (direction == EAST)
- col = col +1;
- else
- col = col -1;
- return level.passable[row][col];
- //return world.isValid(loc) && world.getImage(loc) == null;
- }//frontIsClear
- public boolean leftIsClear() {
- int row = monsterLocation.getRow();
- int col = monsterLocation.getCol();
- if (direction == NORTH)
- col = col - 1;
- else if (direction == SOUTH)
- col = col +1;
- else if (direction == EAST)
- row = row -1;
- else
- row = row + 1;
- return level.passable[row][col];
- }//leftisclear
- //före: roboten vet inte vad som finns till höger i körriktningen
- //efter: roboten vet vad som finns till höger i körriktningen
- public boolean rightIsClear() {
- int row = monsterLocation.getRow();
- int col = monsterLocation.getCol();
- if (direction == NORTH)
- col = col +1;
- else if (direction == SOUTH)
- col = col -1;
- else if (direction == EAST)
- row = row + 1;
- else
- row = row - 1;
- return level.passable[row][col];
- }//frontIsClear
- public boolean[] wallCheck(){
- boolean[] whatWay = {false,false,false};
- if (frontIsClear())
- whatWay[0] = true;
- if(leftIsClear())
- whatWay[1] = true;
- if(rightIsClear())
- whatWay[2] = true;
- return whatWay;
- }
- public int directionPlanner(){
- boolean[] whatWay;
- whatWay = wallCheck();
- int t=0;
- int r;
- Random random = new Random();
- r = random.nextInt(3);
- System.out.println("Skriv ut r: "+r);
- for(int i = 0;i < 3;i++) {
- if (whatWay[i]) {
- t = r;
- }
- }
- //System.out.println(t);
- return t;
- }
- public void move(){
- int row = monsterLocation.getRow();
- int col = monsterLocation.getCol();
- Position newPosition;
- if (direction == NORTH)//up
- newPosition = new Position(row - 1, col);
- else if (direction == SOUTH)//down
- newPosition = new Position(row + 1, col);
- else if (direction == WEST)//right
- newPosition = new Position(row, col - 1);
- else//left
- newPosition = new Position(row, col + 1);
- monsterLocation = newPosition;
- }
- public void turnLeft() {
- if (direction == NORTH) {
- direction = WEST;
- } else if (direction == SOUTH) {
- direction = EAST;
- } else if (direction == WEST) {
- direction = SOUTH;
- } else {
- direction = NORTH;
- }
- }
- public void turnRight() {
- if (direction == NORTH) {
- direction = EAST;
- } else if (direction == SOUTH) {
- direction = WEST;
- } else if (direction == EAST) {
- direction = SOUTH;
- } else {
- direction = NORTH;
- }
- }//turnRight
- public void setDirection(int direction){
- this.direction = direction;
- }
- public int getDirection(){
- return this.direction;
- }
- public boolean getIsAlive(){
- return alive;
- }
- public void setIsAlive(boolean death){
- alive = death;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement