Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
Mathdoku
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tmp1u19
Mathdoku
Commits
a722b17a
Commit
a722b17a
authored
5 years ago
by
tmp1u19
Browse files
Options
Downloads
Patches
Plain Diff
The hint option ca now be accessed for boards equal or lower than 5x5
parent
b05dda14
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Window.java
+126
-121
126 additions, 121 deletions
Window.java
with
126 additions
and
121 deletions
Window.java
+
126
−
121
View file @
a722b17a
...
@@ -24,6 +24,132 @@ public class Window {
...
@@ -24,6 +24,132 @@ public class Window {
static
int
n
;
//the size of the board nxn -> static to be the same everywhere
static
int
n
;
//the size of the board nxn -> static to be the same everywhere
/**
* window that will create the game board and the buttons specific to it
* all the options for the game are accessed from this window
* @param n -> the size of the board nxn
* @param cages -> the cages that were extracted when a file was opened from the menu window
* @return Stage -> the Mathdoku window where a a user can play the game
*/
public
Stage
mathdoku
(
int
n
,
ArrayList
<
Cage
>
cages
)
{
Window
.
n
=
n
;
//set the size of the board to the n selected by the player in the menu window
Handler
handler
=
new
Handler
(
cages
);
//create a handler object to handle the functionalities of the game
Stage
stage
=
new
Stage
();
//create the stage for the game
//create the root for the elements that will be added to the scene; set properties of the root
VBox
root
=
new
VBox
(
5
);
root
.
setStyle
(
"-fx-background-color: SeaShell"
);
root
.
setAlignment
(
Pos
.
CENTER
);
root
.
setPadding
(
new
Insets
(
20
));
//create the top button menu -> horizontal box
HBox
buttons
=
new
HBox
();
buttons
.
setAlignment
(
Pos
.
CENTER
);
//create the grid where the cells of the game will be added; set properties
GridPane
grid
=
new
GridPane
();
grid
.
setAlignment
(
Pos
.
CENTER
);
grid
.
setStyle
(
"-fx-border-color: black; -fx-border-width: 4 4 4 4;"
);
//create the buttons to be added to the top menu of buttons
Button
undo
=
new
Button
(
"Undo"
);
Button
redo
=
new
Button
(
"Redo"
);
Button
help
=
new
Button
(
"Enable Help"
);
Button
clear
=
new
Button
(
"Clear"
);
Button
hint
=
new
Button
(
"Hint"
);
//set properties for the buttons
undo
.
setStyle
(
"-fx-font-size: 20px; -fx-font-weight:bold; -fx-background-color: MediumSeaGreen;"
+
"-fx-border-color: black; -fx-border-width: 4 4 4 4;"
);
redo
.
setStyle
(
"-fx-font-size: 20px; -fx-font-weight:bold; -fx-background-color: MediumSeaGreen;"
+
"-fx-border-color: black; -fx-border-width: 4 4 4 4;"
);
help
.
setStyle
(
"-fx-font-size: 20px; -fx-font-weight:bold; -fx-background-color: MediumSeaGreen;"
+
"-fx-border-color: black; -fx-border-width: 4 4 4 4;"
);
clear
.
setStyle
(
"-fx-font-size: 20px; -fx-font-weight:bold; -fx-background-color: MediumSeaGreen;"
+
"-fx-border-color: black; -fx-border-width: 4 4 4 4;"
);
hint
.
setStyle
(
"-fx-font-size: 20px; -fx-font-weight:bold; -fx-background-color: MediumSeaGreen;"
+
"-fx-border-color: black; -fx-border-width: 4 4 4 4;"
);
//disable the redo and undo buttons (there is nothing to undo or redo yet)
undo
.
setDisable
(
true
);
redo
.
setDisable
(
true
);
//set the functionality for each button from the top menu of buttons
handler
.
helpButton
(
help
,
grid
);
handler
.
clearBoard
(
clear
,
grid
,
undo
,
redo
);
handler
.
undoAction
(
undo
,
redo
,
grid
);
handler
.
redoAction
(
redo
,
grid
);
handler
.
hint
(
hint
,
grid
);
buttons
.
getChildren
().
addAll
(
undo
,
redo
,
help
,
clear
,
hint
);
//add the buttons to the top button menu
handler
.
drawGrid
(
grid
);
//draw the cells in the grid
handler
.
addActions
(
grid
,
undo
);
//add actions to the undo stack when the undo button is pressed
//create the bottom button menu to change the font size of the numbers in the cells
HBox
sizes
=
new
HBox
(
5
);
sizes
.
setAlignment
(
Pos
.
CENTER
);
//create the buttons for the bottom menu buttons which will change the font size of the numbers in the cells
Button
small
=
new
Button
(
"Small"
);
Button
medium
=
new
Button
(
"Medium"
);
Button
large
=
new
Button
(
"Large"
);
//set properties for the buttons from the bottom button menu
small
.
setStyle
(
"-fx-font-size: 20px; -fx-font-weight:bold; -fx-background-color: MediumSeaGreen;"
+
" -fx-border-color: black; -fx-border-width: 4 4 4 4;"
);
medium
.
setStyle
(
"-fx-font-size: 20px; -fx-font-weight:bold; -fx-background-color: MediumSeaGreen; "
+
"-fx-border-color: black; -fx-border-width: 4 4 4 4;"
);
large
.
setStyle
(
"-fx-font-size: 20px; -fx-font-weight:bold; -fx-background-color: MediumSeaGreen; "
+
"-fx-border-color: black; -fx-border-width: 4 4 4 4;"
);
sizes
.
getChildren
().
addAll
(
small
,
medium
,
large
);
//add elements to the bottom menu of buttons
//add functionality to the font size changers
handler
.
changeFont
(
small
,
20
);
handler
.
changeFont
(
medium
,
30
);
handler
.
changeFont
(
large
,
40
);
Label
note
=
new
Label
(
"Double click the space provided for text in cell"
);
//message for the player to
//be aware of the functionality
Button
submit
=
new
Button
(
"Submit"
);
//submit button to check the answer
Button
solve
=
new
Button
(
"Solve"
);
//set properties for the note and the submit button
note
.
setStyle
(
"-fx-font-size: 15px; -fx-font-weight:bold;"
);
submit
.
setStyle
(
"-fx-font-size: 20px; -fx-font-weight:bold; -fx-background-color: pink; "
+
"-fx-border-color: black; -fx-border-width: 4 4 4 4;"
);
//add functionalities to the submit button
handler
.
submitButton
(
submit
,
stage
);
if
((
n
!=
6
)
&&
(
n
!=
7
)
&&
(
n
!=
8
))
{
handler
.
solveBoard
(
grid
);
}
else
{
hint
.
setDisable
(
true
);
}
root
.
getChildren
().
addAll
(
buttons
,
grid
,
sizes
,
note
,
submit
,
solve
);
//add the elements to the root
handler
.
resize
(
root
,
grid
);
//resize the board of the game
//create the scene with the root the vertical box and set it to the stage
Scene
scene
=
new
Scene
(
root
);
stage
.
setScene
(
scene
);
//set properties for the stage
stage
.
setTitle
(
"Mathdoku"
);
stage
.
initStyle
(
StageStyle
.
DECORATED
);
stage
.
setX
(
700
);
stage
.
setY
(
200
);
stage
.
setMinHeight
(
700
);
stage
.
setMinWidth
(
700
);
return
stage
;
//return the stage created
}
/**
/**
* this method shows a window which will be displayed when the player double clicks on a cell to introduce
* this method shows a window which will be displayed when the player double clicks on a cell to introduce
* or delete values via mouse
* or delete values via mouse
...
@@ -183,126 +309,5 @@ public class Window {
...
@@ -183,126 +309,5 @@ public class Window {
return
alert
;
//return the warning alert created
return
alert
;
//return the warning alert created
}
}
/**
* window that will create the game board and the buttons specific to it
* all the options for the game are accessed from this window
* @param n -> the size of the board nxn
* @param cages -> the cages that were extracted when a file was opened from the menu window
* @return Stage -> the Mathdoku window where a a user can play the game
*/
public
Stage
mathdoku
(
int
n
,
ArrayList
<
Cage
>
cages
)
{
Window
.
n
=
n
;
//set the size of the board to the n selected by the player in the menu window
Handler
handler
=
new
Handler
(
cages
);
//create a handler object to handle the functionalities of the game
Stage
stage
=
new
Stage
();
//create the stage for the game
//create the root for the elements that will be added to the scene; set properties of the root
VBox
root
=
new
VBox
(
5
);
root
.
setStyle
(
"-fx-background-color: SeaShell"
);
root
.
setAlignment
(
Pos
.
CENTER
);
root
.
setPadding
(
new
Insets
(
20
));
//create the top button menu -> horizontal box
HBox
buttons
=
new
HBox
();
buttons
.
setAlignment
(
Pos
.
CENTER
);
//create the grid where the cells of the game will be added; set properties
GridPane
grid
=
new
GridPane
();
grid
.
setAlignment
(
Pos
.
CENTER
);
grid
.
setStyle
(
"-fx-border-color: black; -fx-border-width: 4 4 4 4;"
);
//create the buttons to be added to the top menu of buttons
Button
undo
=
new
Button
(
"Undo"
);
Button
redo
=
new
Button
(
"Redo"
);
Button
help
=
new
Button
(
"Enable Help"
);
Button
clear
=
new
Button
(
"Clear"
);
Button
hint
=
new
Button
(
"Hint"
);
//set properties for the buttons
undo
.
setStyle
(
"-fx-font-size: 20px; -fx-font-weight:bold; -fx-background-color: MediumSeaGreen;"
+
"-fx-border-color: black; -fx-border-width: 4 4 4 4;"
);
redo
.
setStyle
(
"-fx-font-size: 20px; -fx-font-weight:bold; -fx-background-color: MediumSeaGreen;"
+
"-fx-border-color: black; -fx-border-width: 4 4 4 4;"
);
help
.
setStyle
(
"-fx-font-size: 20px; -fx-font-weight:bold; -fx-background-color: MediumSeaGreen;"
+
"-fx-border-color: black; -fx-border-width: 4 4 4 4;"
);
clear
.
setStyle
(
"-fx-font-size: 20px; -fx-font-weight:bold; -fx-background-color: MediumSeaGreen;"
+
"-fx-border-color: black; -fx-border-width: 4 4 4 4;"
);
hint
.
setStyle
(
"-fx-font-size: 20px; -fx-font-weight:bold; -fx-background-color: MediumSeaGreen;"
+
"-fx-border-color: black; -fx-border-width: 4 4 4 4;"
);
//disable the redo and undo buttons (there is nothing to undo or redo yet)
undo
.
setDisable
(
true
);
redo
.
setDisable
(
true
);
//set the functionality for each button from the top menu of buttons
handler
.
helpButton
(
help
,
grid
);
handler
.
clearBoard
(
clear
,
grid
,
undo
,
redo
);
handler
.
undoAction
(
undo
,
redo
,
grid
);
handler
.
redoAction
(
redo
,
grid
);
buttons
.
getChildren
().
addAll
(
undo
,
redo
,
help
,
clear
,
hint
);
//add the buttons to the top button menu
handler
.
drawGrid
(
grid
);
//draw the cells in the grid
handler
.
addActions
(
grid
,
undo
);
//add actions to the undo stack when the undo button is pressed
//create the bottom button menu to change the font size of the numbers in the cells
HBox
sizes
=
new
HBox
(
5
);
sizes
.
setAlignment
(
Pos
.
CENTER
);
//create the buttons for the bottom menu buttons which will change the font size of the numbers in the cells
Button
small
=
new
Button
(
"Small"
);
Button
medium
=
new
Button
(
"Medium"
);
Button
large
=
new
Button
(
"Large"
);
//set properties for the buttons from the bottom button menu
small
.
setStyle
(
"-fx-font-size: 20px; -fx-font-weight:bold; -fx-background-color: MediumSeaGreen;"
+
" -fx-border-color: black; -fx-border-width: 4 4 4 4;"
);
medium
.
setStyle
(
"-fx-font-size: 20px; -fx-font-weight:bold; -fx-background-color: MediumSeaGreen; "
+
"-fx-border-color: black; -fx-border-width: 4 4 4 4;"
);
large
.
setStyle
(
"-fx-font-size: 20px; -fx-font-weight:bold; -fx-background-color: MediumSeaGreen; "
+
"-fx-border-color: black; -fx-border-width: 4 4 4 4;"
);
sizes
.
getChildren
().
addAll
(
small
,
medium
,
large
);
//add elements to the bottom menu of buttons
//add functionality to the font size changers
handler
.
changeFont
(
small
,
20
);
handler
.
changeFont
(
medium
,
30
);
handler
.
changeFont
(
large
,
40
);
Label
note
=
new
Label
(
"Double click the space provided for text in cell"
);
//message for the player to
//be aware of the functionality
Button
submit
=
new
Button
(
"Submit"
);
//submit button to check the answer
Button
solve
=
new
Button
(
"Solve"
);
//set properties for the note and the submit button
note
.
setStyle
(
"-fx-font-size: 15px; -fx-font-weight:bold;"
);
submit
.
setStyle
(
"-fx-font-size: 20px; -fx-font-weight:bold; -fx-background-color: pink; "
+
"-fx-border-color: black; -fx-border-width: 4 4 4 4;"
);
//add functionalities to the submit button
handler
.
submitButton
(
submit
,
stage
);
handler
.
solveBoard
(
solve
,
grid
,
n
);
root
.
getChildren
().
addAll
(
buttons
,
grid
,
sizes
,
note
,
submit
);
//add the elements to the root
handler
.
resize
(
root
,
grid
);
//resize the board of the game
//create the scene with the root the vertical box and set it to the stage
Scene
scene
=
new
Scene
(
root
);
stage
.
setScene
(
scene
);
//set properties for the stage
stage
.
setTitle
(
"Mathdoku"
);
stage
.
initStyle
(
StageStyle
.
DECORATED
);
stage
.
setX
(
700
);
stage
.
setY
(
200
);
stage
.
setMinHeight
(
700
);
stage
.
setMinWidth
(
700
);
return
stage
;
//return the stage created
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment