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
5814899d
Commit
5814899d
authored
2 months ago
by
Josua Oppermann
Browse files
Options
Downloads
Patches
Plain Diff
Random Images and Reset fix
parent
9fe7bcf4
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
GameUI.java
+35
-2
35 additions, 2 deletions
GameUI.java
Tile.java
+1
-13
1 addition, 13 deletions
Tile.java
with
36 additions
and
15 deletions
GameUI.java
+
35
−
2
View file @
5814899d
...
...
@@ -5,6 +5,7 @@ import javafx.scene.image.*;
import
javafx.scene.control.*
;
import
javafx.scene.layout.*
;
import
javafx.stage.Stage
;
import
java.util.Random
;
public
class
GameUI
extends
Application
{
Scene
game
,
winningScene
;
...
...
@@ -15,6 +16,9 @@ public class GameUI extends Application{
private
Label
scoreLabelX
=
new
Label
(
"Player X: 0"
);
private
Label
scoreLabelO
=
new
Label
(
"Player O: 0"
);
private
Button
[]
buttons
=
new
Button
[
9
];
/**Random for Images */
Random
rnd
=
new
Random
();
/**
* Provides styles allignment and the scenes for labels, buttons and boxes.
...
...
@@ -37,6 +41,17 @@ public class GameUI extends Application{
buttons
[
i
]
=
new
Button
();
buttons
[
i
].
setPrefSize
(
150
,
150
);
buttons
[
i
].
setOnAction
(
e
->
handleTurn
(
index
,
stage
));
String
imageSymbols
=
getClass
().
getResource
(
"/textures/empty.png"
).
toExternalForm
();
Image
image
=
new
Image
(
""
+
imageSymbols
);
ImageView
imageView
=
new
ImageView
(
image
);
imageView
.
setFitWidth
(
135
);
imageView
.
setFitHeight
(
135
);
imageView
.
setPreserveRatio
(
true
);
buttons
[
index
].
setGraphic
(
imageView
);
gridPane
.
add
(
buttons
[
i
],
i
%
3
,
i
/
3
);
}
...
...
@@ -74,7 +89,24 @@ public class GameUI extends Application{
//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
));
reset
.
setOnAction
(
e
->
{
board
=
new
Board
(
board
.
players
,
board
.
firstPlayer
);
for
(
int
i
=
0
;
i
<
9
;
i
++){
int
index
=
i
;
String
imageSymbols
=
getClass
().
getResource
(
"/textures/empty.png"
).
toExternalForm
();
Image
image
=
new
Image
(
""
+
imageSymbols
);
ImageView
imageView
=
new
ImageView
(
image
);
imageView
.
setFitWidth
(
135
);
imageView
.
setFitHeight
(
135
);
imageView
.
setPreserveRatio
(
true
);
buttons
[
index
].
setGraphic
(
imageView
);
}
stage
.
setScene
(
game
);
});
//winning/tie screen
winnerLabel
.
setAlignment
(
Pos
.
CENTER
);
...
...
@@ -104,7 +136,8 @@ public class GameUI extends Application{
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
();
String
imageSymbols
=
board
.
currentPlayer
==
0
?
getClass
().
getResource
(
"/textures/1_"
+
rnd
.
nextInt
(
3
)
+
".png"
).
toExternalForm
()
:
getClass
().
getResource
(
"/textures/0_"
+
rnd
.
nextInt
(
3
)
+
".png"
).
toExternalForm
();
Image
image
=
new
Image
(
""
+
imageSymbols
);
ImageView
imageView
=
new
ImageView
(
image
);
...
...
This diff is collapsed.
Click to expand it.
Tile.java
+
1
−
13
View file @
5814899d
import
java.util.Random
;
public
class
Tile
{
...
...
@@ -11,18 +11,6 @@ public class Tile {
* -1 = no one; 0 = Player 1; 1 = Player 2
*/
int
owner
=
-
1
;
/**Random for Images
*
*/
Random
rnd
=
new
Random
();
/**Paths for the images
*
*/
String
imagePathPlayer
=
"./textures/"
+
owner
+
"_"
+
rnd
.
nextInt
(
3
);
String
imagePathEmpty
=
"./textures/empty"
;
/**Initializer for Tile Objects
* @param size Sets the Size of the Image
...
...
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