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
187c2d61
Commit
187c2d61
authored
8 years ago
by
Bariatti Francesco
Browse files
Options
Downloads
Patches
Plain Diff
Created update thread
parent
ad440533
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.java
+13
-1
13 additions, 1 deletion
gui/src/Controller.java
gui/src/GameState.java
+7
-2
7 additions, 2 deletions
gui/src/GameState.java
gui/src/UpdateThread.java
+49
-0
49 additions, 0 deletions
gui/src/UpdateThread.java
with
69 additions
and
3 deletions
gui/src/Controller.java
+
13
−
1
View file @
187c2d61
import
java.io.IOException
;
import
java.io.OutputStreamWriter
;
import
java.io.PrintWriter
;
import
java.net.URL
;
import
java.util.ResourceBundle
;
...
...
@@ -13,8 +15,9 @@ import javafx.scene.paint.Color;
import
javafx.scene.shape.Polygon
;
public
class
Controller
implements
Initializable
{
private
State
s
tate
;
private
Game
State
gameS
tate
;
private
Process
gameProcess
;
private
PrintWriter
gameInput
;
private
Plateau
plateau
;
@FXML
...
...
@@ -32,14 +35,23 @@ public class Controller implements Initializable {
c
.
setOnMouseEntered
(
new
MyHexEnteredHandler
());
}
this
.
plateau
=
new
Plateau
(
cases
);
this
.
gameState
=
new
GameState
();
try
{
this
.
gameProcess
=
new
ProcessBuilder
(
"../bin/theturk"
).
start
();
gameInput
=
new
PrintWriter
(
new
OutputStreamWriter
(
gameProcess
.
getOutputStream
()),
true
);
}
catch
(
IOException
e
)
{
Alert
alert
=
new
Alert
(
Alert
.
AlertType
.
ERROR
,
"Can't run penguin program"
,
ButtonType
.
OK
);
alert
.
showAndWait
();
e
.
printStackTrace
();
System
.
exit
(
1
);
}
UpdateThread
upT
=
new
UpdateThread
(
gameProcess
,
this
.
gameState
);
upT
.
setDaemon
(
true
);
upT
.
start
();
//We tell the game that we will start
gameInput
.
print
(
"h"
);
gameInput
.
println
();
}
//public Polygon getPolygonFromCoordinates(double x, double y){ }
...
...
This diff is collapsed.
Click to expand it.
gui/src/State.java
→
gui/src/
Game
State.java
+
7
−
2
View file @
187c2d61
import
org.json.*
;
public
class
State
{
public
void
update
(
String
json
){};
//TODO
public
class
GameState
{
public
void
update
(
String
json
){
System
.
out
.
println
(
json
);
};
public
int
getPenguinPos
(
int
i
,
Player
player
)
{
//TODO
...
...
This diff is collapsed.
Click to expand it.
gui/src/UpdateThread.java
0 → 100644
+
49
−
0
View file @
187c2d61
import
javafx.application.Platform
;
import
javafx.scene.control.Alert
;
import
javafx.scene.control.ButtonType
;
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
public
class
UpdateThread
extends
Thread
{
BufferedReader
reader
;
GameState
gameState
;
public
UpdateThread
(
Process
program
,
GameState
gameState
)
{
this
.
reader
=
new
BufferedReader
(
new
InputStreamReader
(
program
.
getInputStream
()));
this
.
gameState
=
gameState
;
}
public
void
run
()
{
boolean
running
=
true
;
while
(
running
)
try
{
String
line
=
reader
.
readLine
();
//System.out.println(line);
if
(
line
.
contains
(
"{"
))
{
gameState
.
update
(
line
.
substring
(
line
.
indexOf
(
"{"
),
line
.
lastIndexOf
(
"}"
)+
1
));
Platform
.
runLater
(()
->
{
// TODO: 4/27/16 update GUI from state
});
}
}
catch
(
IOException
e
)
{
running
=
false
;
Platform
.
runLater
(()
->
{
Alert
alert
=
new
Alert
(
Alert
.
AlertType
.
ERROR
,
"Error during reading from penguin program!"
,
ButtonType
.
FINISH
);
e
.
printStackTrace
();
alert
.
showAndWait
();
System
.
exit
(
1
);
});
}
}
}
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