Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Quentin DRUAULT-AUBIN
lo23-project
Commits
8ad6c03b
Commit
8ad6c03b
authored
Dec 12, 2017
by
Paul Jeannot
Committed by
Quentin DRUAULT-AUBIN
Dec 15, 2017
Browse files
[Ship] Compute coordinates between start/end point of a given ship
parent
fa0ca785
Changes
1
Hide whitespace changes
Inline
Side-by-side
Battleship/src/main/java/com/utclo23/ihmtable/controller/InGameGUIController.java
View file @
8ad6c03b
...
...
@@ -956,6 +956,18 @@ public class InGameGUIController {
// Add the coordinates.
ship
.
getListCoord
().
add
(
startPosition
);
ship
.
getListCoord
().
add
(
endPosition
);
// Add the coordinates between the two cases.
Coordinate
diff
=
new
Coordinate
(
endPosition
.
getX
()-
startPosition
.
getX
(),
endPosition
.
getY
()-
startPosition
.
getY
());
int
xDirection
=
(
diff
.
getX
()
>=
0
)
?
1
:
-
1
;
int
yDirection
=
(
diff
.
getY
()
>=
0
)
?
1
:
-
1
;
for
(
int
x
=
1
;
x
<
Math
.
abs
(
diff
.
getX
());
++
x
)
{
ship
.
getListCoord
().
add
(
new
Coordinate
(
startPosition
.
getX
()+
xDirection
*
x
,
startPosition
.
getY
()));
}
for
(
int
y
=
1
;
y
<
Math
.
abs
(
diff
.
getY
());
++
y
)
{
ship
.
getListCoord
().
add
(
new
Coordinate
(
startPosition
.
getX
(),
startPosition
.
getY
()+
yDirection
*
y
));
}
// Send the ship.
facade
.
getFacadeData
().
setShip
(
ship
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment