Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhengQ2 authored Jan 19, 2021
0 parents commit 8ddbc23
Show file tree
Hide file tree
Showing 9 changed files with 800 additions and 0 deletions.
36 changes: 36 additions & 0 deletions Cannon.java
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;
}

}
26 changes: 26 additions & 0 deletions Chess.java
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;
}
}
Loading

0 comments on commit 8ddbc23

Please sign in to comment.