Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
Tick-Tack-Trauma
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
Josua Oppermann
Tick-Tack-Trauma
Commits
ad8be085
Commit
ad8be085
authored
2 months ago
by
David Reiser
Browse files
Options
Downloads
Patches
Plain Diff
win/tie screen after match with reset button
parent
469da8f0
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
GameUI.java
+29
-10
29 additions, 10 deletions
GameUI.java
with
29 additions
and
10 deletions
GameUI.java
+
29
−
10
View file @
ad8be085
...
...
@@ -9,9 +9,11 @@ import javafx.scene.layout.*;
import
javafx.stage.Stage
;
public
class
GameUI
extends
Application
{
Scene
game
,
winningScene
;
BorderPane
gameBorderPane
,
winningBorderPane
;
private
Board
board
=
new
Board
();
private
Label
playerLabel
=
new
Label
(
"Player X's turn"
);
private
Label
winnerLabel
=
new
Label
(
"Won"
);
private
Label
scoreLabelX
=
new
Label
(
"Player X: 0"
);
private
Label
scoreLabelO
=
new
Label
(
"Player O: 0"
);
private
Button
[]
buttons
=
new
Button
[
9
];
...
...
@@ -22,21 +24,23 @@ public class GameUI extends Application{
@Override
public
void
start
(
Stage
stage
){
playerLabel
.
setStyle
(
"-fx-font-size: 30px; -fx-font-family: 'Impact'; -fx-text-fill: blue;"
);
winnerLabel
.
setStyle
(
"-fx-font-size: 150px; -fx-font-family: 'Impact'; -fx-text-fill: blue;"
);
scoreLabelX
.
setStyle
(
"-fx-font-size: 30px; -fx-font-family: 'Impact'; -fx-text-fill: black;"
);
scoreLabelO
.
setStyle
(
"-fx-font-size: 30px; -fx-font-family: 'Impact'; -fx-text-fill: black;"
);
BorderPane
borderPane
=
new
BorderPane
();
gameBorderPane
=
new
BorderPane
();
winningBorderPane
=
new
BorderPane
();
GridPane
gridPane
=
new
GridPane
();
for
(
int
i
=
0
;
i
<
9
;
i
++){
int
index
=
i
;
buttons
[
i
]
=
new
Button
();
buttons
[
i
].
setPrefSize
(
150
,
150
);
buttons
[
i
].
setOnAction
(
e
->
handleTurn
(
index
));
buttons
[
i
].
setOnAction
(
e
->
handleTurn
(
index
,
stage
));
gridPane
.
add
(
buttons
[
i
],
i
%
3
,
i
/
3
);
}
b
orderPane
.
setCenter
(
gridPane
);
gameB
orderPane
.
setCenter
(
gridPane
);
//HBox for the labels
HBox
Box
=
new
HBox
(
20
);
...
...
@@ -59,7 +63,7 @@ public class GameUI extends Application{
scoreBox
.
getChildren
().
addAll
(
scoreLabelX
,
scoreLabelO
);
Box
.
getChildren
().
add
(
scoreBox
);
b
orderPane
.
setTop
(
Box
);
gameB
orderPane
.
setTop
(
Box
);
//board allignment
gridPane
.
setPadding
(
new
Insets
(
10
));
...
...
@@ -67,9 +71,22 @@ public class GameUI extends Application{
gridPane
.
setVgap
(
30
);
gridPane
.
setAlignment
(
Pos
.
CENTER
);
//reset button
Button
reset
=
new
Button
(
"Reset"
);
reset
.
setStyle
(
"-fx-font-size: 30px; -fx-font-family: 'Impact'; -fx-text-fill: black;"
);
reset
.
setOnAction
(
e
->
stage
.
setScene
(
game
));
//winning/tie screen
winnerLabel
.
setAlignment
(
Pos
.
CENTER
);
VBox
finalBox
=
new
VBox
(
35
);
finalBox
.
setAlignment
(
Pos
.
CENTER
);
finalBox
.
getChildren
().
addAll
(
winnerLabel
,
reset
);
winningBorderPane
.
setCenter
(
finalBox
);
winningScene
=
new
Scene
(
winningBorderPane
,
1500
,
850
);
//main Scene
Scene
scen
e
=
new
Scene
(
b
orderPane
,
1500
,
850
);
stage
.
setScene
(
scen
e
);
gam
e
=
new
Scene
(
gameB
orderPane
,
1500
,
850
);
stage
.
setScene
(
gam
e
);
stage
.
setTitle
(
"Tick-Tack-Trauma"
);
stage
.
show
();
}
...
...
@@ -78,7 +95,7 @@ public class GameUI extends Application{
*
* @param index of the selectet tile
*/
private
void
handleTurn
(
int
index
){
private
void
handleTurn
(
int
index
,
Stage
stage
){
if
(
board
.
tiles
[
index
].
exist_owner
())
{
return
;
}
...
...
@@ -101,14 +118,16 @@ public class GameUI extends Application{
//changes label state for the winning player and updates its score
if
(
board
.
victoryCheck
())
{
play
erLabel
.
setText
(
"Player "
+
(
board
.
currentPlayer
==
0
?
"X"
:
"O"
)
+
" wins!"
);
winn
erLabel
.
setText
(
"Player "
+
(
board
.
currentPlayer
==
0
?
"X"
:
"O"
)
+
" wins!"
);
updatePlayerScore
();
stage
.
setScene
(
winningScene
);
return
;
}
//changes label state to draw
if
(
board
.
marks
==
9
)
{
playerLabel
.
setText
(
"It's a draw!"
);
winnerLabel
.
setText
(
"It's a draw!"
);
stage
.
setScene
(
winningScene
);
return
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Josua Oppermann
@josua.oppermann
mentioned in commit
3534c5ab
·
2 months ago
mentioned in commit
3534c5ab
mentioned in commit 3534c5ab2c947ce4781ff115fe9aaf6effac2190
Toggle commit list
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