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
c30c0ae3
Commit
c30c0ae3
authored
2 months ago
by
Josua Oppermann
Browse files
Options
Downloads
Plain Diff
Merge branch 'revert-
42000598
' into 'main'
Revert "Merge remote-tracking branch 'origin/main'" See merge request
!1
parents
42000598
c25fbf25
No related branches found
Branches containing commit
No related tags found
1 merge request
!1
Revert "Merge remote-tracking branch 'origin/main'"
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
GameUI.java
+6
-145
6 additions, 145 deletions
GameUI.java
Tile.java
+1
-1
1 addition, 1 deletion
Tile.java
with
7 additions
and
146 deletions
GameUI.java
+
6
−
145
View file @
c30c0ae3
import
javafx.application.Application
;
import
javafx.geometry.Insets
;
import
javafx.geometry.Pos
;
import
javafx.scene.Scene
;
import
javafx.scene.control.Label
;
import
javafx.scene.image.*
;
import
javafx.scene.control.Button
;
import
javafx.scene.layout.*
;
import
javafx.scene.layout.GridPane
;
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
];
/** 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;"
);
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;"
);
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
,
stage
));
gridPane
.
add
(
buttons
[
i
],
i
%
3
,
i
/
3
);
}
gameBorderPane
.
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
);
scoreBox
.
setPadding
(
new
Insets
(
15
,
25
,
5
,
5
));
scoreBox
.
setAlignment
(
Pos
.
TOP_RIGHT
);
scoreBox
.
getChildren
().
addAll
(
scoreLabelX
,
scoreLabelO
);
Box
.
getChildren
().
add
(
scoreBox
);
gameBorderPane
.
setTop
(
Box
);
//board allignment
gridPane
.
setPadding
(
new
Insets
(
10
));
gridPane
.
setHgap
(
30
);
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
game
=
new
Scene
(
gameBorderPane
,
1500
,
850
);
stage
.
setScene
(
game
);
stage
.
setTitle
(
"Tick-Tack-Trauma"
);
GridPane
GridPane
=
new
GridPane
();
Scene
scene
=
new
Scene
(
GridPane
,
300
,
300
);
stage
.
setScene
(
scene
);
stage
.
setTitle
(
"Tic-Tac-Toe"
);
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
,
Stage
stage
){
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
())
{
winnerLabel
.
setText
(
"Player "
+
(
board
.
currentPlayer
==
0
?
"X"
:
"O"
)
+
" wins!"
);
updatePlayerScore
();
stage
.
setScene
(
winningScene
);
return
;
}
//changes label state to draw
if
(
board
.
marks
==
9
)
{
winnerLabel
.
setText
(
"It's a draw!"
);
stage
.
setScene
(
winningScene
);
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
);
launch
(
args
);
}
}
This diff is collapsed.
Click to expand it.
Tile.java
+
1
−
1
View file @
c30c0ae3
...
...
@@ -89,7 +89,7 @@ public class Tile extends ImageView{
/**Whether this Tile is owned by a Player
*/
public
boolean
exist_owner
(){
return
owner
!=
-
1
;
return
owner
>
0
;
}
}
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