Commit 320e10e6 authored by Nguyen Nguyen's avatar Nguyen Nguyen
Browse files

added a goodbye screen and restart the lvl

parent dc22b1e8
......@@ -33,11 +33,11 @@ public class BabaIsYouGameGUIController {
/** The width of the board */
private static final int WIDTH = 800;
/** The height of the board */
private static final int HEIGHT = 800;
private static final int HEIGHT = 600;
/** The number of rows of the board */
private static final int ROWS = 40;
/** The number of columns of the board */
private static final int COLUMNS = 40;
private static final int COLUMNS = 30;
/** The size of a square */
private static final int SQUARE_SIZE = WIDTH/ROWS;
......@@ -46,16 +46,26 @@ public class BabaIsYouGameGUIController {
private int moveDown = 1;
private int moveRight = 1;
private int moveLeft = 1;
private int countLvl2 = 0;
private int countLvl3 = 0;
private static Color defaultBackground = setDefaultBackground();
/** For the levels to maintain their state */
private static int countLvl1 = 0;
private static int countLvl2 = 0;
private static int countLvl3 = 0;
/** Character color */
private KeyCode code;
/** The current level */
private static int currentLvl = 1;
/** Setting up theModel and theView */
private BabaIsYouGameGUIModel theModel;
private BabaIsYouGameGUIView theView;
public BabaIsYouGameGUIController(BabaIsYouGameGUIView theView, BabaIsYouGameGUIModel theModel){
this.theModel = new BabaIsYouGameGUIModel();
this.theView = new BabaIsYouGameGUIView(theModel);
......@@ -71,35 +81,41 @@ public class BabaIsYouGameGUIController {
}
private void run(){
if (theModel.getCurrentLvl() == 1) {
theModel.setObjs(generateObjLvl1());
//generateKeyObjsLvl1();
if (getCurrentLvl() == 1) {
countLvl1 += 1;
if (countLvl1 <= 1) {
theModel.setObjs(generateObjLvl1());
BabaIsYouGameGUIModel.setBabaObj(new Point(600, 400));
BabaIsYouGameGUIModel.setIsObj(new Point(80, 200));
BabaIsYouGameGUIModel.setPassObj(new Point(700, 200));
BabaIsYouGameGUIModel.setWinObj(new Point(100, 100));
}
}
else if (theModel.getCurrentLvl() == 2) {
else if (getCurrentLvl() == 2) {
countLvl2+= 1;
theModel.setObjs(generateObjLvl2());
if (countLvl2 <= 1) {
theModel.setObjs(generateObjLvl2());
BabaIsYouGameGUIModel.setBabaObj(new Point(600, 400));
BabaIsYouGameGUIModel.setIsObj(new Point(80, 200));
BabaIsYouGameGUIModel.setPassObj(new Point(700, 200));
BabaIsYouGameGUIModel.setWinObj(new Point(100, 100));
}
}
else if (theModel.getCurrentLvl() == 3){
else if (getCurrentLvl() == 3){
countLvl3 += 1;
theModel.setObjs(generateObjLvl3());
if (countLvl3 <= 1) {
theModel.setObjs(generateObjLvl3());
BabaIsYouGameGUIModel.setBabaObj(new Point(600, 400));
BabaIsYouGameGUIModel.setIsObj(new Point(80, 200));
BabaIsYouGameGUIModel.setPassObj(new Point(700, 200));
BabaIsYouGameGUIModel.setWinObj(new Point(100, 100));
}
}
else if (getCurrentLvl() > 3){
goToExit();
}
keyboardInput();
colorBackground();
colorBackground(defaultBackground);
colorCharacter(theModel.getCurrentColor());
drawObj();
drawPassObj();
......@@ -179,77 +195,77 @@ public class BabaIsYouGameGUIController {
return objs;
}
private void generateKeyObjsLvl1(){
theModel.setBabaObj(new Point(100, 100));
theModel.setIsObj(new Point(80, 200));
theModel.setPassObj(new Point(200, 200));
theModel.setWinObj(new Point(400, 400));
}
//
// private void generateKeyObjsLvl1(){
// theModel.setBabaObj(new Point(2* SQUARE_SIZE,2* SQUARE_SIZE)) ;
// theModel.setIsObj(new Point(3* SQUARE_SIZE,3* SQUARE_SIZE)) ;
// theModel.setPassObj(new Point(4* SQUARE_SIZE,4* SQUARE_SIZE)) ;
// theModel.setWinObj(new Point(5* SQUARE_SIZE,5* SQUARE_SIZE)) ;
// }
//
// private void generateKeyObjsLvl2(){
// theModel.setBabaObj(new Point(2* SQUARE_SIZE,5* SQUARE_SIZE)) ;
// theModel.setIsObj(new Point(4* SQUARE_SIZE,9* SQUARE_SIZE)) ;
// theModel.setPassObj(new Point(8* SQUARE_SIZE,3* SQUARE_SIZE)) ;
// theModel.setWinObj(new Point(12* SQUARE_SIZE,10* SQUARE_SIZE)) ;
// }
//
// private void generateKeyObjsLvl3(){
// theModel.setBabaObj(new Point(10* SQUARE_SIZE,4* SQUARE_SIZE)) ;
// theModel.setIsObj(new Point(12* SQUARE_SIZE,9* SQUARE_SIZE)) ;
// theModel.setPassObj(new Point(15* SQUARE_SIZE,8* SQUARE_SIZE)) ;
// theModel.setWinObj(new Point(2* SQUARE_SIZE,19* SQUARE_SIZE)) ;
// }
/**
* Checks the keyboard input of user and move the character to the input
* Go to the in-game menu if user choose ESC button
*/
private void keyboardInput() {
GameManager.scene.setOnKeyPressed(event -> {
code = event.getCode();
if (code == KeyCode.RIGHT){
theModel.getCharacter().x += moveRight;
BabaIsYouGameGUIModel.getCharacter().x += moveRight;
} else if (code == KeyCode.LEFT){
theModel.getCharacter().x -= moveLeft;
BabaIsYouGameGUIModel.getCharacter().x -= moveLeft;
} else if (code == KeyCode.UP){
theModel.getCharacter().y -= moveUp;
BabaIsYouGameGUIModel.getCharacter().y -= moveUp;
} else if (code == KeyCode.DOWN){
theModel.getCharacter().y+= moveDown;
BabaIsYouGameGUIModel.getCharacter().y+= moveDown;
} else if (code == KeyCode.ESCAPE){
goToInGameMenu();
}
});
}
/**
* If is next level, go to next level, as we've won the current level
*/
private void checkWinCondition(){
int checker = theModel.getCurrentLvl();
if (theModel.isNextLvl() && (theModel.getCurrentLvl() == checker))
theModel.goToNextLvl();
if (isNextLvl())
goToNextLvl();
}
public void goToNextLvl() {
currentLvl++;
}
public static int getCurrentLvl() {
return currentLvl;
}
/**
* Check if Baba-Is-Win is viable. Return true if so.
* @return true if Baba-Is-Pass, false otherwise
*/
public boolean isNextLvl(){
if (theModel.getBabaObj().getX() == (theModel.getIsObj().getX()-SQUARE_SIZE) && (theModel.getIsObj().getX() == (theModel.getWinObj().getX()-SQUARE_SIZE))
&& (theModel.getBabaObj().getY() == (theModel.getIsObj().getY())) && (theModel.getIsObj().getY() == (theModel.getWinObj().getY()))){
return true;
}
return false;
}
/**
* Check the interaction and the current state of the character and the normal objects
* If the object is not passable or the character is at an edge, make the character unmovable
*/
private void checkInteraction(){
if (!theModel.isPassable()) {
if (theModel.nearObjectLeft())
if (theModel.nearObjectLeft() || (theModel.getCharacter().getX() == ROWS -1))
moveRight = 0;
else {
moveRight = 1;
}
if (theModel.nearObjectRight())
if (theModel.nearObjectRight() || (theModel.getCharacter().getX() == 0))
moveLeft = 0;
else {
moveLeft = 1;
}
if (theModel.nearObjectDown())
if (theModel.nearObjectDown() || (theModel.getCharacter().getY() == 0))
moveUp = 0;
else {
moveUp = 1;
}
if (theModel.nearObjectUp())
if (theModel.nearObjectUp() || (theModel.getCharacter().getY() == COLUMNS - 1))
moveDown = 0;
else {
moveDown = 1;
......@@ -257,6 +273,7 @@ public class BabaIsYouGameGUIController {
}
}
/**
* Go to in-game menu by calling In-Game Menu methods
*/
......@@ -268,12 +285,16 @@ public class BabaIsYouGameGUIController {
}
private void goToExit(){
ExitScene.generateMessage();
GameManager.gamePrimaryStage.setScene(ExitScene.getExitScene());
}
/**
* colors the background
*/
private void colorBackground(){
theView.getGc().setFill(Color.BLACK);
theView.getGc().fillRect(0, 0, 800,800);
private void colorBackground(Color color){
theView.getGc().setFill(color);
theView.getGc().fillRect(0, 0, 800,600);
}
/**
......@@ -295,20 +316,33 @@ public class BabaIsYouGameGUIController {
}
}
/**
* Draw the Pass object
*/
private void drawPassObj(){
theView.getGc().setFill(Color.RED);
theView.getGc().fillRect(BabaIsYouGameGUIModel.getPassObj().getX(), BabaIsYouGameGUIModel.getPassObj().getY(), SQUARE_SIZE - 1, SQUARE_SIZE - 1);
}
/**
* Draw the Is object
*/
private void drawIsObj(){
theView.getGc().setFill(Color.BLUE);
theView.getGc().fillRect(BabaIsYouGameGUIModel.getIsObj().getX(), BabaIsYouGameGUIModel.getIsObj().getY(), SQUARE_SIZE - 1, SQUARE_SIZE - 1);
}
/**
* Draw the Baba object
*/
private void drawBaBaObj(){
theView.getGc().setFill(Color.PURPLE);
theView.getGc().fillRect(BabaIsYouGameGUIModel.getBabaObj().getX(), BabaIsYouGameGUIModel.getBabaObj().getY(), SQUARE_SIZE - 1, SQUARE_SIZE - 1);
}
/**
* Draw the Win object
*/
private void drawWinObj(){
theView.getGc().setFill(Color.PINK);
theView.getGc().fillRect(BabaIsYouGameGUIModel.getWinObj().getX(), BabaIsYouGameGUIModel.getWinObj().getY(), SQUARE_SIZE - 1, SQUARE_SIZE - 1);
......@@ -332,6 +366,23 @@ public class BabaIsYouGameGUIController {
}
}
public static void setCountLvl1(int newCountLvl1) {
countLvl1 = newCountLvl1;
}
public static void setCountLvl2(int newCountLvl2) {
countLvl2 = newCountLvl2;
}
public static void setCountLvl3(int newCountLvl3) {
countLvl3 = newCountLvl3;
}
public static void setDefaultBackground(Color newDefaultBackground) {
defaultBackground = newDefaultBackground;
}
private static javafx.scene.paint.Color setDefaultBackground(){
return Color.BLACK;
}
}
......@@ -31,19 +31,19 @@ public class BabaIsYouGameGUIModel {
/** The width of the board */
private static final int WIDTH = 800;
/** The height of the board */
private static final int HEIGHT = 800;
private static final int HEIGHT = 600;
/** The number of rows of the board */
private static final int ROWS = 40;
/** The number of columns of the board */
private static final int COLUMNS = 40;
private static final int COLUMNS = 30;
/** The size of a square */
private static final int SQUARE_SIZE = WIDTH/ROWS;
/** The character as a Point object */
private Point character = new Point(0,0);
private static Point character = new Point(0,0);
/** The objects */
private Point obj;
private int currentLvl = 1;
/** Key objects */
......@@ -57,35 +57,13 @@ public class BabaIsYouGameGUIModel {
/** List of objects */
private ArrayList<Point> objs;
// private ArrayList<GeneralObject> entityList;
// private ArrayList<GeneralObject> nameWordList;
// private ArrayList<GeneralObject> connectorWordList = new ArrayList<GeneralObject>();
// private ArrayList<GeneralObject> ruleWordList = new ArrayList<GeneralObject>();
/** The in-game scene */
protected static Scene scene;
public BabaIsYouGameGUIModel(){
}
// private void generateObjsFromList(GeneralObject[] objList) {
// for (int i=0; i<objList.length; i++){
// if (objList[i].getType().equals("Entity"))
// entityList.add(objList[i]);
// else if (objList[i].getType().equals("NameWord"))
// nameWordList.add(objList[i]);
// else if (objList[i].getType().equals("RuleWord"))
// ruleWordList.add(objList[i]);
// else if (objList[i].getType().equals("ConnectorWord"))
// connectorWordList.add(objList[i]);
//
// }
// }
public BabaIsYouGameGUIModel(){}
/**
......@@ -150,17 +128,7 @@ public class BabaIsYouGameGUIModel {
return false;
}
/**
* Check if Baba-Is-Win is viable. Return true if so.
* @return true if Baba-Is-Pass, false otherwise
*/
public boolean isNextLvl(){
if (babaObj.getX() == (isObj.getX()-SQUARE_SIZE) && (isObj.getX() == (winObj.getX()-SQUARE_SIZE))
&& (babaObj.getY() == (isObj.getY())) && (isObj.getY() == (winObj.getY()))){
return true;
}
return false;
}
/**
* Default color
......@@ -177,7 +145,7 @@ public class BabaIsYouGameGUIModel {
return currentColor;
}
public Point getCharacter() {
public static Point getCharacter() {
return character;
}
......@@ -201,13 +169,6 @@ public class BabaIsYouGameGUIModel {
return objs;
}
public void goToNextLvl() {
currentLvl++;
}
public int getCurrentLvl() {
return currentLvl;
}
public void setObjs(ArrayList<Point> objs) {
this.objs = objs;
......
......@@ -28,7 +28,7 @@ public class BabaIsYouGameGUIView {
/** The width of the board */
private static final int WIDTH = 800;
/** The height of the board */
private static final int HEIGHT = 800;
private static final int HEIGHT = 600;
/** The number of rows of the board */
private static final int ROWS = 40;
/** The number of columns of the board */
......@@ -50,8 +50,10 @@ public class BabaIsYouGameGUIView {
private static Canvas canvas;
/** The in-game scene */
protected static Scene scene;
private BabaIsYouGameGUIModel theModel;
public BabaIsYouGameGUIView(BabaIsYouGameGUIModel theModel){
this.theModel = new BabaIsYouGameGUIModel();
//Setting up the screen...
root = new Group();
canvas = new Canvas(WIDTH, HEIGHT);
......@@ -61,6 +63,7 @@ public class BabaIsYouGameGUIView {
gc = canvas.getGraphicsContext2D();
}
public Group getRoot() {
return root;
}
......
/* *****************************************
* CSCI205 - Software Engineering and Design
* Spring 2021
* Instructor: Prof. Chris Dancy
*
* Name: Nguyen Nguyen
* Section: Section 02 - 1:50-2:42am
* Date: 5/18/2021
* Time: 11:55 AM
*
* Project: CSCI205SP21finalproject
* Package: gameboard
* Class: ExitScene
*
* Description: THIS IS A DESCRIPTION Y’ALL AND I NEED TO CHANGE THIS!
*
* ****************************************
*/
package gameboard;
import gameManager.GameManager;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
public class ExitScene {
/** The width of the board */
private static final int WIDTH = 800;
/** The height of the board */
private static final int HEIGHT = 600;
/** The scene */
private static Scene exitScene;
public static void generateMessage() {
VBox layout = new VBox();
layout.setAlignment(Pos.CENTER);
layout.getStyleClass().add("with-opaque-background");
Label exitMessage = new Label("Congratulations!!! The game was easy, right?\nIt took a long time to develop though....\nIt's the end. Time to exit the game");
exitMessage.getStyleClass().add("wide-blue-text");
layout.getChildren().addAll(exitMessage);
exitScene = new Scene(layout, WIDTH, HEIGHT);
exitScene.getStylesheets().add(GameManager.styleSheet);
}
public static Scene getExitScene() {
return exitScene;
}
}
......@@ -38,13 +38,12 @@ public class InGameMenu {
private static final int WIDTH = 800;
/** The height of the board */
private static final int HEIGHT = 600;
/** The number of rows of the board */
private static final int ROWS = 40;
/** The BabaIsYou game GUI */
private static BabaIsYouGameGUIMain gameGUI;
/** The scenes */
private static Scene menuScene, hintScene, customizeScene;
private static BabaIsYouGameGUIModel theModel;
private static BabaIsYouGameGUIController theController;
/**
* Generate the in-game menu after we pressed ESC while playing
......@@ -63,6 +62,16 @@ public class InGameMenu {
GameManager.gamePrimaryStage.setScene(customizeScene);
});
Button restartButton = new Button("Restart");
restartButton.setOnAction(event -> {
System.out.println(BabaIsYouGameGUIController.getCurrentLvl());
if (BabaIsYouGameGUIController.getCurrentLvl() == 1) {
BabaIsYouGameGUIController.setCountLvl1(0);
}
else if (BabaIsYouGameGUIController.getCurrentLvl() == 2)
BabaIsYouGameGUIController.setCountLvl2(0);
else if (BabaIsYouGameGUIController.getCurrentLvl() == 3)
BabaIsYouGameGUIController.setCountLvl3(0);
});
Button hintButton = new Button("Get hint");
hintButton.setOnAction(event -> {
GameManager.gamePrimaryStage.setScene(hintScene);
......@@ -100,12 +109,15 @@ public class InGameMenu {
});
backButton.getStyleClass().add("wide-blue-text");
Label temp1 = new Label("Hint for lvl 1");
Label temp2 = new Label("Hint for lvl 2");
hintLayout.getChildren().addAll(temp1, temp2, backButton);
temp1.getStyleClass().add("wide-blue-text");
temp2.getStyleClass().add("wide-blue-text");
Label hint1 = new Label("Hint for lvl 1: Purple-Blue-Red to pass through Orange,\nPurple-Blue-Pink to win and go to next level");
Label hint2 = new Label("Hint for lvl 2: Same as level 1 ");
Label hint3 = new Label("Hint for lvl 3: get Purple-Blue-Red first ");
hintLayout.getChildren().addAll(hint1, hint2, hint3, backButton);
hint1.getStyleClass().add("wide-blue-text");
hint2.getStyleClass().add("wide-blue-text");
hint3.getStyleClass().add("wide-blue-text");
hintScene = new Scene(hintLayout, WIDTH, HEIGHT);
hintScene.getStylesheets().add(GameManager.styleSheet);
}
......@@ -124,17 +136,15 @@ public class InGameMenu {
GameManager.gamePrimaryStage.setScene(menuScene);
});
FlowPane radioButtonHolder = new FlowPane(Orientation.VERTICAL);
VBox radioButtonHolder = new VBox();
radioButtonHolder.setAlignment(Pos.TOP_LEFT);
radioButtonHolder.setMaxHeight(120);
radioButtonHolder.setMaxWidth(260);
radioButtonHolder.setMaxWidth(400);
Label temp1 = new Label("Adjust character color");
RadioButton btnCharBlue = new RadioButton("Blue");
btnCharBlue.setOnAction(event -> {
theModel.setCurrentColor(Color.BLUE);
});
RadioButton btnCharWhite = new RadioButton("White");
btnCharWhite.setOnAction(event -> {
theModel.setCurrentColor(Color.WHITE);
......@@ -144,10 +154,9 @@ public class InGameMenu {
theModel.setCurrentColor(Color.YELLOW);
});
radioButtonHolder.getChildren().addAll(temp1, btnCharBlue, btnCharWhite, btnCharYellow);
radioButtonHolder.getChildren().addAll(temp1, btnCharWhite, btnCharYellow);
Label temp2 = new Label("Adjust color of blocks");
customizeLayout.getChildren().addAll(radioButtonHolder, temp2, backButton);
customizeLayout.getChildren().addAll(radioButtonHolder, backButton);
customizeScene = new Scene(customizeLayout, WIDTH, HEIGHT);
customizeScene.getStylesheets().add(GameManager.styleSheet);
}
......
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