Commit 8ce0c0e3 authored by hosein's avatar hosein

all nuts classes -> canMove added

parent 00443b1f
package pack.Nuts;
public class Bishop {
public class Bishop extends Nut {
public Bishop(int id) {
this.id = id;
isAlive = true;
switch (id) {
case 13:
x = 7;
y = 2;
break;
case 14:
x = 7;
y = 5;
break;
case -13:
x = 0;
y = 5;
break;
case -14:
x = 0;
y = 2;
}
}
// @Override
// public void move(int[] destination) {
//
// }
@Override
public boolean canMove(int[] destination) {
if (x == destination[0]) return false;
else
return Math.abs((y - destination[1])/(x - destination[0])) == 1;
}
@Override
public void changeAlive() {
isAlive = false;
}
}
package pack.Nuts;
public class King {
public class King extends Nut {
public King(int id) {
this.id = id;
isAlive = true;
if (id == 16) {
x = 7;
y = 4;
} else {
x = 0;
y = 3;
}
}
// @Override
// public void move(int[] destination) {
//
// }
@Override
public boolean canMove(int[] destination) {
return Math.pow(x - destination[0], 2) + Math.pow(y - destination[1], 2) <= 2;
}
public boolean isCheck() {
return false;
}
@Override
public void changeAlive() {
isAlive = false;
}
}
package pack.Nuts;
public class Knight {
import java.lang.Math;
public class Knight extends Nut {
public Knight(int id) {
this.id = id;
isAlive = true;
switch (id) {
case 11:
x = 7;
y = 1;
break;
case 12:
x = 7;
y = 6;
break;
case -11:
x = 0;
y = 6;
break;
case -12:
x = 0;
y = 1;
}
}
// @Override
// public void move(int[] destination) {
// x = destination[0];
// y = destination[1];
// }
@Override
public boolean canMove(int[] destination) {
return Math.pow(destination[0] - x, 2) + Math.pow(destination[1] - y, 2) == 5;
}
@Override
public void changeAlive() {
isAlive = false;
}
}
package pack.Nuts;
public class Queen {
public class Queen extends Nut {
public Queen(int id) {
this.id = id;
isAlive = true;
if (id == 15) {
x = 7;
y = 3;
} else {
x = 0;
y = 4;
}
}
// @Override
// public void move(int[] destination) {
//
// }
@Override
public boolean canMove(int[] destination) {
if (x == destination[0] || y == destination[1]) return true;
else {
if (x == destination[0])
return false;
else
return Math.abs((y - destination[1])/(x - destination[0])) == 1;
}
}
@Override
public void changeAlive() {
isAlive = false;
}
}
package pack.Nuts;
public class Rook {
public class Rook extends Nut {
public Rook(int id) {
this.id = id;
isAlive = true;
switch (id) {
case 9:
x = 7;
y = 0;
break;
case 10:
x = 7;
y = 7;
break;
case -9:
x = 0;
y = 7;
break;
case -10:
x = 0;
y = 0;
}
}
// @Override
// public void move(int[] destination) {
// x = destination[0];
// y = destination[1];
// }
@Override
public boolean canMove(int[] destination) {
return x == destination[0] || y == destination[1];
}
@Override
public void changeAlive() {
isAlive = false;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment