Commit 5d129b42 authored by Yuhan Chen's avatar Yuhan Chen
Browse files

Merge remote-tracking branch 'origin/master' into master

# Conflicts:
#	build.gradle
#	src/main/java/BabaIsYouGameGUI.java
#	src/main/java/gameboard/BabaIsYouGameGUIModel.java
#	src/main/java/instructions/InstructionsView.java
parents fe25bb21 a227f933
......@@ -20,11 +20,10 @@ test {
// Needs to be either 11.0.2 or 14.0.2
javafx {
version = "14.0.2"
modules = [ 'javafx.controls', 'javafx.fxml' ]
modules = [ 'javafx.controls', 'javafx.fxml', 'javafx.media' ]
}
dependencies {
implementation 'org.jetbrains:annotations:20.1.0'
testImplementation('org.junit.jupiter:junit-jupiter:5.6.2')
implementation 'org.junit.jupiter:junit-jupiter:5.6.2'
}
application {
mainClassName = project.hasProperty("mainClass") ? project.getProperty("mainClass") :
......
@font-face {
font-family: 'Fleftex';
src: url("fonts/Fleftex_M.ttf");
}
.label {
-fx-font-family: 'Fleftex';
-fx-font-size: 20;
}
\ No newline at end of file
@font-face {
font-family: "Fleftex";
src: url("fonts/Fleftex_M.ttf");
}
* {
-fx-font-family: "Fleftex";
-fx-font-size: 16;
-fx-text-fill: white;
}
.wide-blue-text{
-fx-background-color: rgba(59, 130, 246, 0.6);
-fx-accent: rgba(96, 165, 250, 0.6);
-fx-border-radius: 0;
-fx-border-color: rgba(147, 197, 253, 1) ;
-fx-alignment: center;
-fx-padding: 1px 0 1px 0;
-fx-min-width: 350px;
}
.white-text{
-fx-text-fill: white;
}
.button{
-fx-background-color: rgba(59, 130, 246, 0.6);
-fx-border-radius: 0;
-fx-border-color: rgba(147, 197, 253, 1) ;
-fx-padding: 0 100px 0 100px;
}
.with-opaque-background{
-fx-background-image: url("image/menu-background-opaque.png");
-fx-background-size: 100%;
-fx-background-color: rgba(255, 255, 255, 0.8);
}
.scroll-pane .track{
-fx-stroke-width: 1;
-fx-stroke: -c-dark-glass;
-fx-arc-width: 16px;
-fx-arc-height: 16px;
-fx-fill: transparent;
}
.scroll-pane .thumb {
-fx-fill: transparent;
-fx-arc-width: 16px;
-fx-arc-height: 16px;
}
.scroll-pane
{
-fx-background-color: transparent;
}
.scroll-pane > .viewport{
-fx-background-color: transparent;
}
/* entire scroll bar */
.scroll-bar:horizontal, .scroll-bar:vertical{
-fx-background-color:transparent;
}
.increment-button, .decrement-button {
-fx-background-color: transparent;
-fx-border-color: transparent;
}
/* area around the scroller on the right */
.scroll-bar:horizontal .track,
.scroll-bar:vertical .track{
-fx-background-color: transparent;
-fx-border-color: transparent;
-fx-background-radius: 0em;
}
/*the scroller*/
.scroll-bar:vertical .thumb {
-fx-background-color: rgba(55, 65, 81, 1);
-fx-background-radius: 5em;
}
/* *****************************************
* CSCI205 - Software Engineering and Design
* Spring 2021
* Instructor: Prof. Chris Dancy
*
* Name: Nguyen Nguyen
* Section: Section 02 - 1:50-2:42am
* Date: 5/13/2021
* Time: 10:11 PM
*
* Project: CSCI205SP21finalproject
* Package: PACKAGE_NAME
* Class: BabaIsYouGameGUI
*
* Description: THIS IS A DESCRIPTION Y’ALL AND I NEED TO CHANGE THIS!
*
* ****************************************
*/
import javafx.animation.Animation;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.control.RadioButton;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
import javafx.stage.Stage;
import javafx.util.Duration;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import java.awt.*;
import java.util.ArrayList;
import java.util.Random;
/**
* The BabaIsYouGameGUI, with the game board, character and objects
*
* Source of reference:
* @see
* <a href=" https://github.com/mahmoudhamwi/Snake/blob/main/Snake/src/sample/Main.java">
* https://github.com/mahmoudhamwi/Snake/blob/main/Snake/src/sample/Main.java</a>
*/
public class BabaIsYouGameGUI extends Application {
/** The width of the board */
private static final int WIDTH = 800;
/** The height of the board */
private static final int HEIGHT = 800;
/** 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;
/** The size of a square */
private static final int SQUARE_SIZE = WIDTH/ROWS;
/** The image for object */
private static final String [] OBJ_IMAGES = new String[]{};
/** Graphics for game */
private GraphicsContext gc;
/** The character as a Point object */
private Point character = new Point(0,0);
/** The objects */
private Point obj;
/** For character movement */
private int moveUp = 1;
private int moveDown = 1;
private int moveRight = 1;
private int moveLeft = 1;
/** Key objects */
private Point babaObj = new Point(2* SQUARE_SIZE,2* SQUARE_SIZE);
private Point isObj = new Point(3* SQUARE_SIZE,3* SQUARE_SIZE);
private Point passObj = new Point(4* SQUARE_SIZE,4* SQUARE_SIZE);
/** Character color */
protected static Color currentColor = defaultColor();
/** List of objects */
private ArrayList<Point> objs = generateObj();
private Image objImage;
/** The root */
private static Group root;
/** The in-game layout */
private static Canvas canvas;
/** The in-game scene */
protected static Scene scene;
/** The stage */
protected static Stage stage;
/** The in-game menu */
private InGameMenu inGameMenu;
private KeyCode code;
public static void main(String[] args) {
launch(args);
}
// /**
// * Every game level is created by feeding a BabaIsYouGameGUI object a list of
// * GeneralObjects and dimensions to generate a Board. Each object contains a certain type
// * and coordinates to be placed on the board.
// *
// * @param objList list of GeneralObjects with coordinates within the given board parameters
// * @param boardHeight height of the board generated
// * @param boardWidth width of the board generated
// */
// public BabaIsYouGameGUI(Rule.GeneralObject[] objList, int boardHeight, int boardWidth){
//
// }
@Override
public void start(Stage primaryStage) {
//The stage
stage = primaryStage;
//Setting up the screen...
root = new Group();
canvas = new Canvas(WIDTH, HEIGHT);
root.getChildren().add(canvas);
scene = new Scene(root);
//Initiate the graphic context gc
gc = canvas.getGraphicsContext2D();
//Changing the characters coordinate based on key press
keyboardInput();
//Setting the scene
stage.setScene(scene);
stage.setTitle("Rule.Baba Rule.Is You");
stage.show();
//Timeline for character animation
Timeline timeline = new Timeline(new KeyFrame(new Duration(10), e -> run()));
timeline.setCycleCount(Animation.INDEFINITE);
timeline.play();
}
private void keyboardInput() {
scene.setOnKeyPressed(event -> {
code = event.getCode();
if (code == KeyCode.RIGHT){
character.x += moveRight;
} else if (code == KeyCode.LEFT){
character.x -= moveLeft;
} else if (code == KeyCode.UP){
character.y -= moveUp;
} else if (code == KeyCode.DOWN){
character.y+= moveDown;
} else if (code == KeyCode.ESCAPE){
goToInGameMenu();
}
});
}
private void run(){
colorBackground();
colorCharacter(currentColor);
drawObj();
drawPassObj();
drawBaBaObj();
drawIsObj();
checkInteraction();
nearKeyObject(babaObj);
nearKeyObject(isObj);
nearKeyObject(passObj);
}
/**
* Go to in-game menu by calling In-Game Menu methods
*/
private void goToInGameMenu(){
InGameMenu.generateInGameMenu();
InGameMenu.generateHint();
InGameMenu.generateCustomizeTheme();
stage.setScene(InGameMenu.getMenuScene());
}
/**
* Initializes a list of objects with coordinates
* @return list of objects
*/
private ArrayList<Point> generateObj(){
ArrayList<Point> objs = new ArrayList<Point>();
for (int i = 10; i< 21; i++) {
int x = (i) * SQUARE_SIZE;
int y = (i) * SQUARE_SIZE;
obj = new Point(x, y);
objs.add(obj);
}
return objs;
}
/**
* Colors the objects based on its coordinate
*/
private void drawObj(){
for (Point obj: objs) {
gc.setFill(Color.ORANGE);
gc.fillRect(obj.getX(), obj.getY(), SQUARE_SIZE - 1, SQUARE_SIZE - 1);
}
}
private void drawPassObj(){
gc.setFill(Color.RED);
gc.fillRect(passObj.getX(), passObj.getY(), SQUARE_SIZE - 1, SQUARE_SIZE - 1);
}
private void drawIsObj(){
gc.setFill(Color.BLUE);
gc.fillRect(isObj.getX(), isObj.getY(), SQUARE_SIZE - 1, SQUARE_SIZE - 1);
}
private void drawBaBaObj(){
gc.setFill(Color.PURPLE);
gc.fillRect(babaObj.getX(), babaObj.getY(), SQUARE_SIZE - 1, SQUARE_SIZE - 1);
}
/**
* Check the interaction and the current state of the character and the normal objects
*/
private void checkInteraction(){
if (!isPassable()) {
if (nearObjectLeft())
moveRight = 0;
else {
moveRight = 1;
}
if (nearObjectRight())
moveLeft = 0;
else {
moveLeft = 1;
}
if (nearObjectDown())
moveUp = 0;
else {
moveUp = 1;
}
if (nearObjectUp())
moveDown = 0;
else {
moveDown = 1;
}
}
}
/**
* Check if the character is on the left a normal object
* @return true/false
*/
private boolean nearObjectLeft(){
for (Point obj: objs) {
if (character.getX()*SQUARE_SIZE == (obj.getX() - 1*SQUARE_SIZE) && character.getY()*SQUARE_SIZE == obj.getY()) {
return true;
}
}
return false;
}
/**
* Check if the character is on the right a normal object
* @return true/false
*/
private boolean nearObjectRight(){
for (Point obj: objs) {
if (character.getX()*SQUARE_SIZE == (obj.getX() + 1*SQUARE_SIZE) && character.getY()*SQUARE_SIZE == obj.getY())
return true;
}
return false;
}
/**
* Check if the character is above a normal object
* @return true/false
*/
private boolean nearObjectUp(){
for (Point obj: objs) {
if (character.getX()*SQUARE_SIZE == (obj.getX()) && character.getY()*SQUARE_SIZE == obj.getY() - 1*SQUARE_SIZE )
return true;
}
return false;
}
/**
* Check if the character is below a normal object
* @return true/false
*/
private boolean nearObjectDown(){
for (Point obj: objs) {
if (character.getX()*SQUARE_SIZE == (obj.getX()) && character.getY()*SQUARE_SIZE == obj.getY() + 1*SQUARE_SIZE )
return true;
}
return false;
}
/**
* Check if the character is near the key objects (baba-is-pass)
* @param keyObj baba-is-pass objects
*/
private void nearKeyObject(Point keyObj){
if (character.getX()*SQUARE_SIZE == (keyObj.getX()) && character.getY()*SQUARE_SIZE == keyObj.getY()) {
if (code == KeyCode.RIGHT)
keyObj.x += SQUARE_SIZE;
else if (code == KeyCode.LEFT)
keyObj.x -= SQUARE_SIZE;
else if (code == KeyCode.UP)
keyObj.y -= SQUARE_SIZE;
else if (code == KeyCode.DOWN)
keyObj.y+= SQUARE_SIZE;
}
}
/**
* Check if Rule.Baba-Rule.Is-Pass is viable. Return true if so.
* @return true if Rule.Baba-Rule.Is-Pass, false otherwise
*/
private boolean isPassable(){
if (babaObj.getX() == (isObj.getX()-SQUARE_SIZE) && (isObj.getX() == (passObj.getX()-SQUARE_SIZE))
&& (babaObj.getY() == (isObj.getY())) && (isObj.getY() == (passObj.getY()))){
return true;
}
return false;
}
/**
* colors the background
*/
private void colorBackground(){
gc.setFill(Color.BLACK);
gc.fillRect(0, 0, 800,800);
}
/**
* colors the character
* @param color - The desired color
*/
private void colorCharacter(Color color){
gc.setFill(color);
gc.fillRect(character.getX()*SQUARE_SIZE, character.getY()*SQUARE_SIZE, SQUARE_SIZE-1, SQUARE_SIZE-1);
}
/**
* Default color
*/
private static Color defaultColor(){
return Color.WHITE;
}
}
......@@ -22,6 +22,9 @@ import javafx.scene.image.Image;
/**
* ABSTRACT PARENT TO ALL GAME BOARD OBJECTS
*
* This class is the essential interface that all GameObjects inherit, in order to generate the game board
* as well as interactions between different objects easily.
*
* @author Christiaan
*/
public interface GeneralObject {
......
......@@ -2,15 +2,27 @@ package gameManager;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.media.MediaPlayer;
import javafx.stage.Stage;
import mediaPlayer.MusicPlayer;
/**
* Master application for the entire game itself, running this class begins the game and
* loads the user in the way the game is intended to be played.
*/
public class GameManager extends Application {
public static final int GAME_WIDTH = 800;
public static final int GAME_HEIGHT = 600;
private SceneManager manager;
private Scene scene;
public static Stage gamePrimaryStage;
public static Scene scene;
public static String styleSheet;
public MediaPlayer player; //manages the game sounds
public static void main(String[] args) {
launch(args);
......@@ -19,17 +31,37 @@ public class GameManager extends Application {
@Override
public void init() throws Exception {
super.init();
SceneManager manager = new SceneManager();
// creates the default scene
manager = new SceneManager();
}
@Override
public void start(Stage primaryStage) {
gamePrimaryStage = primaryStage;
scene = new Scene(SceneManager.getSceneRoot("game menu"));
scene.getStylesheets().add(getClass().getResource("/fontstyle.css").toExternalForm());
styleSheet = getClass().getResource("/style.css").toExternalForm();
scene.getStylesheets().add(styleSheet);
// populate the other scenes before user clicks
SceneManager.populateOtherScenes();
primaryStage.setScene(scene);
primaryStage.sizeToScene();
primaryStage.setTitle("Rule.Baba is Us");
primaryStage.show();
playMusic();
}
/**
* Manages the MusicPlayer of the game to load the soundtrack into it
*/
private void playMusic(){
// get media
MusicPlayer.getMedia("/src/main/Resources/music/BabaIsUsMusic.mp3");
// adjust vol
MusicPlayer.adjustVolume(50);
// play
MusicPlayer.putMediaOnLoop();
}
public Scene getScene() {
......
......@@ -18,10 +18,13 @@
*/
package gameManager;
import gameMenu.GameMenuMain;
import javafx.scene.Parent;
import levelMenu.LevelMenuMain;
import instructions.InstructionsMain;
import gameboard.BabaIsYouGameGUIMain;
import settings.SettingsMain;
import java.util.HashMap;
......@@ -29,6 +32,8 @@ public class SceneManager {
public static final String GAME_MENU = "game menu";
public static final String LEVEL_MENU = "level menu";
public static final String INSTRUCTIONS = "instructions";
public static final String GAMEPLAY = "gameplay";
public static final String SETTINGS = "settings";
private static HashMap<String, Parent> roots = new HashMap<>();
......@@ -36,12 +41,21 @@ public class SceneManager {
Parent GameMenuRoot = GameMenuMain.getRoot();
addSceneRoots(GAME_MENU, GameMenuRoot);
}
public static void populateOtherScenes(){
Parent LevelMenuRoot = LevelMenuMain.getRoot();
addSceneRoots(LEVEL_MENU, LevelMenuRoot);
Parent InstructionRoot = InstructionsMain.getRoot();
addSceneRoots(INSTRUCTIONS, InstructionRoot);
Parent GameplayRoot = BabaIsYouGameGUIMain.getRoot();
addSceneRoots(GAMEPLAY, GameplayRoot);
Parent SettingsRoot = SettingsMain.getRoot();
addSceneRoots(SETTINGS, SettingsRoot);
}
public static void addSceneRoots(String sceneName, Parent sceneRoot){
......
......@@ -12,16 +12,17 @@
* Package: gameMenu
* Class: GameMenuController
*
* Description: THIS IS A DESCRIPTION Y’ALL AND I NEED TO CHANGE THIS!
* Description: Controller for the GameMenu