Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
TicTacToe
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
Jan Peter Schweers
TicTacToe
Commits
1b7b47b2
Commit
1b7b47b2
authored
2 months ago
by
jan-schw
Browse files
Options
Downloads
Patches
Plain Diff
refactor
parent
64939e23
No related branches found
Branches containing commit
No related tags found
2 merge requests
!6
Add final version of the game to main branch
,
!5
Add basic implementation
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/com/example/tictactoe_game/GameEvent.java
+2
-2
2 additions, 2 deletions
src/main/java/com/example/tictactoe_game/GameEvent.java
src/main/java/com/example/tictactoe_game/TicTacToeFX.java
+18
-21
18 additions, 21 deletions
src/main/java/com/example/tictactoe_game/TicTacToeFX.java
with
20 additions
and
23 deletions
src/main/java/com/example/tictactoe_game/GameEvent.java
+
2
−
2
View file @
1b7b47b2
...
...
@@ -4,8 +4,8 @@ import javafx.event.Event;
import
javafx.event.EventType
;
public
class
GameEvent
extends
Event
{
public
static
final
EventType
<
GameEvent
>
VICTORY_EVENT
=
new
EventType
<
GameEvent
>(
"VICTORY_EVENT"
);
public
static
final
EventType
<
GameEvent
>
DRAW_EVENT
=
new
EventType
<
GameEvent
>(
"DRAW_EVENT"
);
public
static
final
EventType
<
GameEvent
>
VICTORY_EVENT
=
new
EventType
<>(
"VICTORY_EVENT"
);
public
static
final
EventType
<
GameEvent
>
DRAW_EVENT
=
new
EventType
<>(
"DRAW_EVENT"
);
public
GameEvent
(
EventType
<?
extends
Event
>
eventType
)
{
super
(
eventType
);
...
...
This diff is collapsed.
Click to expand it.
src/main/java/com/example/tictactoe_game/TicTacToeFX.java
+
18
−
21
View file @
1b7b47b2
...
...
@@ -19,26 +19,23 @@ public class TicTacToeFX extends Application {
@Override
public
void
start
(
Stage
primaryStage
)
{
EventHandler
<
GameEvent
>
handler
=
new
EventHandler
<
GameEvent
>()
{
@Override
public
void
handle
(
GameEvent
gameEvent
)
{
String
currentPlayer
=
isXTurn
?
"X"
:
"O"
;
final
Stage
dialog
=
new
Stage
();
dialog
.
initModality
(
Modality
.
APPLICATION_MODAL
);
dialog
.
initOwner
(
primaryStage
);
VBox
dialogVbox
=
new
VBox
(
20
);
if
(
gameEvent
.
getEventType
()
==
GameEvent
.
VICTORY_EVENT
)
{
dialogVbox
.
getChildren
().
add
(
new
Text
(
"This is a victory for player "
+
currentPlayer
+
"!"
));
}
else
if
(
gameEvent
.
getEventType
()
==
GameEvent
.
DRAW_EVENT
)
{
dialogVbox
.
getChildren
().
add
(
new
Text
(
"This is a Draw!"
));
}
Scene
dialogScene
=
new
Scene
(
dialogVbox
,
150
,
150
);
dialog
.
setScene
(
dialogScene
);
dialog
.
show
();
EventHandler
<
GameEvent
>
gameEventHandler
=
gameEvent
->
{
String
currentPlayer
=
isXTurn
?
"X"
:
"O"
;
final
Stage
dialog
=
new
Stage
();
dialog
.
initModality
(
Modality
.
APPLICATION_MODAL
);
dialog
.
initOwner
(
primaryStage
);
VBox
dialogVbox
=
new
VBox
(
20
);
if
(
gameEvent
.
getEventType
()
==
GameEvent
.
VICTORY_EVENT
)
{
dialogVbox
.
getChildren
().
add
(
new
Text
(
"This is a victory for player "
+
currentPlayer
+
"!"
));
}
else
if
(
gameEvent
.
getEventType
()
==
GameEvent
.
DRAW_EVENT
)
{
dialogVbox
.
getChildren
().
add
(
new
Text
(
"This is a Draw!"
));
}
Scene
dialogScene
=
new
Scene
(
dialogVbox
,
150
,
150
);
dialog
.
setScene
(
dialogScene
);
dialog
.
show
();
};
...
...
@@ -52,8 +49,8 @@ public class TicTacToeFX extends Application {
button
.
setPrefSize
(
100
,
100
);
// Größe der Buttons
grid
.
add
(
button
,
col
,
row
);
// Hinzufügen zum Grid
buttons
[
row
][
col
]
=
button
;
button
.
addEventHandler
(
GameEvent
.
VICTORY_EVENT
,
h
andler
);
button
.
addEventHandler
(
GameEvent
.
DRAW_EVENT
,
h
andler
);
button
.
addEventHandler
(
GameEvent
.
VICTORY_EVENT
,
gameEventH
andler
);
button
.
addEventHandler
(
GameEvent
.
DRAW_EVENT
,
gameEventH
andler
);
button
.
setOnAction
(
event
->
handleButtonClick
(
button
));
}
}
...
...
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