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
469da8f0
Commit
469da8f0
authored
2 months ago
by
David Reiser
Browse files
Options
Downloads
Patches
Plain Diff
comments added
parent
288d68cf
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
+28
-2
28 additions, 2 deletions
GameUI.java
with
28 additions
and
2 deletions
GameUI.java
+
28
−
2
View file @
469da8f0
...
...
@@ -16,6 +16,9 @@ public class GameUI extends Application{
private
Label
scoreLabelO
=
new
Label
(
"Player O: 0"
);
private
Button
[]
buttons
=
new
Button
[
9
];
/** Provides styles allignment and the scenes for labels, buttons and boxes.
* @param stage starts the scene and is the main stage for the application
*/
@Override
public
void
start
(
Stage
stage
){
playerLabel
.
setStyle
(
"-fx-font-size: 30px; -fx-font-family: 'Impact'; -fx-text-fill: blue;"
);
...
...
@@ -35,16 +38,19 @@ public class GameUI extends Application{
borderPane
.
setCenter
(
gridPane
);
//HBox for the labels
HBox
Box
=
new
HBox
(
20
);
Box
.
setAlignment
(
Pos
.
CENTER
);
playerLabel
.
setAlignment
(
Pos
.
TOP_CENTER
);
playerLabel
.
setPadding
(
new
Insets
(
10
,
0
,
15
,
15
));
Box
.
getChildren
().
add
(
playerLabel
);
//space between the labels
Region
spacer
=
new
Region
();
HBox
.
setHgrow
(
spacer
,
Priority
.
ALWAYS
);
Box
.
getChildren
().
add
(
spacer
);
//score labels design
scoreLabelX
.
setAlignment
(
Pos
.
TOP_CENTER
);
scoreLabelO
.
setAlignment
(
Pos
.
TOP_CENTER
);
VBox
scoreBox
=
new
VBox
(
15
);
...
...
@@ -55,58 +61,78 @@ public class GameUI extends Application{
Box
.
getChildren
().
add
(
scoreBox
);
borderPane
.
setTop
(
Box
);
//board allignment
gridPane
.
setPadding
(
new
Insets
(
10
));
gridPane
.
setHgap
(
30
);
gridPane
.
setVgap
(
30
);
gridPane
.
setAlignment
(
Pos
.
CENTER
);
//main Scene
Scene
scene
=
new
Scene
(
borderPane
,
1500
,
850
);
stage
.
setScene
(
scene
);
stage
.
setTitle
(
"Tick-Tack-Trauma"
);
stage
.
show
();
}
/** method for the game updating its state including changing turn of the player and check for win or tie. Images are set as symbols.
*
* @param index of the selectet tile
*/
private
void
handleTurn
(
int
index
){
if
(
board
.
tiles
[
index
].
exist_owner
())
{
return
;
}
board
.
tiles
[
index
].
set_owner
(
board
.
currentPlayer
);
//Replace symbols with images
String
imageSymbols
=
board
.
currentPlayer
==
0
?
getClass
().
getResource
(
"/textures/1_0.png"
).
toExternalForm
()
:
getClass
().
getResource
(
"/textures/0_0.png"
).
toExternalForm
();
Image
image
=
new
Image
(
""
+
imageSymbols
);
ImageView
imageView
=
new
ImageView
(
image
);
//size of the image
imageView
.
setFitWidth
(
135
);
imageView
.
setFitHeight
(
135
);
imageView
.
setPreserveRatio
(
true
);
buttons
[
index
].
setGraphic
(
imageView
);
board
.
turnEnd
();
updatePlayerTurn
(
board
.
currentPlayer
);
//changes label state for the winning player and updates its score
if
(
board
.
victoryCheck
())
{
playerLabel
.
setText
(
"Player "
+
(
board
.
currentPlayer
==
0
?
"X"
:
"O"
)
+
" wins!"
);
updatePlayerScore
();
return
;
}
//changes label state to draw
if
(
board
.
marks
==
9
)
{
playerLabel
.
setText
(
"It's a draw!"
);
return
;
}
}
/** updates the label of the current player
*
* @param currentPlayer player whose turn it is
*/
private
void
updatePlayerTurn
(
int
currentPlayer
)
{
String
playerSymbol
=
(
currentPlayer
==
0
)
?
"X"
:
"O"
;
playerLabel
.
setText
(
"Player "
+
playerSymbol
+
"'s turn"
);
}
/** updates the score of a player who won
*
*/
private
void
updatePlayerScore
(){
scoreLabelX
.
setText
(
"Player X: "
+
board
.
players
[
0
].
getPlayerScore
());
scoreLabelO
.
setText
(
"Player O: "
+
board
.
players
[
1
].
getPlayerScore
());
}
/** starts the javafx application
*
* @param args
*/
public
void
call
(
String
[]
args
){
launch
(
args
);
}
...
...
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