-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 8ddbc23
Showing
9 changed files
with
800 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* 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 Cannon extends Chess { | ||
|
||
public Cannon(int xPos, int yPos, boolean red) { | ||
super(xPos, yPos, red); | ||
} | ||
|
||
public boolean move(int yMove, int xMove, boolean eat) { | ||
boolean moved = false; | ||
|
||
if (eat) { | ||
xPos += xMove; | ||
yPos += yMove; | ||
moved = true; | ||
} else { | ||
if (Math.abs(yMove) != 0 && (yPos + yMove) >= 1 && (yPos + yMove) <= 10) { | ||
yPos += yMove; | ||
moved = true; | ||
} else if (Math.abs(xMove) != 0 && (xPos + xMove) >= 1 && (xPos + xMove) <= 9) { | ||
xPos += xMove; | ||
moved = true; | ||
} | ||
|
||
return moved; | ||
} | ||
|
||
return moved; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* 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 abstract class Chess { | ||
protected int xPos; | ||
protected int yPos; | ||
protected boolean red; | ||
|
||
public Chess (int xPos, int yPos, boolean red) { | ||
this.xPos = xPos; | ||
this.yPos = yPos; | ||
this.red = red; | ||
} | ||
|
||
public int getXPos() { | ||
return xPos; | ||
} | ||
|
||
public int getYPos() { | ||
return yPos; | ||
} | ||
} |
Oops, something went wrong.