Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Tristan MAISONNEUVE
projetS2-2021-23-LJ
Commits
d54b155d
Commit
d54b155d
authored
Jun 24, 2021
by
Jérémie
Browse files
Ships et class bateau commenté
parent
d1a139aa
Changes
8
Hide whitespace changes
Inline
Side-by-side
out/production/battleship-student-project-2021/vue/FenetreConnexion.class
View file @
d54b155d
No preview for this file type
out/production/battleship-student-project-2021/vue/FenetreJeux.class
View file @
d54b155d
No preview for this file type
src/modele/info1/ships/AircraftCarrier.java
View file @
d54b155d
...
...
@@ -8,16 +8,16 @@ import info1.ships.ShipCategory;
* Classe définissant une navire de catégorie "Porte-Avion" (taille 5)
*/
public
class
AircraftCarrier
extends
Ship
{
public
class
AircraftCarrier
extends
Ship
{
//Class porte-avion, extension de Ship
public
AircraftCarrier
(
String
name
,
String
xyFront
,
String
xyBack
)
throws
BadCoordException
,
CoordsBadShipException
{
super
(
name
,
xyFront
,
xyBack
);
public
AircraftCarrier
(
String
name
,
String
xyFront
,
String
xyBack
)
//Constructeur avec le nom, les coordonnées de l'avant et l'arrière du bateau
throws
BadCoordException
,
CoordsBadShipException
{
//qui peut renvoyer les exceptions
super
(
name
,
xyFront
,
xyBack
);
//renvoie ses argument a sa classe mère
}
@Override
public
ShipCategory
getCategory
()
{
return
ShipCategory
.
AIRCRAFT_CARRIER
;
}
}
//getter de sa categorie
}
src/modele/info1/ships/Battleship.java
View file @
d54b155d
...
...
@@ -9,16 +9,16 @@ import info1.ships.ShipCategory;
* @author lanoix-a
*/
public
class
Battleship
extends
Ship
{
public
class
Battleship
extends
Ship
{
//Class Battleship, extension de Ship
public
Battleship
(
String
name
,
String
xyFront
,
String
xyBack
)
throws
BadCoordException
,
CoordsBadShipException
{
super
(
name
,
xyFront
,
xyBack
);
throws
BadCoordException
,
CoordsBadShipException
{
//qui peut renvoyer les exceptions
super
(
name
,
xyFront
,
xyBack
);
//renvoie ses argument a sa classe mère
}
@Override
public
ShipCategory
getCategory
()
{
return
ShipCategory
.
BATTLESHIP
;
}
}
//getter de sa categorie
}
src/modele/info1/ships/Cruiser.java
View file @
d54b155d
...
...
@@ -10,16 +10,16 @@ import info1.ships.ShipCategory;
* @author lanoix-a
*/
public
class
Cruiser
extends
Ship
{
public
class
Cruiser
extends
Ship
{
//Class Cruiser, extension de Ship
public
Cruiser
(
String
name
,
String
xyFront
,
String
xyBack
)
throws
BadCoordException
,
CoordsBadShipException
{
super
(
name
,
xyFront
,
xyBack
);
throws
BadCoordException
,
CoordsBadShipException
{
//qui peut renvoyer les exceptions
super
(
name
,
xyFront
,
xyBack
);
//renvoie ses argument a sa classe mère
}
@Override
public
ShipCategory
getCategory
()
{
return
ShipCategory
.
CRUISER
;
}
}
//getter de sa categorie
}
src/modele/info1/ships/Destroyer.java
View file @
d54b155d
...
...
@@ -10,16 +10,16 @@ import info1.ships.ShipCategory;
* @author lanoix-a
*/
public
class
Destroyer
extends
Ship
{
public
class
Destroyer
extends
Ship
{
//Class Destroyer, extension de Ship
public
Destroyer
(
String
name
,
String
xyFront
,
String
xyBack
)
throws
BadCoordException
,
CoordsBadShipException
{
super
(
name
,
xyFront
,
xyBack
);
throws
BadCoordException
,
CoordsBadShipException
{
//qui peut renvoyer les exceptions
super
(
name
,
xyFront
,
xyBack
);
//renvoie ses argument a sa classe mère
}
@Override
public
ShipCategory
getCategory
()
{
return
ShipCategory
.
DESTROYER
;
}
}
//getter de sa categorie
}
src/modele/info1/ships/Ship.java
View file @
d54b155d
...
...
@@ -11,11 +11,11 @@ import java.util.Objects;
*/
public
abstract
class
Ship
implements
IShip
{
public
abstract
class
Ship
implements
IShip
{
//Class shipe implémentant l'interface IShip
private
String
name
;
Coord
cord1
;
Coord
cord2
;
private
String
name
;
//Argument : nom
Coord
cord1
;
//Argument : Coordonnée de l'avant
Coord
cord2
;
//Argument : Coordonnée de l'arriere
/**
...
...
@@ -29,22 +29,22 @@ public abstract class Ship implements IShip {
* @throws CoordsBadShipException si les coordonnées données ne permettent pas de définir un bateau correct :
* une ligne, une colonne, de la bonne taille, etc.
*/
public
Ship
(
String
name
,
String
ayFront
,
String
ayBack
)
throws
BadCoordException
,
CoordsBadShipException
{
this
.
name
=
name
;
this
.
cord1
=
new
Coord
(
ayFront
);
this
.
cord2
=
new
Coord
(
ayBack
);
if
(
getCategory
().
getSize
()!=
getSize
()){
throw
new
CoordsBadShipException
();
public
Ship
(
String
name
,
String
ayFront
,
String
ayBack
)
//Constructeur avec les argument
throws
BadCoordException
,
CoordsBadShipException
{
//qui peut renvoyer les exceptions
this
.
name
=
name
;
//attribue les argument à leur variables d'instances réspectives
this
.
cord1
=
new
Coord
(
ayFront
);
//convertie les coordonnée de String en Coord
this
.
cord2
=
new
Coord
(
ayBack
);
//idem
if
(
getCategory
().
getSize
()!=
getSize
()){
//verifie si la taille du bateau correspond bien a son type
throw
new
CoordsBadShipException
();
//renvoie une erreur si ce n'est pas le cas
}
}
@Override
public
List
<
ICoord
>
getCoords
()
{
ArrayList
<
ICoord
>
list
=
new
ArrayList
<>();
Coord
icord1
=
cord1
;
Coord
icord2
=
cord2
;
public
List
<
ICoord
>
getCoords
()
{
//methode renvoyant la liste des coordonnée sur lesquelle sont le bateau
ArrayList
<
ICoord
>
list
=
new
ArrayList
<>();
//création d'une arrayList qui contiendra ces coordonnées
Coord
icord1
=
cord1
;
//création de variable contenant ce qu'il y a dans les variable d'instance
Coord
icord2
=
cord2
;
//idem
int
j
=
0
;
if
(
cord1
.
toString
().
equals
(
cord2
.
toString
())){
list
.
add
(
cord1
);
...
...
@@ -72,53 +72,53 @@ public abstract class Ship implements IShip {
}
}
}
return
list
;
return
list
;
//return l'arrayList pleine
}
@Override
public
ICoord
getFront
()
{
return
cord1
;
}
}
//getter de la coordonnée avant
@Override
public
ICoord
getBack
()
{
return
cord2
;
}
}
//getter de la coordonnée arrière
@Override
public
String
getName
()
{
return
this
.
name
;
}
}
//getter du nom du bateau
@Override
public
int
getSize
()
{
if
(
cord1
.
getY
()==
cord2
.
getY
()){
if
(
cord1
.
getX
()>
cord2
.
getX
())
return
cord1
.
getX
()-
cord2
.
getX
()+
1
;
return
cord2
.
getX
()-
cord1
.
getX
()+
1
;
public
int
getSize
()
{
//Methode pour avoir la taille du bateau
if
(
cord1
.
getY
()==
cord2
.
getY
()){
//test si le bateau est dans le sens horizontale
if
(
cord1
.
getX
()>
cord2
.
getX
())
//test si le bateau est de droite a gauche
return
cord1
.
getX
()-
cord2
.
getX
()+
1
;
//retourne sa taille
return
cord2
.
getX
()-
cord1
.
getX
()+
1
;
//retourne sa taille s'il est de gauche a droite
}
if
(
cord1
.
getX
()==
cord2
.
getX
()){
if
(
cord1
.
getY
()>
cord2
.
getY
())
return
cord1
.
getY
()-
cord2
.
getY
()+
1
;
return
cord2
.
getY
()-
cord1
.
getY
()+
1
;
if
(
cord1
.
getX
()==
cord2
.
getX
()){
//test si le bateau est dans le sens verticale
if
(
cord1
.
getY
()>
cord2
.
getY
())
//test si le bateau est de bas en haut
return
cord1
.
getY
()-
cord2
.
getY
()+
1
;
//retourne sa taille
return
cord2
.
getY
()-
cord1
.
getY
()+
1
;
//retourne sa taille s'il est de haut en bas
}
return
-
1
;
return
-
1
;
//retourne -1 si la methode si aucun des test n'est concluant (bug)
}
public
ShipCategory
gettheCategory
(){
return
getCategory
();
}
}
//retourne la catégorie du bateau
@Override
public
boolean
equals
(
Object
o
)
{
if
(
this
==
o
)
return
true
;
if
(
o
==
null
||
getClass
()
!=
o
.
getClass
())
return
false
;
public
boolean
equals
(
Object
o
)
{
//methode redéfinissant le equals
if
(
this
==
o
)
return
true
;
//retourne true s'ils sont égaux
if
(
o
==
null
||
getClass
()
!=
o
.
getClass
())
return
false
;
// retourne false si equals n'a pas d'argument ou si les bateaux ne sont pas de la même classe
Ship
ship
=
(
Ship
)
o
;
return
Objects
.
equals
(
name
,
ship
.
name
)
&&
Objects
.
equals
(
cord1
,
ship
.
cord1
)
&&
Objects
.
equals
(
cord2
,
ship
.
cord2
);
return
Objects
.
equals
(
name
,
ship
.
name
)
&&
Objects
.
equals
(
cord1
,
ship
.
cord1
)
&&
Objects
.
equals
(
cord2
,
ship
.
cord2
);
//retourne
}
@Override
public
String
toString
()
{
public
String
toString
()
{
//methode toString
return
"Ship{"
+
"name='"
+
name
+
'\''
+
", cord1="
+
cord1
+
...
...
@@ -129,5 +129,5 @@ public abstract class Ship implements IShip {
@Override
public
int
hashCode
()
{
return
Objects
.
hash
(
name
,
cord1
,
cord2
);
}
}
//retourne le hashcode
}
src/modele/info1/ships/Submarine.java
View file @
d54b155d
...
...
@@ -9,16 +9,16 @@ import info1.ships.ShipCategory;
* @author lanoix-a
*/
public
class
Submarine
extends
Ship
{
public
class
Submarine
extends
Ship
{
//Class sousmarin, extension de Ship
public
Submarine
(
String
name
,
String
xy
)
throws
BadCoordException
,
CoordsBadShipException
{
super
(
name
,
xy
,
xy
);
throws
BadCoordException
,
CoordsBadShipException
{
//qui peut renvoyer les exceptions
super
(
name
,
xy
,
xy
);
//renvoie son argument a sa classe mère
}
@Override
public
ShipCategory
getCategory
()
{
return
ShipCategory
.
SUBMARINE
;
}
}
//getter de sa categorie
}
Write
Preview
Markdown
is supported
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