Commit 043fd95d authored by Yuhan Chen's avatar Yuhan Chen
Browse files

New update

parent 423dd446
......@@ -29,7 +29,7 @@ public class Baba extends NameWordImpl {
private int y;
public String name = "Baba";
javafx.scene.image.Image image = new javafx.scene.image.Image(getClass().getResource("/image/Baba.png").toExternalForm());
javafx.scene.image.Image image = new javafx.scene.image.Image(getClass().getResource("/image/Baba.png").toExternalForm(), 40, 40, false, false);
public Baba(int x, int y) {
this.x = x;
......
......@@ -28,18 +28,18 @@ public class DemoRule {
/** The height of the board */
private static final int HEIGHT = 800;
/** The number of rows of the board */
private static final int ROWS = 40;
private static final int ROWS = 20;
/** The number of columns of the board */
private static final int COLUMNS = 40;
private static final int COLUMNS = 20;
/** The size of a square */
private static final int SQUARE_SIZE = WIDTH/ROWS;
//Generate objects for the demo
//TODO: initialize the coordinates of the character
public static Baba babaObj = new Baba(0,0);
public static Is isObj = new Is(60,60);
public static Rock rockObj = new Rock(100,100);
public static Win winObj = new Win(600,600);
public static Is isObj = new Is(80,80);
public static Rock rockObj = new Rock(200,200);
public static Win winObj = new Win(400,400);
// Generate a character that player currently moved
public static NameWordImpl player = new NameWordImpl();
......@@ -60,9 +60,10 @@ public class DemoRule {
*/
public static GeneralObject nearObjectLeft(GeneralObject generalObject){
for (GeneralObject obj: objs) {
if (generalObject.getX()*SQUARE_SIZE == (obj.getX() - 1*SQUARE_SIZE) && generalObject.getY()*SQUARE_SIZE == obj.getY()) {
return obj;
}
if (!obj.equals(generalObject))
if (generalObject.getX() == (obj.getX() - SQUARE_SIZE) && generalObject.getY() == obj.getY()) {
return obj;
}
}
return generalObject;
}
......@@ -73,8 +74,10 @@ public class DemoRule {
*/
public static GeneralObject nearObjectRight(GeneralObject generalObject){
for (GeneralObject obj: objs) {
if (generalObject.getX()*SQUARE_SIZE == (obj.getX() + 1*SQUARE_SIZE) && generalObject.getY()*SQUARE_SIZE == obj.getY())
return obj;
if(!obj.equals(generalObject)) {
if (generalObject.getX() == (obj.getX() + SQUARE_SIZE) && generalObject.getY() == obj.getY())
return obj;
}
}
return generalObject;
}
......@@ -85,8 +88,10 @@ public class DemoRule {
*/
public static GeneralObject nearObjectUp(GeneralObject generalObject){
for (GeneralObject obj: objs) {
if (generalObject.getX()*SQUARE_SIZE == (obj.getX()) && generalObject.getY()*SQUARE_SIZE == obj.getY() - 1*SQUARE_SIZE )
return obj;
if (!obj.equals(generalObject)) {
if (generalObject.getX() == (obj.getX()) && generalObject.getY() == obj.getY() - SQUARE_SIZE)
return obj;
}
}
return generalObject;
}
......@@ -97,8 +102,10 @@ public class DemoRule {
*/
public static GeneralObject nearObjectDown(GeneralObject generalObject){
for (GeneralObject obj: objs) {
if (generalObject.getX()*SQUARE_SIZE == (obj.getX()) && generalObject.getY()*SQUARE_SIZE == obj.getY() + 1*SQUARE_SIZE )
return obj;
if (!obj.equals(generalObject)) {
if (generalObject.getX() == (obj.getX()) && generalObject.getY() == obj.getY() + SQUARE_SIZE)
return obj;
}
}
return generalObject;
}
......@@ -121,8 +128,8 @@ public class DemoRule {
if (player.isPushable() == false) {return false;}
switch (key) {
case DOWN:
while (!nearObjectDown(boundaryObj).equals(boundaryObj)) {
if (boundaryObj.getY() == 0) {
while (!nearObjectUp(boundaryObj).equals(boundaryObj)) {
if (boundaryObj.getY() == HEIGHT) {
return false;
} else {
boundaryObj = nearObjectDown(boundaryObj);
......@@ -130,24 +137,24 @@ public class DemoRule {
}
break;
case UP:
while (!nearObjectUp(boundaryObj).equals(boundaryObj)) {
if (boundaryObj.getY() == HEIGHT) {
while (!nearObjectDown(boundaryObj).equals(boundaryObj)) {
if (boundaryObj.getY() == 0) {
return false;
}
boundaryObj = nearObjectDown(boundaryObj);
}
break;
case RIGHT:
while (!nearObjectRight(boundaryObj).equals(boundaryObj)) {
if (boundaryObj.getX() == 0) {
while (!nearObjectLeft(boundaryObj).equals(boundaryObj)) {
if (boundaryObj.getX() == WIDTH) {
return false;
}
boundaryObj = nearObjectDown(boundaryObj);
}
break;
case LEFT:
while (!nearObjectDown(boundaryObj).equals(boundaryObj)) {
if (boundaryObj.getX() == WIDTH) {
while (!nearObjectRight(boundaryObj).equals(boundaryObj)) {
if (boundaryObj.getX() == 0) {
return false;
}
boundaryObj = nearObjectDown(boundaryObj);
......@@ -158,18 +165,35 @@ public class DemoRule {
}
public static void moveCharacter(KeyCode code) {
GeneralObject generalObject = player;
if (isPushable(code)) {
if (code == KeyCode.UP) {
player.move(0,-SQUARE_SIZE);
while(!nearObjectDown(generalObject).equals(generalObject)){
generalObject = nearObjectDown(generalObject);
generalObject.move(0, -SQUARE_SIZE);
}
}
if (code == KeyCode.DOWN) {
player.move(0, SQUARE_SIZE);
while(!nearObjectUp(generalObject).equals(generalObject)){
generalObject = nearObjectUp(generalObject);
generalObject.move(0, SQUARE_SIZE);
}
}
if (code == KeyCode.RIGHT) {
player.move(SQUARE_SIZE,0);
while(!nearObjectLeft(generalObject).equals(generalObject)) {
generalObject = nearObjectLeft(generalObject);
generalObject.move(SQUARE_SIZE,0);
}
}
if (code == KeyCode.LEFT) {
player.move(-SQUARE_SIZE,0);
while(!nearObjectRight(generalObject).equals(generalObject)) {
generalObject = nearObjectRight(generalObject);
generalObject.move(-SQUARE_SIZE,0);
}
}
}
}
......
......@@ -21,7 +21,7 @@ import javafx.scene.image.Image;
public class Is extends ConnectorWord {
public String name = "Is";
javafx.scene.image.Image image = new javafx.scene.image.Image(getClass().getResource("/image/TextIs.png").toExternalForm());
javafx.scene.image.Image image = new javafx.scene.image.Image(getClass().getResource("/image/TextIs.png").toExternalForm(),40,40,false,false);
public Is(int x, int y) {
setCoordinate(x,y);
......
......@@ -21,7 +21,7 @@ import javafx.scene.image.Image;
public class Rock extends NameWordImpl {
public String name = "Rock";
javafx.scene.image.Image image = new javafx.scene.image.Image(getClass().getResource("/image/Rock.png").toExternalForm());;
javafx.scene.image.Image image = new javafx.scene.image.Image(getClass().getResource("/image/Rock.png").toExternalForm(), 40, 40,false,false);;
public Rock(int x, int y) {
setCoordinate(x,y);
......
......@@ -21,7 +21,7 @@ import javafx.scene.image.Image;
public class Win extends RuleWord{
public String name = "Win";
javafx.scene.image.Image image = new javafx.scene.image.Image(getClass().getResource("/image/TextWin.png").toExternalForm());;
javafx.scene.image.Image image = new javafx.scene.image.Image(getClass().getResource("/image/TextWin.png").toExternalForm(),40,40,false,false);;
public Win(int x, int y) {
setCoordinate(x,y);
......
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