-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathElephant.java
41 lines (34 loc) · 1.16 KB
/
Elephant.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package chinesechess;
public class Elephant extends Chess{
public Elephant(int xPos, int yPos, boolean red) {
super(xPos, yPos, red);
}
public boolean move(int yMove, int xMove) {
boolean canMove = false;
if (red) {
if (Math.abs(yMove) == 2 && Math.abs(xMove) == 2 && (yPos + yMove) >= 1 && (yPos + yMove) <= 5 && (xPos + xMove) >= 1 && (xPos + xMove) <= 9) {
xPos += xMove;
yPos += yMove;
canMove = true;
}
} else {
if (Math.abs(yMove) == 2 && Math.abs(xMove) == 2 && (yPos + yMove) >= 6 && (yPos + yMove) <= 10 && (xPos + xMove) >= 1 && (xPos + xMove) <= 9) {
xPos += xMove;
yPos += yMove;
canMove = true;
}
}
return canMove;
}
public int getXPos() {
return xPos;
}
public int getYPos() {
return yPos;
}
}