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
57052dc0
Commit
57052dc0
authored
2 months ago
by
jan-schw
Browse files
Options
Downloads
Patches
Plain Diff
add close button
parent
913d97e7
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
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/com/example/tictactoe_game/TicTacToeFX.java
+22
-17
22 additions, 17 deletions
src/main/java/com/example/tictactoe_game/TicTacToeFX.java
with
22 additions
and
17 deletions
src/main/java/com/example/tictactoe_game/TicTacToeFX.java
+
22
−
17
View file @
57052dc0
...
...
@@ -2,6 +2,7 @@ package com.example.tictactoe_game;
import
javafx.application.Application
;
import
javafx.event.EventHandler
;
import
javafx.geometry.Pos
;
import
javafx.scene.Scene
;
import
javafx.scene.control.Button
;
import
javafx.scene.layout.GridPane
;
...
...
@@ -28,8 +29,7 @@ public class TicTacToeFX extends Application {
public
void
start
(
Stage
primaryStage
)
{
EventHandler
<
GameEvent
>
gameEventHandler
=
gameEvent
->
{
String
currentPlayer
=
isXTurn
?
"X"
:
"O"
;
String
currentPlayer
=
this
.
isXTurn
?
"X"
:
"O"
;
final
Stage
dialog
=
new
Stage
();
dialog
.
initModality
(
Modality
.
APPLICATION_MODAL
);
dialog
.
initOwner
(
primaryStage
);
...
...
@@ -45,6 +45,12 @@ public class TicTacToeFX extends Application {
dialogVbox
.
getChildren
().
add
(
new
Text
(
"This is a Draw!"
));
}
Button
closeButton
=
new
Button
();
closeButton
.
setText
(
"Close"
);
closeButton
.
setOnAction
(
event
->
primaryStage
.
close
());
dialogVbox
.
getChildren
().
add
(
closeButton
);
dialogVbox
.
setAlignment
(
Pos
.
CENTER
);
Scene
dialogScene
=
new
Scene
(
dialogVbox
,
200
,
100
);
dialog
.
setScene
(
dialogScene
);
dialog
.
show
();
...
...
@@ -75,14 +81,14 @@ public class TicTacToeFX extends Application {
grid
.
add
(
turnCounter
,
3
,
1
);
// Szene und Stage erstellen
Scene
scene1
=
new
Scene
(
grid
,
3
00
,
300
);
// Größe der Szene
Scene
scene1
=
new
Scene
(
grid
,
4
00
,
300
);
// Größe der Szene
primaryStage
.
setTitle
(
"Tic-Tac-Toe"
);
primaryStage
.
setScene
(
scene1
);
primaryStage
.
show
();
}
private
void
handleButtonClick
(
Button
button
)
{
if
(
button
.
getText
().
isEmpty
()
&&
!
this
.
isGameOver
)
{
if
(
button
.
getText
().
isEmpty
()
&&
!
this
.
isGameOver
)
{
if
(
this
.
isXTurn
)
{
button
.
setText
(
"X"
);
this
.
currentTurn
++;
...
...
@@ -94,8 +100,7 @@ public class TicTacToeFX extends Application {
if
(
checkForWin
())
{
this
.
isGameOver
=
true
;
button
.
fireEvent
(
new
GameEvent
(
GameEvent
.
VICTORY_EVENT
));
}
else
if
(
checkForDraw
()){
}
else
if
(
checkForDraw
())
{
this
.
isGameOver
=
true
;
button
.
fireEvent
(
new
GameEvent
(
GameEvent
.
DRAW_EVENT
));
}
...
...
@@ -106,21 +111,21 @@ public class TicTacToeFX extends Application {
}
}
private
boolean
checkForWin
(){
for
(
int
row
=
0
;
row
<
3
;
row
++){
private
boolean
checkForWin
()
{
for
(
int
row
=
0
;
row
<
3
;
row
++)
{
String
text1
=
buttons
[
row
][
0
].
getText
();
String
text2
=
buttons
[
row
][
1
].
getText
();
String
text3
=
buttons
[
row
][
2
].
getText
();
if
(!
text1
.
isEmpty
()
&&
text1
.
equals
(
text2
)
&&
text1
.
equals
(
text3
)){
if
(!
text1
.
isEmpty
()
&&
text1
.
equals
(
text2
)
&&
text1
.
equals
(
text3
))
{
return
true
;
}
}
for
(
int
col
=
0
;
col
<
3
;
col
++){
for
(
int
col
=
0
;
col
<
3
;
col
++)
{
String
text1
=
buttons
[
0
][
col
].
getText
();
String
text2
=
buttons
[
1
][
col
].
getText
();
String
text3
=
buttons
[
2
][
col
].
getText
();
if
(!
text1
.
isEmpty
()
&&
text1
.
equals
(
text2
)
&&
text1
.
equals
(
text3
)){
if
(!
text1
.
isEmpty
()
&&
text1
.
equals
(
text2
)
&&
text1
.
equals
(
text3
))
{
return
true
;
}
}
...
...
@@ -131,21 +136,21 @@ public class TicTacToeFX extends Application {
String
upperRightCorner
=
buttons
[
0
][
2
].
getText
();
String
lowerLeftCorner
=
buttons
[
2
][
0
].
getText
();
if
(!
upperLeftCorner
.
isEmpty
()
&&
upperLeftCorner
.
equals
(
center
)
&&
upperLeftCorner
.
equals
(
lowerRightCorner
)){
if
(!
upperLeftCorner
.
isEmpty
()
&&
upperLeftCorner
.
equals
(
center
)
&&
upperLeftCorner
.
equals
(
lowerRightCorner
))
{
return
true
;
}
if
(!
upperRightCorner
.
isEmpty
()
&&
upperRightCorner
.
equals
(
center
)
&&
upperRightCorner
.
equals
(
lowerLeftCorner
)){
if
(!
upperRightCorner
.
isEmpty
()
&&
upperRightCorner
.
equals
(
center
)
&&
upperRightCorner
.
equals
(
lowerLeftCorner
))
{
return
true
;
}
return
false
;
}
private
boolean
checkForDraw
(){
for
(
int
row
=
0
;
row
<
3
;
row
++){
for
(
int
col
=
0
;
col
<
3
;
col
++){
if
(
buttons
[
row
][
col
].
getText
().
isEmpty
()){
private
boolean
checkForDraw
()
{
for
(
int
row
=
0
;
row
<
3
;
row
++)
{
for
(
int
col
=
0
;
col
<
3
;
col
++)
{
if
(
buttons
[
row
][
col
].
getText
().
isEmpty
())
{
return
false
;
}
}
...
...
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