Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Nguyen Nguyen
babaisus
Commits
2ce387a7
Commit
2ce387a7
authored
May 19, 2021
by
Nguyen Nguyen
Browse files
Merge branch 'master' of gitlab.bucknell.edu:yc017/csci205sp21finalproject
parents
3d1f41ab
1eee1a98
Changes
15
Hide whitespace changes
Inline
Side-by-side
src/main/java/Rule/TestGUIOne.java
View file @
2ce387a7
...
...
@@ -144,5 +144,39 @@ public class TestGUIOne extends Application {
return
Color
.
WHITE
;
}
/**
* Creates the scene normally, so that we can call from other scenes
* Only change from start() is that it does not use stage
*/
public
void
createScene
(){
//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
();
//Initiate the character to Rule.Baba
DemoRuleOne
.
player
=
DemoRuleOne
.
babaObj
;
//Initiate the objects list
DemoRuleOne
.
setObjs
(
DemoRuleOne
.
objs
);
//Changing the characters coordinate based on key press
keyboardInput
();
//Timeline for character animation
timeline
=
new
Timeline
(
new
KeyFrame
(
new
Duration
(
10
),
e
->
run
()));
timeline
.
setCycleCount
(
Animation
.
INDEFINITE
);
timeline
.
play
();
}
/**
* @return - the scene
*/
public
Scene
getScene
(){
return
scene
;
}
}
\ No newline at end of file
src/main/java/Rule/TestGUIThree.java
View file @
2ce387a7
...
...
@@ -161,5 +161,40 @@ public class TestGUIThree extends Application {
return
Color
.
WHITE
;
}
/**
* Creates the scene normally, so that we can call from other scenes
* Only change from start() is that it does not use stage
*/
public
void
createScene
(){
//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
();
//Initiate the character to Baba
DemoRuleThree
.
player
=
DemoRuleThree
.
babaObj
;
//Initiate the objects list
DemoRuleThree
.
setWallObjs
(
DemoRuleThree
.
wallObjs
);
DemoRuleThree
.
setObjs
(
DemoRuleThree
.
objs
);
//Changing the characters coordinate based on key press
keyboardInput
();
//Timeline for character animation
Timeline
timeline
=
new
Timeline
(
new
KeyFrame
(
new
Duration
(
100
),
e
->
run
()));
timeline
.
setCycleCount
(
Animation
.
INDEFINITE
);
timeline
.
play
();
}
/**
* @return - the scene
*/
public
Scene
getScene
(){
return
scene
;
}
}
\ No newline at end of file
src/main/java/Rule/TestGUITwo.java
View file @
2ce387a7
...
...
@@ -138,10 +138,6 @@ public class TestGUITwo extends Application {
}
}
public
static
Scene
getScene
()
{
return
scene
;
}
/**
* colors the background
...
...
@@ -159,5 +155,39 @@ public class TestGUITwo extends Application {
return
Color
.
WHITE
;
}
/**
* Creates the scene normally, so that we can call from other scenes
* Only change from start() is that it does not use stage
*/
public
void
createScene
(){
//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
();
//Initiate the character to Rule.Baba
DemoRuleTwo
.
player
=
DemoRuleTwo
.
babaObj
;
//Initiate the objects list
DemoRuleTwo
.
setWallObjs
(
DemoRuleTwo
.
wallObjs
);
DemoRuleTwo
.
setObjs
(
DemoRuleTwo
.
objs
);
//Changing the characters coordinate based on key press
keyboardInput
();
//Timeline for character animation
Timeline
timeline
=
new
Timeline
(
new
KeyFrame
(
new
Duration
(
100
),
e
->
run
()));
timeline
.
setCycleCount
(
Animation
.
INDEFINITE
);
timeline
.
play
();
}
/**
* @return - the scene
*/
public
Scene
getScene
(){
return
scene
;
}
}
\ No newline at end of file
src/main/java/gameManager/GameManager.java
View file @
2ce387a7
...
...
@@ -2,7 +2,6 @@ package gameManager;
import
javafx.application.Application
;
import
javafx.scene.Scene
;
import
javafx.scene.media.MediaPlayer
;
import
javafx.stage.Stage
;
import
mediaPlayer.MusicPlayer
;
...
...
@@ -11,19 +10,25 @@ import mediaPlayer.MusicPlayer;
* loads the user in the way the game is intended to be played.
*/
public
class
GameManager
extends
Application
{
/**
* Global game width, game height
*/
public
static
final
int
GAME_WIDTH
=
800
;
public
static
final
int
GAME_HEIGHT
=
600
;
// Scene manager that instantiates all possible scenes beforehand for
// performance
private
SceneManager
manager
;
// stage for different scenes to access
public
static
Stage
gamePrimaryStage
;
// scene for different roots to access
public
static
Scene
scene
;
// Stylesheet for the game menus
public
static
String
styleSheet
;
public
MediaPlayer
player
;
//manages the game sounds
public
static
void
main
(
String
[]
args
)
{
launch
(
args
);
}
...
...
@@ -35,18 +40,32 @@ public class GameManager extends Application {
manager
=
new
SceneManager
();
}
/**
* Starts the game
* @param primaryStage - stage for the scene to show itself
*/
@Override
public
void
start
(
Stage
primaryStage
)
{
// instantiate the gamePrimaryStage for other scenes to access
gamePrimaryStage
=
primaryStage
;
// get starting game root
scene
=
new
Scene
(
SceneManager
.
getSceneRoot
(
"game menu"
));
// add styling for this scene
styleSheet
=
getClass
().
getResource
(
"/style.css"
).
toExternalForm
();
scene
.
getStylesheets
().
add
(
styleSheet
);
// populate the other scenes before user clicks
SceneManager
.
populateOtherScenes
();
// set scene to stage
primaryStage
.
setScene
(
scene
);
primaryStage
.
sizeToScene
();
primaryStage
.
setTitle
(
"Rule.Baba is Us"
);
primaryStage
.
show
();
// play the game music (Baba Is You OST)
playMusic
();
}
...
...
@@ -64,6 +83,9 @@ public class GameManager extends Application {
MusicPlayer
.
putMediaOnLoop
();
}
/**
* @return Scene - the scene of the game
*/
public
Scene
getScene
()
{
return
scene
;
}
...
...
src/main/java/gameManager/SceneManager.java
View file @
2ce387a7
...
...
@@ -12,7 +12,7 @@
* Package: gameManager
* Class: sceneManager
*
* Description:
THIS IS A DESCRIPTION Y’ALL AND I NEED TO CHANGE THIS!
* Description:
Loads and stores scene roots for other scenes to access
*
* ****************************************
*/
...
...
@@ -28,22 +28,33 @@ import settings.SettingsMain;
import
java.util.HashMap
;
/**
* Scene manager: loads the scenes (more specifically: roots) of
* the scenes in the game
*/
public
class
SceneManager
{
// holds the names of the Roots that will be put onto the GameManager scene
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"
;
// place to store roots
private
static
HashMap
<
String
,
Parent
>
roots
=
new
HashMap
<>();
/**
* Instantiates the first root- the game menu
*/
public
SceneManager
(){
Parent
GameMenuRoot
=
GameMenuMain
.
getRoot
();
addSceneRoots
(
GAME_MENU
,
GameMenuRoot
);
}
/**
* Populate all the other scenes (level menu, instructions, ...)
*/
public
static
void
populateOtherScenes
(){
Parent
LevelMenuRoot
=
LevelMenuMain
.
getRoot
();
addSceneRoots
(
LEVEL_MENU
,
LevelMenuRoot
);
...
...
@@ -58,11 +69,21 @@ public class SceneManager {
addSceneRoots
(
SETTINGS
,
SettingsRoot
);
}
/**
* Add scene root into hashmap
* @param sceneName - name of the scene root
* @param sceneRoot - the root itself
*/
public
static
void
addSceneRoots
(
String
sceneName
,
Parent
sceneRoot
){
roots
.
put
(
sceneName
,
sceneRoot
);
}
/**
* Gets a scene root based on the name
* @param rootName - name of the scene root (as stored in the hashmap)
* @return - scene root
*/
public
static
Parent
getSceneRoot
(
String
rootName
){
return
roots
.
get
(
rootName
);
}
...
...
src/main/java/gameMenu/GameMenuController.java
View file @
2ce387a7
...
...
@@ -21,36 +21,44 @@ package gameMenu;
import
javafx.application.Platform
;
import
javafx.scene.control.Label
;
import
gameManager.SceneManager
;
import
gameManager.GameManager
;
import
gameboard.BabaIsYouGameGUIMain
;
/**
* Controller for the game menu
*/
public
class
GameMenuController
{
// private SceneManager sceneManager;
private
GameMenuView
view
;
/**
* Attaches redirection events to the view
* @param theView - view of the Game Menu
*/
public
GameMenuController
(
GameMenuView
theView
){
view
=
theView
;
// get play label and attach root transition event
Label
play
=
view
.
getPlay
();
play
.
setOnMouseClicked
(
e
->{
// GameManager.gamePrimaryStage.setScene(BabaIsYouGameGUIMain.getScene());
play
.
getScene
().
setRoot
(
SceneManager
.
getSceneRoot
(
SceneManager
.
GAMEPLAY
));
play
.
getScene
().
setRoot
(
SceneManager
.
getSceneRoot
(
SceneManager
.
LEVEL_MENU
));
});
// get view label and attach root transition event
Label
instruction
=
view
.
getInstructions
();
instruction
.
setOnMouseClicked
(
e
->{
instruction
.
getScene
().
setRoot
(
SceneManager
.
getSceneRoot
(
SceneManager
.
INSTRUCTIONS
));
});
// get settings label and attach root transition event
Label
settings
=
view
.
getSettings
();
settings
.
setOnMouseClicked
(
e
->
{
settings
.
getScene
().
setRoot
(
SceneManager
.
getSceneRoot
(
SceneManager
.
SETTINGS
));
});
// get exit label , and exit when clicked
Label
exit
=
view
.
getExit
();
exit
.
setOnMouseClicked
(
e
->{
...
...
src/main/java/gameMenu/GameMenuMain.java
View file @
2ce387a7
...
...
@@ -13,16 +13,28 @@ public class GameMenuMain extends Application {
// view for the menu
private
GameMenuView
theView
;
/**
* Main method for calling the game from cmd line
* @param args - arguments
*/
public
static
void
main
(
String
[]
args
)
{
launch
(
args
);
}
/**
* Initialize the game with the view
* @throws Exception
*/
@Override
public
void
init
()
throws
Exception
{
super
.
init
();
this
.
theView
=
new
GameMenuView
();
}
/**
* Add logic and show
* @param primaryStage - stage to show
*/
@Override
public
void
start
(
Stage
primaryStage
)
{
Scene
scene
=
new
Scene
(
theView
.
getRoot
());
...
...
@@ -33,6 +45,10 @@ public class GameMenuMain extends Application {
primaryStage
.
show
();
}
/**
* gets the root of the game
* @return - the root of the game with controls attached
*/
public
static
Parent
getRoot
(){
GameMenuView
view
=
new
GameMenuView
();
GameMenuController
controller
=
new
GameMenuController
(
view
);
...
...
src/main/java/gameMenu/GameMenuView.java
View file @
2ce387a7
...
...
@@ -29,19 +29,21 @@ import javafx.scene.layout.VBox;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileNotFoundException
;
/**
* Used to add visuals to the game menu in GameMenuMain
*/
public
class
GameMenuView
{
// root of the menu
private
VBox
root
;
// play label
private
Label
play
;
// image label for cool game name
private
Image
image
;
// all other labels
private
Label
instructions
,
settings
,
exit
;
...
...
@@ -95,6 +97,11 @@ public class GameMenuView {
instructions
,
settings
,
exit
,
space_two
);
}
/**
* Getters for the controller to attach events
* @return - elements in the UI
*/
public
VBox
getRoot
()
{
return
root
;
}
...
...
src/main/java/instructions/InstructionsController.java
View file @
2ce387a7
...
...
@@ -12,7 +12,7 @@
* Package: settingsPane
* Class: SettingsController
*
* Description:
THIS IS A DESCRIPTION Y’ALL AND I NEED TO CHANGE THIS!
* Description:
Controller for instructions
*
* ****************************************
*/
...
...
@@ -21,10 +21,17 @@ package instructions;
import
gameManager.SceneManager
;
import
javafx.scene.control.Button
;
/**
* Controller for instructions scene
*/
public
class
InstructionsController
{
// viewer of the instructions scene
private
InstructionsView
view
;
/**
* Attach a return-to-menu action to the instruction scene
* @param theView - view of the instruction scene
*/
public
InstructionsController
(
InstructionsView
theView
){
this
.
view
=
theView
;
...
...
src/main/java/instructions/InstructionsMain.java
View file @
2ce387a7
...
...
@@ -6,17 +6,29 @@ import javafx.stage.Stage;
import
levelMenu.LevelMenuController
;
import
levelMenu.LevelMenuView
;
/**
* Main instructions scene for the game
*/
public
class
InstructionsMain
extends
Application
{
// main method
public
static
void
main
(
String
[]
args
)
{
launch
(
args
);
}
/**
* Default, not really used
* @param primaryStage - stage to show the scene
*/
@Override
public
void
start
(
Stage
primaryStage
)
{
}
/**
* Gets the root of the scene, with controllers attached
* @return - the root of the instruction scene
*/
public
static
Parent
getRoot
(){
InstructionsView
view
=
new
InstructionsView
();
InstructionsController
controller
=
new
InstructionsController
(
view
);
...
...
src/main/java/instructions/InstructionsView.java
View file @
2ce387a7
...
...
@@ -12,7 +12,7 @@
* Package: settingsPane
* Class: SettingsView
*
* Description:
THIS IS A DESCRIPTION Y’ALL AND I NEED TO CHANGE THIS!
* Description:
UI for the instructions scene
*
* ****************************************
*/
...
...
@@ -21,33 +21,40 @@ package instructions;
import
gameManager.GameManager
;
import
javafx.geometry.Pos
;
import
javafx.scene.control.Button
;
import
javafx.scene.control.Label
;
import
javafx.scene.control.ScrollPane
;
import
javafx.scene.control.TextArea
;
import
javafx.scene.layout.Priority
;
import
javafx.scene.layout.Region
;
import
javafx.scene.layout.VBox
;
import
javafx.scene.paint.Color
;
import
javafx.scene.text.Text
;
import
javafx.scene.text.TextAlignment
;
/**
* UI for the instructions scene
*/
public
class
InstructionsView
{
// root node
private
VBox
root
;
// Text node for the game explanations
private
Text
gameExplanations
;
private
TextArea
game
E
xplanation
;
// Scroller for the
game
e
xplanation
s
private
ScrollPane
explanationsScroller
;
// return to menu button
private
Button
menuButton
;
/**
* Create the instruction scene view
*/
public
InstructionsView
(){
// add root with styling + centering
root
=
new
VBox
();
root
.
getStyleClass
().
add
(
"with-opaque-background"
);
root
.
setMinHeight
(
GameManager
.
GAME_HEIGHT
);
root
.
setMinWidth
(
GameManager
.
GAME_WIDTH
);
root
.
setAlignment
(
Pos
.
CENTER
);
// create the game explanation and style it
gameExplanations
=
new
Text
(
"Baba is Us game rules: \n\n"
+
"There are three different kinds of blocks to "
+
"make rules in the game, ones representing "
+
...
...
@@ -68,31 +75,33 @@ public class InstructionsView {
gameExplanations
.
setWrappingWidth
(
600
);
gameExplanations
.
setTextAlignment
(
TextAlignment
.
JUSTIFY
);
// create scroll pane, attach game explanations
explanationsScroller
=
new
ScrollPane
();
explanationsScroller
.
setContent
(
gameExplanations
);
explanationsScroller
.
setPrefHeight
(
400
);
explanationsScroller
.
setMaxWidth
(
650
);
// explanationsScroller.setId("instruction-scroller");
// margin between game name and options
Region
space_one
=
new
Region
();
space_one
.
setPrefHeight
(
50
);
//
VBox.setVgrow(explanationsScroller, Priority.ALWAYS);
//
create button
menuButton
=
new
Button
(
"Return"
);
// add all elements to root node
root
.
getChildren
().
addAll
(
explanationsScroller
,
space_one
,
menuButton
);
}
/**
* Getters for the controller
* @return - UI elements
*/
public
VBox
getRoot
()
{
return
root
;
}
public
Text
getGameExplanations
()
{
return
gameExplanations
;
}
public
Button
getMenuButton
()
{
return
menuButton
;
}
...
...
src/main/java/levelMenu/LevelMenuController.java
View file @
2ce387a7
...
...
@@ -12,25 +12,63 @@
* Package: levelMenu
* Class: LevelMenuController
*
* Description:
THIS IS A DESCRIPTION Y’ALL AND I NEED TO CHANGE THIS!
* Description:
controller for the level menu
*
* ****************************************
*/
package
levelMenu
;
import
gameManager.GameManager
;
import
gameManager.SceneManager
;
import
javafx.scene.control.Button
;
import
javafx.scene.control.Label
;
import
Rule.TestGUIOne
;
import
Rule.TestGUITwo
;
import
Rule.TestGUIThree
;
/**
* Controls the redirection of the level menu
*/
public
class
LevelMenuController
{
// view of the level menu
private
LevelMenuView
view
;
/**
* Attaches redirection events for all elemts
* @param theView - ui of the level menu
*/
public
LevelMenuController
(
LevelMenuView
theView
){
this
.
view
=
theView
;
// attach return to game menu
Button
menuButton
=
view
.
getBackToMenu
();
menuButton
.
setOnAction
(
e
->{
menuButton
.
getScene
().
setRoot
(
SceneManager
.
getSceneRoot
(
SceneManager
.
GAME_MENU
));
});
// for all three labels, redirect to the appropriate scene
Label
lvlOne
=
view
.
getLevel1
();
Label
lvlTwo
=
view
.
getLevel2
();
Label
lvlThree
=
view
.
getLevel3
();
lvlOne
.
setOnMouseClicked
(
e
->{
TestGUIOne
firstLvl
=
new
TestGUIOne
();
firstLvl
.
createScene
();
GameManager
.
gamePrimaryStage
.
setScene
(
firstLvl
.
getScene
());
});
lvlTwo
.
setOnMouseClicked
(
e
->{
TestGUITwo
secondLvl
=
new
TestGUITwo
();
secondLvl
.
createScene
();
GameManager
.
gamePrimaryStage
.
setScene
(
secondLvl
.
getScene
());
});
lvlThree
.
setOnMouseClicked
(
e
->{
TestGUIThree
thirdLvl
=
new
TestGUIThree
();
thirdLvl
.
createScene
();
GameManager
.
gamePrimaryStage
.
setScene
(
thirdLvl
.
getScene
());