Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
pingouins
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
Felton Samuel
pingouins
Commits
b6ec98de
Commit
b6ec98de
authored
8 years ago
by
Bariatti Francesco
Browse files
Options
Downloads
Patches
Plain Diff
Added status label for showing messages... and taunts!
parent
5108ccd1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
gui/src/controller/Controller.java
+15
-3
15 additions, 3 deletions
gui/src/controller/Controller.java
gui/src/controller/UpdateThread.java
+26
-2
26 additions, 2 deletions
gui/src/controller/UpdateThread.java
gui/src/view/view.fxml
+10
-9
10 additions, 9 deletions
gui/src/view/view.fxml
with
51 additions
and
14 deletions
gui/src/controller/Controller.java
+
15
−
3
View file @
b6ec98de
...
...
@@ -29,6 +29,7 @@ import java.util.ResourceBundle;
public
class
Controller
implements
Initializable
{
private
static
final
String
iaProgramPath
=
"../bin/theturk"
;
private
static
final
String
introMusicFile
=
"./resource/pingu_theme.wav"
;
private
static
final
String
clickSoundFile
=
"./resource/clic.wav"
;
...
...
@@ -50,7 +51,7 @@ public class Controller implements Initializable
private
BorderPane
mainPane
;
@FXML
private
Label
scoreRedLabel
,
scoreBlueLabel
,
turnLabel
;
private
Label
scoreRedLabel
,
scoreBlueLabel
,
turnLabel
,
statusLabel
;
@Override
public
void
initialize
(
URL
location
,
ResourceBundle
resources
)
...
...
@@ -67,7 +68,7 @@ public class Controller implements Initializable
this
.
gameState
=
new
GameState
();
try
{
this
.
gameProcess
=
new
ProcessBuilder
(
"../bin/theturk"
).
start
();
this
.
gameProcess
=
new
ProcessBuilder
(
iaProgramPath
).
start
();
gameInput
=
new
PrintWriter
(
new
OutputStreamWriter
(
gameProcess
.
getOutputStream
()),
true
);
Runtime
.
getRuntime
().
addShutdownHook
(
new
Thread
()
{
...
...
@@ -76,7 +77,7 @@ public class Controller implements Initializable
gameProcess
.
destroy
();
}
});
UpdateThread
upT
=
new
UpdateThread
(
gameProcess
,
this
.
gameState
,
this
.
board
,
this
.
boardView
,
scoreRedLabel
,
scoreBlueLabel
,
turnLabel
);
UpdateThread
upT
=
new
UpdateThread
(
gameProcess
,
this
.
gameState
,
this
.
board
,
this
.
boardView
,
scoreRedLabel
,
scoreBlueLabel
,
turnLabel
,
statusLabel
);
upT
.
setDaemon
(
true
);
upT
.
start
();
}
catch
(
IOException
e
)
...
...
@@ -135,6 +136,7 @@ public class Controller implements Initializable
t
.
getFxTile
().
setOnMouseClicked
(
phandl
);
t
.
getFishLabel
().
setOnMouseClicked
(
phandl
);
}
statusLabel
.
setText
(
"Click to place RED penguins"
);
}
}
...
...
@@ -189,6 +191,16 @@ public class Controller implements Initializable
boardView
[
tileNumber
].
update
();
}
penguinGenCounter
++;
if
(
penguinGenCounter
<
4
)
statusLabel
.
setText
(
"Red penguins left: "
+
Integer
.
toString
(
4
-
penguinGenCounter
));
else
if
(
penguinGenCounter
==
4
)
statusLabel
.
setText
(
"Click to place BLUE penguins"
);
else
if
(
penguinGenCounter
<
8
)
statusLabel
.
setText
(
"Blue penguins left: "
+
Integer
.
toString
(
8
-
penguinGenCounter
));
else
statusLabel
.
setText
(
""
);
//If we placed all penguins
if
(
penguinGenCounter
>=
8
)
{
gameInput
.
println
(
gameState
.
toGameInputJSON
());
...
...
This diff is collapsed.
Click to expand it.
gui/src/controller/UpdateThread.java
+
26
−
2
View file @
b6ec98de
...
...
@@ -18,9 +18,9 @@ public class UpdateThread extends Thread
GameState
gameState
;
Tile
[]
board
;
TileView
[]
boardView
;
Label
scoreRed
,
scoreBlue
,
turnLabel
;
Label
scoreRed
,
scoreBlue
,
turnLabel
,
statusLabel
;
public
UpdateThread
(
Process
program
,
GameState
gameState
,
Tile
[]
board
,
TileView
[]
boardView
,
Label
scoreRed
,
Label
scoreBlue
,
Label
turnLabel
)
public
UpdateThread
(
Process
program
,
GameState
gameState
,
Tile
[]
board
,
TileView
[]
boardView
,
Label
scoreRed
,
Label
scoreBlue
,
Label
turnLabel
,
Label
statusLabel
)
{
this
.
reader
=
new
BufferedReader
(
new
InputStreamReader
(
program
.
getInputStream
()));
this
.
writer
=
new
PrintWriter
(
new
OutputStreamWriter
(
program
.
getOutputStream
()),
true
);
...
...
@@ -30,6 +30,7 @@ public class UpdateThread extends Thread
this
.
scoreRed
=
scoreRed
;
this
.
scoreBlue
=
scoreBlue
;
this
.
turnLabel
=
turnLabel
;
this
.
statusLabel
=
statusLabel
;
}
public
void
run
()
...
...
@@ -97,6 +98,29 @@ public class UpdateThread extends Thread
}
}
}
else
if
(
line
.
startsWith
(
"("
)
&&
line
.
contains
(
"value:"
))
//lines with values (estimation) of the computer winning chances
{
//We want to show a little message to the user depending on if we win or not
Platform
.
runLater
(()
->
{
try
{
float
value
=
Float
.
valueOf
(
line
.
substring
(
line
.
indexOf
(
"value:"
)
+
7
,
line
.
indexOf
(
")"
)));
if
(
value
>
0.8
)
statusLabel
.
setText
(
"Are you sure you don't want to give up?"
);
else
if
(
value
>
0.3
)
statusLabel
.
setText
(
"You may want to think harder..."
);
else
if
(
value
>
-
0.3
)
statusLabel
.
setText
(
"I will win, in the end"
);
else
if
(
value
>
-
0.8
)
statusLabel
.
setText
(
"You may think you are winning... but you are not really"
);
else
statusLabel
.
setText
(
"I can not believe it... Human too strong... Segmentation fault."
);
}
catch
(
Exception
e
)
//This is not a core function, so if there is an exception we just ignore it
{
e
.
printStackTrace
();
}
});
}
}
catch
(
IOException
e
)
{
gameRunning
=
false
;
...
...
This diff is collapsed.
Click to expand it.
gui/src/view/view.fxml
+
10
−
9
View file @
b6ec98de
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.image.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.text.*?>
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.shape.*?>
<?import java.lang.Double?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.shape.Polygon?>
<?import javafx.scene.text.Font?>
<BorderPane
fx:id=
"mainPane"
xmlns=
"http://javafx.com/javafx/8.0.9
2
"
xmlns:fx=
"http://javafx.com/fxml/1"
fx:controller=
"controller.Controller"
>
<BorderPane
fx:id=
"mainPane"
xmlns=
"http://javafx.com/javafx/8.0.9
1
"
xmlns:fx=
"http://javafx.com/fxml/1"
fx:controller=
"controller.Controller"
>
<center>
<AnchorPane
prefHeight=
"
487
.0"
prefWidth=
"5
5
7.0"
BorderPane.alignment=
"CENTER"
>
<AnchorPane
prefHeight=
"
576
.0"
prefWidth=
"5
9
7.0"
BorderPane.alignment=
"CENTER"
>
<children>
<Polygon
fx:id=
"tile7"
fill=
"#1f93ff"
layoutX=
"39.0"
layoutY=
"434.0"
stroke=
"BLACK"
strokeType=
"INSIDE"
>
<points>
...
...
@@ -1077,6 +1073,11 @@
<Label
fx:id=
"nbFish22"
layoutX=
"34.0"
layoutY=
"337.0"
text=
"0"
/>
<Label
fx:id=
"nbFish37"
layoutX=
"34.0"
layoutY=
"247.0"
text=
"0"
/>
<Label
fx:id=
"nbFish52"
layoutX=
"34.0"
layoutY=
"157.0"
text=
"0"
/>
<Label
fx:id=
"statusLabel"
alignment=
"CENTER"
layoutX=
"29.0"
layoutY=
"484.0"
prefHeight=
"87.0"
prefWidth=
"383.0"
text=
"Good luck!"
textAlignment=
"CENTER"
wrapText=
"true"
>
<font>
<Font
size=
"22.0"
/>
</font>
</Label>
</children>
</AnchorPane>
</center>
...
...
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