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
1797cac1
Commit
1797cac1
authored
Dec 15, 2017
by
Quentin DRUAULT-AUBIN
Browse files
Merge branch 'IHM-Table/develop' into develop
parents
c1d984ce
551c6722
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
Battleship/src/main/java/com/utclo23/data/module/GameMediator.java
View file @
1797cac1
...
...
@@ -150,10 +150,8 @@ public class GameMediator {
/**
* Check if the ship has the right amount of coordinates
*/
for
(
Ship
s
:
player
.
getShips
())
{
if
(
s
.
getSize
()
!=
s
.
getListCoord
().
size
()){
throw
new
DataException
(
"Data : ship has more coordinates than its size"
);
}
if
(
ship
.
getSize
()
!=
ship
.
getListCoord
().
size
()){
throw
new
DataException
(
"Data : ship has more coordinates than its size"
);
}
...
...
Battleship/src/main/java/com/utclo23/ihmmain/controller/GameListController.java
View file @
1797cac1
...
...
@@ -303,7 +303,7 @@ public class GameListController extends AbstractController{
private
void
goIntoGame
(){
if
(
isRunning
()){
if
(
receivedGame
!=
null
){
getFacade
().
iIHMTableToIHMMain
.
showGame
(
receivedGame
);
getFacade
().
iIHMTableToIHMMain
.
showGame
();
}
else
{
showErrorPopup
(
"Connection Impossible"
,
""
,
"Your connection request failed."
);
refresh
();
...
...
Battleship/src/main/java/com/utclo23/ihmtable/IHMTableFacade.java
View file @
1797cac1
...
...
@@ -8,14 +8,11 @@ package com.utclo23.ihmtable;
import
com.utclo23.data.structure.Coordinate
;
import
com.utclo23.data.structure.StatGame
;
import
com.utclo23.data.facade.IDataIHMTable
;
import
com.utclo23.data.structure.Game
;
import
com.utclo23.data.structure.LightPublicUser
;
import
com.utclo23.ihmmain.controller.AbstractController
;
import
com.utclo23.data.structure.Ship
;
import
com.utclo23.ihmmain.facade.IHMMainToIhmTable
;
import
com.utclo23.ihmtable.controller.InGameGUIController
;
import
java.io.IOException
;
import
java.rmi.server.UID
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
import
javafx.fxml.FXMLLoader
;
...
...
@@ -132,10 +129,9 @@ public class IHMTableFacade implements IIHMTableToIHMMain, IIHMTableToData {
/**
* Join a current game.
* @param guid : id of the game.
*/
@Override
public
void
showGame
(
Game
game
)
{
public
void
showGame
()
{
//Créer la fenêtre
FXMLLoader
paneLoader
=
new
FXMLLoader
(
getClass
().
getResource
(
FXML_PATH
));
Parent
pane
;
...
...
@@ -194,20 +190,32 @@ public class IHMTableFacade implements IIHMTableToIHMMain, IIHMTableToData {
/**
* Show on the board if the shot has hit or not a ship.
* @param coord : the coordinates of the hit.
* @param bool : true if a ship is hit.
* @param touched : true if a ship is hit.
* @param destroyedShip : destroyed ship or null.
*/
@Override
public
void
feedBack
(
Coordinate
coord
,
boolean
bool
)
{
public
void
feedBack
(
Coordinate
coord
,
boolean
touched
,
Ship
destroyedShip
)
{
controller
.
displayOpponentAttack
(
coord
,
touched
,
destroyedShip
);
controller
.
timeToAttack
();
}
/**
* Display the new stats of the player.
* @param stGame : th
s
stats
* @param stGame : th
e
stats
*/
@Override
public
void
finishGame
(
StatGame
stGame
)
{
throw
new
UnsupportedOperationException
(
EXCEPTION_MESSAGE
);
String
sMessage
;
// Game lost.
if
(!
stGame
.
getWinner
().
getPlayerName
().
equals
(
facadeData
.
getMyPublicUserProfile
().
getPlayerName
()))
{
sMessage
=
"Defeat! You should train against AI! Hahahah!"
;
}
else
{
// Game won.
sMessage
=
"Victory! I'm proud of you General!"
;
}
// Display popup.
controller
.
displayFinishPopup
(
sMessage
);
}
/**
...
...
@@ -215,7 +223,8 @@ public class IHMTableFacade implements IIHMTableToIHMMain, IIHMTableToData {
*/
@Override
public
void
opponentHasLeftGame
()
{
throw
new
UnsupportedOperationException
(
EXCEPTION_MESSAGE
);
// Display popup.
controller
.
displayFinishPopup
(
"Your opponent has left this game!"
);
}
/**
...
...
@@ -223,7 +232,7 @@ public class IHMTableFacade implements IIHMTableToIHMMain, IIHMTableToData {
*/
@Override
public
void
connectionLostWithOpponent
()
{
throw
new
UnsupportedOperationException
(
EXCEPTION_MESSAGE
);
controller
.
displayFinishPopup
(
"Connection has been lost with your opponent"
);
}
/**
...
...
Battleship/src/main/java/com/utclo23/ihmtable/IIHMTableToData.java
View file @
1797cac1
...
...
@@ -6,6 +6,7 @@
package
com.utclo23.ihmtable
;
import
com.utclo23.data.structure.Coordinate
;
import
com.utclo23.data.structure.Ship
;
import
com.utclo23.data.structure.StatGame
;
/**
...
...
@@ -15,7 +16,7 @@ import com.utclo23.data.structure.StatGame;
public
interface
IIHMTableToData
{
public
void
notifyGameReady
();
public
void
printMessage
(
String
message
);
public
void
feedBack
(
Coordinate
coord
,
boolean
bool
);
public
void
feedBack
(
Coordinate
coord
,
boolean
bool
,
Ship
destroyedShip
);
public
void
finishGame
(
StatGame
stGame
);
public
void
opponentHasLeftGame
();
public
void
connectionLostWithOpponent
();
...
...
Battleship/src/main/java/com/utclo23/ihmtable/IIHMTableToIHMMain.java
View file @
1797cac1
...
...
@@ -5,8 +5,6 @@
*/
package
com.utclo23.ihmtable
;
import
com.utclo23.data.structure.Game
;
import
java.rmi.server.UID
;
import
javafx.stage.Stage
;
/**
...
...
@@ -17,5 +15,5 @@ public interface IIHMTableToIHMMain {
public
void
showSavedGameWithId
(
int
id
);
public
void
createInGameGUI
(
Stage
primaryStage
);
public
void
stopTimer
();
public
void
showGame
(
Game
game
);
public
void
showGame
();
}
Battleship/src/main/java/com/utclo23/ihmtable/controller/InGameGUIController.java
View file @
1797cac1
This diff is collapsed.
Click to expand it.
Battleship/src/main/java/com/utclo23/ihmtable/structure/CoordinatesGenerator.java
0 → 100644
View file @
1797cac1
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package
com.utclo23.ihmtable.structure
;
import
com.utclo23.data.structure.Coordinate
;
import
java.util.List
;
/**
*
* @author gum
*/
public
class
CoordinatesGenerator
{
/**
* This function adds coordinates between a starting/ending point
* @param startPosition Start position of the ship
* @param endPosition End position of the ship
* @param list List in which coordinates have to be added
*/
public
static
void
generate
(
Coordinate
startPosition
,
Coordinate
endPosition
,
List
<
Coordinate
>
list
)
{
// For 1-cell ships.
if
(
startPosition
.
getX
()
==
endPosition
.
getX
()
&&
startPosition
.
getY
()
==
endPosition
.
getY
()
)
{
list
.
add
(
endPosition
);
}
else
{
// For more-tan-two-cell ship.
list
.
add
(
startPosition
);
// 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
)
{
list
.
add
(
new
Coordinate
(
startPosition
.
getX
()
+
xDirection
*
x
,
startPosition
.
getY
()));
}
for
(
int
y
=
1
;
y
<
Math
.
abs
(
diff
.
getY
());
++
y
)
{
list
.
add
(
new
Coordinate
(
startPosition
.
getX
(),
startPosition
.
getY
()
+
yDirection
*
y
));
}
list
.
add
(
endPosition
);
}
}
}
Battleship/src/test/java/com/utclo23/ihmtable/CoordinatesGenerationTest.java
0 → 100644
View file @
1797cac1
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package
com.utclo23.ihmtable
;
import
com.utclo23.data.structure.Coordinate
;
import
com.utclo23.ihmtable.structure.CoordinatesGenerator
;
import
java.util.ArrayList
;
import
static
org
.
junit
.
Assert
.*;
/**
*
* @author gum
*/
public
class
CoordinatesGenerationTest
{
private
static
CoordinatesGenerator
generator
=
new
CoordinatesGenerator
();
@org
.
junit
.
Test
public
void
testCoordinateGenerator1
()
throws
Exception
{
Coordinate
startPoint
=
new
Coordinate
(
1
,
1
);
Coordinate
endPoint
=
new
Coordinate
(
5
,
1
);
ArrayList
<
Coordinate
>
coordinates
=
new
ArrayList
<
Coordinate
>();
CoordinatesGenerator
.
generate
(
startPoint
,
endPoint
,
coordinates
);
assertTrue
(
"Must contains (1,1)"
,
equal
(
new
Coordinate
(
1
,
1
),
coordinates
.
get
(
0
)));
assertTrue
(
"Must contains (2,1)"
,
equal
(
new
Coordinate
(
2
,
1
),
coordinates
.
get
(
1
)));
assertTrue
(
"Must contains (3,1)"
,
equal
(
new
Coordinate
(
3
,
1
),
coordinates
.
get
(
2
)));
assertTrue
(
"Must contains (4,1)"
,
equal
(
new
Coordinate
(
4
,
1
),
coordinates
.
get
(
3
)));
assertTrue
(
"Must contains (5,1)"
,
equal
(
new
Coordinate
(
5
,
1
),
coordinates
.
get
(
4
)));
}
@org
.
junit
.
Test
public
void
testCoordinateGenerator2
()
throws
Exception
{
Coordinate
startPoint
=
new
Coordinate
(
5
,
1
);
Coordinate
endPoint
=
new
Coordinate
(
1
,
1
);
ArrayList
<
Coordinate
>
coordinates
=
new
ArrayList
<
Coordinate
>();
CoordinatesGenerator
.
generate
(
startPoint
,
endPoint
,
coordinates
);
assertTrue
(
"Must contains (5,1)"
,
equal
(
new
Coordinate
(
5
,
1
),
coordinates
.
get
(
0
)));
assertTrue
(
"Must contains (4,1)"
,
equal
(
new
Coordinate
(
4
,
1
),
coordinates
.
get
(
1
)));
assertTrue
(
"Must contains (3,1)"
,
equal
(
new
Coordinate
(
3
,
1
),
coordinates
.
get
(
2
)));
assertTrue
(
"Must contains (2,1)"
,
equal
(
new
Coordinate
(
2
,
1
),
coordinates
.
get
(
3
)));
assertTrue
(
"Must contains (1,1)"
,
equal
(
new
Coordinate
(
1
,
1
),
coordinates
.
get
(
4
)));
}
@org
.
junit
.
Test
public
void
testCoordinateGenerator3
()
throws
Exception
{
Coordinate
startPoint
=
new
Coordinate
(
1
,
5
);
Coordinate
endPoint
=
new
Coordinate
(
1
,
1
);
ArrayList
<
Coordinate
>
coordinates
=
new
ArrayList
<
Coordinate
>();
CoordinatesGenerator
.
generate
(
startPoint
,
endPoint
,
coordinates
);
assertTrue
(
"Must contains (1,5)"
,
equal
(
new
Coordinate
(
1
,
5
),
coordinates
.
get
(
0
)));
assertTrue
(
"Must contains (1,4)"
,
equal
(
new
Coordinate
(
1
,
4
),
coordinates
.
get
(
1
)));
assertTrue
(
"Must contains (1,3)"
,
equal
(
new
Coordinate
(
1
,
3
),
coordinates
.
get
(
2
)));
assertTrue
(
"Must contains (1,2)"
,
equal
(
new
Coordinate
(
1
,
2
),
coordinates
.
get
(
3
)));
assertTrue
(
"Must contains (1,1)"
,
equal
(
new
Coordinate
(
1
,
1
),
coordinates
.
get
(
4
)));
}
@org
.
junit
.
Test
public
void
testCoordinateGenerator4
()
throws
Exception
{
Coordinate
startPoint
=
new
Coordinate
(
1
,
1
);
Coordinate
endPoint
=
new
Coordinate
(
1
,
5
);
ArrayList
<
Coordinate
>
coordinates
=
new
ArrayList
<
Coordinate
>();
CoordinatesGenerator
.
generate
(
startPoint
,
endPoint
,
coordinates
);
assertTrue
(
"Must contains (1,1)"
,
equal
(
new
Coordinate
(
1
,
1
),
coordinates
.
get
(
0
)));
assertTrue
(
"Must contains (1,2)"
,
equal
(
new
Coordinate
(
1
,
2
),
coordinates
.
get
(
1
)));
assertTrue
(
"Must contains (1,3)"
,
equal
(
new
Coordinate
(
1
,
3
),
coordinates
.
get
(
2
)));
assertTrue
(
"Must contains (1,4)"
,
equal
(
new
Coordinate
(
1
,
4
),
coordinates
.
get
(
3
)));
assertTrue
(
"Must contains (1,5)"
,
equal
(
new
Coordinate
(
1
,
5
),
coordinates
.
get
(
4
)));
}
@org
.
junit
.
Test
public
void
testCoordinateGenerator5
()
throws
Exception
{
Coordinate
startPoint
=
new
Coordinate
(
1
,
1
);
Coordinate
endPoint
=
new
Coordinate
(
2
,
1
);
ArrayList
<
Coordinate
>
coordinates
=
new
ArrayList
<
Coordinate
>();
CoordinatesGenerator
.
generate
(
startPoint
,
endPoint
,
coordinates
);
assertTrue
(
"Must contains (1,1)"
,
equal
(
new
Coordinate
(
1
,
1
),
coordinates
.
get
(
0
)));
assertTrue
(
"Must contains (2,1)"
,
equal
(
new
Coordinate
(
2
,
1
),
coordinates
.
get
(
1
)));
}
@org
.
junit
.
Test
public
void
testCoordinateGenerator6
()
throws
Exception
{
Coordinate
startPoint
=
new
Coordinate
(
2
,
1
);
Coordinate
endPoint
=
new
Coordinate
(
1
,
1
);
ArrayList
<
Coordinate
>
coordinates
=
new
ArrayList
<
Coordinate
>();
CoordinatesGenerator
.
generate
(
startPoint
,
endPoint
,
coordinates
);
assertTrue
(
"Must contains (2,1)"
,
equal
(
new
Coordinate
(
2
,
1
),
coordinates
.
get
(
0
)));
assertTrue
(
"Must contains (1,1)"
,
equal
(
new
Coordinate
(
1
,
1
),
coordinates
.
get
(
1
)));
}
@org
.
junit
.
Test
public
void
testCoordinateGenerator7
()
throws
Exception
{
Coordinate
startPoint
=
new
Coordinate
(
1
,
2
);
Coordinate
endPoint
=
new
Coordinate
(
1
,
1
);
ArrayList
<
Coordinate
>
coordinates
=
new
ArrayList
<
Coordinate
>();
CoordinatesGenerator
.
generate
(
startPoint
,
endPoint
,
coordinates
);
assertTrue
(
"Must contains (1,2)"
,
equal
(
new
Coordinate
(
1
,
2
),
coordinates
.
get
(
0
)));
assertTrue
(
"Must contains (1,1)"
,
equal
(
new
Coordinate
(
1
,
1
),
coordinates
.
get
(
1
)));
}
@org
.
junit
.
Test
public
void
testCoordinateGenerator8
()
throws
Exception
{
Coordinate
startPoint
=
new
Coordinate
(
1
,
1
);
Coordinate
endPoint
=
new
Coordinate
(
1
,
2
);
ArrayList
<
Coordinate
>
coordinates
=
new
ArrayList
<
Coordinate
>();
CoordinatesGenerator
.
generate
(
startPoint
,
endPoint
,
coordinates
);
assertTrue
(
"Must contains (1,1)"
,
equal
(
new
Coordinate
(
1
,
1
),
coordinates
.
get
(
0
)));
assertTrue
(
"Must contains (1,2)"
,
equal
(
new
Coordinate
(
1
,
2
),
coordinates
.
get
(
1
)));
}
@org
.
junit
.
Test
public
void
testCoordinateGeneratorOneCell
()
throws
Exception
{
Coordinate
startPoint
=
new
Coordinate
(
1
,
1
);
Coordinate
endPoint
=
new
Coordinate
(
1
,
1
);
ArrayList
<
Coordinate
>
coordinates
=
new
ArrayList
<
Coordinate
>();
CoordinatesGenerator
.
generate
(
startPoint
,
endPoint
,
coordinates
);
assertTrue
(
"Must contains (1,1)"
,
equal
(
new
Coordinate
(
1
,
1
),
coordinates
.
get
(
0
)));
assertTrue
(
"Must contains only 1 cell"
,
coordinates
.
size
()
==
1
);
}
public
boolean
equal
(
Coordinate
c1
,
Coordinate
c2
)
{
return
c1
.
getX
()
==
c2
.
getX
()
&&
c1
.
getY
()
==
c2
.
getY
();
}
}
\ No newline at end of file
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