-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPawn.java
48 lines (42 loc) · 1.43 KB
/
Pawn.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
42
43
44
45
46
47
48
/*
* 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 Pawn extends Chess {
public Pawn(int xPos, int yPos, boolean red) {
super(xPos, yPos, red);
}
public boolean move(int yMove, int xMove) {
boolean moved = false;
boolean riverSide = false;
if (red) {
if (yPos >= 6 && yPos <= 10){
riverSide = true;
}
} else {
if (yPos >= 1 && yPos <= 5){
riverSide = true;
}
}
if (red) {
if (yMove == 1 && (yPos + yMove) >= 1 && (yPos + yMove) <= 10) {
yPos += yMove;
moved = true;
} else if (riverSide && (xMove == 1 || xMove == -1) && (xPos + xMove) >= 1 && (xPos + xMove) <= 9) {
xPos += yMove;
moved = true;
}
} else {
if (yMove == -1 && (yPos + yMove) >= 1 && (yPos + yMove) <= 10) {
yPos += yMove;
moved = true;
} else if (riverSide && (xMove == 1 || xMove == -1) && (xPos + xMove) >= 1 && (xPos + xMove) <= 9) {
xPos += yMove;
moved = true;
}
}
return moved;
}
}