Commit 5d027f17 authored by Nguyen Nguyen's avatar Nguyen Nguyen
Browse files

fixing some of the bugs in

parent 563e295e
......@@ -133,7 +133,10 @@ public class DemoRuleOne {
objs.add(winObj);
}
/**
* Check if character is movable and move if character is movable
* @param code - Keyboard input
*/
public static void moveCharacter(KeyCode code) {
GeneralObject generalObject = player;
if (player.isPushable()) {
......@@ -198,24 +201,15 @@ public class DemoRuleOne {
* @return win or not yet
*/
public static boolean isWin() {
if (ruleRock) {
if(player.equals(babaObj)){
if (nearObjectLeft(babaObj).equals(rockObj) || nearObjectRight(babaObj).equals(rockObj)
|| nearObjectDown(babaObj).equals(rockObj) || nearObjectUp(babaObj).equals(rockObj)) {
return true;
}
}
if(player.equals(rockObj)) {return true;}
if (nearObjectLeft(babaObj).equals(winObj) || nearObjectRight(babaObj).equals(winObj)
|| nearObjectDown(babaObj).equals(winObj) || nearObjectUp(babaObj).equals(winObj)) {
return true;
}
if (ruleBaba) {
if (player.equals(rockObj)) {
if (nearObjectLeft(babaObj).equals(rockObj) || nearObjectRight(babaObj).equals(rockObj)
|| nearObjectDown(babaObj).equals(rockObj) || nearObjectUp(babaObj).equals(rockObj)) {
return true;
}
}
if (player.equals(babaObj)) {return true;}
else if (nearObjectLeft(rockObj).equals(winObj) || nearObjectRight(rockObj).equals(winObj)
|| nearObjectDown(rockObj).equals(winObj) || nearObjectUp(rockObj).equals(winObj)) {
return true;
}
return false;
}
......
......@@ -148,7 +148,11 @@ public class DemoRuleThree {
return generalObject;
}
/**
* Checks if object is passable
* @param code - keyboard input
* @return true if is, false otherwise
*/
public static boolean isPassable(KeyCode code) {
switch (code) {
case DOWN:
......@@ -156,6 +160,7 @@ public class DemoRuleThree {
if (nearObjectUp(player).isPassable()) {
return true;
}
else {return false;}
}
else {return true;}
......@@ -187,18 +192,25 @@ public class DemoRuleThree {
return false;
}
/**
* Check if character is movable and move if character is movable
* @param code - Keyboard input
*/
public static void moveCharacter(KeyCode code) {
GeneralObject generalObject = player;
if (player.isPushable()) {
if (code == KeyCode.UP) {
player.move(0,-SQUARE_SIZE);
while(!atObjectLocation(generalObject).equals(generalObject)){
generalObject = atObjectLocation(generalObject);
generalObject.move(0, -SQUARE_SIZE);
if(isPassable(code)) {
player.move(0,-SQUARE_SIZE);
while(!atObjectLocation(generalObject).equals(generalObject)) {
generalObject = atObjectLocation(generalObject);
generalObject.move(0, -SQUARE_SIZE);
}
}
}
if (code == KeyCode.DOWN) {
if(isPassable(code)) {
player.move(0, SQUARE_SIZE);
while (!atObjectLocation(generalObject).equals(generalObject)) {
generalObject = atObjectLocation(generalObject);
......@@ -258,7 +270,7 @@ public class DemoRuleThree {
* The rule is only established when "baba is win" or " rock is win" is connected
*/
public static void ruleChange() {
for (Wall obj:wallObjs) {
for (Wall obj: wallObjs) {
obj.setPassable(true);
}
ruleWin = false;
......@@ -267,8 +279,20 @@ public class DemoRuleThree {
|| nearObjectDown(wallKeyObj).equals(winObj) || nearObjectUp(wallKeyObj).equals(winObj)) {
ruleWin = true;
}
if (nearObjectLeft(wallTextTwo).equals(isObjTwo) && nearObjectRight(stopObj).equals(isObjTwo)) {
if (nearObjectLeft(babaObj).equals(winObj) || nearObjectRight(babaObj).equals(winObj)
|| nearObjectDown(babaObj).equals(winObj) || nearObjectUp(babaObj).equals(winObj)) {
ruleWin = true;
}
if (nearObjectLeft(wallTextTwo).equals(isObjOne) && nearObjectRight(stopObj).equals(isObjOne)) {
for (Wall obj: wallObjs) {
obj.setPassable(false);
}
ruleWall = true;
}
}
}
\ No newline at end of file
......@@ -141,7 +141,11 @@ public class DemoRuleTwo {
return generalObject;
}
/**
* Checks if object is passable
* @param code - keyboard input
* @return true if is, false otherwise
*/
public static boolean isPassable(KeyCode code) {
switch (code) {
case DOWN:
......@@ -180,6 +184,10 @@ public class DemoRuleTwo {
return false;
}
/**
* Check if character is movable and move if character is movable
* @param code - Keyboard input
*/
public static void moveCharacter(KeyCode code) {
GeneralObject generalObject = player;
if (player.isPushable()) {
......
package Rule;
import gameManager.GameManager;
import javafx.animation.Animation;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
......@@ -87,13 +88,13 @@ public class TestGUIOne extends Application {
stage.setTitle("Baba Is You");
stage.show();
//Timeline for character animation
timeline = new Timeline(new KeyFrame(new Duration(10), e -> run()));
timeline.setCycleCount(Animation.INDEFINITE);
timeline.play();
}
/**
* Check the keyboard input and move the character
*/
private void keyboardInput() {
scene.setOnKeyPressed(event -> {
......@@ -102,6 +103,9 @@ public class TestGUIOne extends Application {
});
}
/**
* Run everything
*/
private void run(){
colorBackground();
drawBabaObj();
......@@ -110,11 +114,18 @@ public class TestGUIOne extends Application {
drawWinObj();
DemoRuleOne.changeCharacter();
DemoRuleOne.ruleChange();
DemoRuleOne.isWin();
if (DemoRuleOne.isWin()){
TestGUITwo secondLvl = new TestGUITwo();
secondLvl.createScene();
GameManager.gamePrimaryStage.setScene(secondLvl.getScene());
timeline.stop();
}
}
/**
* Draw the objects
*/
private void drawBabaObj(){
gc.drawImage(DemoRuleOne.babaObj.getImage(), DemoRuleOne.babaObj.getX(), DemoRuleOne.babaObj.getY());
}
......
package Rule;
import gameManager.GameManager;
import javafx.animation.Animation;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
......@@ -12,6 +13,7 @@ import javafx.scene.input.KeyCode;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import javafx.util.Duration;
import gameboard.ExitScene;
import static javafx.application.Platform.exit;
......@@ -52,6 +54,7 @@ public class TestGUIThree extends Application {
protected static Stage stage;
/** The in-game menu */
private KeyCode code;
private Timeline timeline;
public static void main(String[] args) {
launch(args);
......@@ -87,10 +90,6 @@ public class TestGUIThree extends Application {
stage.setTitle("BabaIs You");
stage.show();
//Timeline for character animation
Timeline timeline = new Timeline(new KeyFrame(new Duration(100), e -> run()));
timeline.setCycleCount(Animation.INDEFINITE);
timeline.play();
}
......@@ -113,7 +112,11 @@ public class TestGUIThree extends Application {
drawWallKeyObj();
DemoRuleThree.changeCharacter();
DemoRuleThree.ruleChange();
if (DemoRuleThree.isWin()){exit();};
if (DemoRuleThree.isWin()){
ExitScene.generateMessage();
GameManager.gamePrimaryStage.setScene(ExitScene.getExitScene());
timeline.stop();
};
}
......@@ -186,7 +189,7 @@ public class TestGUIThree extends Application {
keyboardInput();
//Timeline for character animation
Timeline timeline = new Timeline(new KeyFrame(new Duration(100), e -> run()));
timeline = new Timeline(new KeyFrame(new Duration(100), e -> run()));
timeline.setCycleCount(Animation.INDEFINITE);
timeline.play();
}
......
package Rule;
import gameManager.GameManager;
import javafx.animation.Animation;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
......@@ -52,6 +53,7 @@ public class TestGUITwo extends Application {
protected static Stage stage;
/** The in-game menu */
private KeyCode code;
private Timeline timeline;
public static void main(String[] args) {
launch(args);
......@@ -87,10 +89,6 @@ public class TestGUITwo extends Application {
stage.setTitle("Rule.Baba Rule.Is You");
stage.show();
//Timeline for character animation
Timeline timeline = new Timeline(new KeyFrame(new Duration(100), e -> run()));
timeline.setCycleCount(Animation.INDEFINITE);
timeline.play();
}
......@@ -112,7 +110,12 @@ public class TestGUITwo extends Application {
drawWinObj();
DemoRuleTwo.changeCharacter();
DemoRuleTwo.ruleChange();
if (DemoRuleTwo.isWin()){exit();};
if (DemoRuleTwo.isWin()){
TestGUIThree thirdLvl = new TestGUIThree();
thirdLvl.createScene();
GameManager.gamePrimaryStage.setScene(thirdLvl.getScene());
timeline.stop();
};
}
......@@ -180,7 +183,7 @@ public class TestGUITwo extends Application {
keyboardInput();
//Timeline for character animation
Timeline timeline = new Timeline(new KeyFrame(new Duration(100), e -> run()));
timeline = new Timeline(new KeyFrame(new Duration(100), e -> run()));
timeline.setCycleCount(Animation.INDEFINITE);
timeline.play();
}
......
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