Commit 55ed19db authored by Aroubate Hamza's avatar Aroubate Hamza
Browse files

Fin TP5

parent abcb11d9
......@@ -35,7 +35,9 @@ public class Porte extends ElementStructurel implements Activable{
super(nom,monde);
this.pieceA = pieceA;
this.pieceB = pieceB;
this.etat = FERME;
this.etat = Etat.FERME;
this.pieceA.addPorte(this);
this.pieceB.addPorte(this);
}
/**
......@@ -61,15 +63,15 @@ public class Porte extends ElementStructurel implements Activable{
* @throws ActivationImpossibleException
*/
public void activer() throws ActivationImpossibleException{
if (etat==CASSE || etat==VERROUILLE)
if (etat==Etat.CASSE || etat==Etat.VERROUILLE)
throw new ActivationImpossibleException();
else
switch (etat){
case FERME:
etat=OUVERT;
etat=Etat.OUVERT;
break;
case OUVERT:
etat=FERME;
etat=Etat.FERME;
break;
}
}
......@@ -81,15 +83,15 @@ public class Porte extends ElementStructurel implements Activable{
* @throws ActivationImpossibleAvecObjetException
*/
public void activerAvec(Objet obj) throws ActivationImpossibleException, ActivationImpossibleAvecObjetException{
if (etat==CASSE || etat==VERROUILLE)
if (etat==Etat.CASSE || etat==Etat.VERROUILLE)
throw new ActivationImpossibleException();
else
switch (etat){
case FERME:
etat=OUVERT;
etat=Etat.OUVERT;
break;
case OUVERT:
etat=FERME;
etat=Etat.FERME;
break;
}
}
......@@ -109,7 +111,10 @@ public class Porte extends ElementStructurel implements Activable{
*/
public String toString(){
StringBuilder str = new StringBuilder();
str.append(String.format(super.toString(),this.pieceA,this.pieceB,this.etat));
str.append(super.toString());
str.append(this.pieceA.toString());
str.append(this.pieceB.toString());
str.append(this.etat.toString());
return str.toString();
}
}
package fr.insarouen.asi.prog.asiaventure.elements.vivants;
import fr.insarouen.asi.prog.asiaventure.Monde;
import fr.insarouen.asi.prog.asiaventure.elements.Entite;
import fr.insarouen.asi.prog.asiaventure.elements.objets.Objet;
import fr.insarouen.asi.prog.asiaventure.elements.structure.Piece;
import fr.insarouen.asi.prog.asiaventure.elements.*;
import fr.insarouen.asi.prog.asiaventure.*;
import fr.insarouen.asi.prog.asiaventure.elements.objets.*;
import fr.insarouen.asi.prog.asiaventure.elements.vivants.*;
......@@ -134,6 +131,10 @@ public abstract class Vivant extends Entite {
return (getPointVie() == 0);
}
public void activerActivable(Activable activable) throws ActivationException{
}
/**
* franchir permet de passer d'une Piece à une autre grâce à une Porte
* @param porte Porte à franchir
......@@ -151,13 +152,12 @@ public abstract class Vivant extends Entite {
* @throws PorteFermeException
* @throws PorteInexistanteDansLaPieceException
*/
public void franchir(String nomPorte) throws PorteFermeException,
PorteInexistanteDansLaPieceException{
public void franchir(String nomPorte) throws PorteFermeException, PorteInexistanteDansLaPieceException{
try{
if (!(piece.aLaPorte(nomPorte)) || piece.getPorte(nomPorte).getPieceAutreCote(piece)==null){
throw new PorteInexistanteDansLaPieceException();
}
if (piece.getPorte(nomPorte).getEtat().equals(FERME)){
if (piece.getPorte(nomPorte).getEtat().equals(Etat.FERME)){
throw new PorteFermeException();
}
piece.sortir(this);
......
......@@ -24,21 +24,21 @@ public class TestPorte {
@Before
public void init() throws Exception {
monde1 = new Monde("monde1");
pieceA1 = new Piece("pieceA1", monde1);
pieceB1 = new Piece("pieceB1", monde1);
pieceA1 = new Piece(monde1,"pieceA1");
pieceB1 = new Piece(monde1,"pieceB1");
porte1 = new Porte("porte1", monde1, pieceA1, pieceB1);
}
@Test
public void test_activer_getEtat() throws ActivationImpossibleException {
assertThat(porte1.getEtat(), equalTo(Etat.FERME));
assertThat(porte1.getEtat(), IsEqual.equalTo(Etat.FERME));
porte1.activer();
assertThat(porte1.getEtat(), equalTo(Etat.OUVERT));
assertThat(porte1.getEtat(), IsEqual.equalTo(Etat.OUVERT));
}
@Test
public void test_getPieceAutreCote() {
assertThat(porte1.getPieceAutreCote(pieceA1), equalTo(pieceB1));
assertThat(porte1.getPieceAutreCote(pieceB1), equalTo(pieceA1));
assertThat(porte1.getPieceAutreCote(pieceA1), IsEqual.equalTo(pieceB1));
assertThat(porte1.getPieceAutreCote(pieceB1), IsEqual.equalTo(pieceA1));
}
}
......@@ -7,16 +7,11 @@ import org.hamcrest.core.IsEqual;
import org.junit.Test;
import java.util.*;
import fr.insarouen.asi.prog.asiaventure.Monde;
import fr.insarouen.asi.prog.asiaventure.NomDEntiteDejaUtiliseDansLeMondeException;
import fr.insarouen.asi.prog.asiaventure.elements.objets.Objet;
import fr.insarouen.asi.prog.asiaventure.elements.objets.ObjetNonDeplacableException;
import fr.insarouen.asi.prog.asiaventure.elements.structure.ObjetAbsentDeLaPieceException;
import fr.insarouen.asi.prog.asiaventure.elements.structure.Piece;
import fr.insarouen.asi.prog.asiaventure.elements.structure.Porte;
import fr.insarouen.asi.prog.asiaventure.elements.structure.PorteFermeException;
import fr.insarouen.asi.prog.asiaventure.elements.structure.PorteInexistanteDansLaPieceException;
import fr.insarouen.asi.prog.asiaventure.elements.ActivationImpossibleException;
import fr.insarouen.asi.prog.asiaventure.*;
import fr.insarouen.asi.prog.asiaventure.elements.objets.*;
import fr.insarouen.asi.prog.asiaventure.elements.structure.*;
import fr.insarouen.asi.prog.asiaventure.elements.*;
import fr.insarouen.asi.prog.asiaventure.elements.vivants.*;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.*;
......@@ -25,6 +20,7 @@ public class TestVivant {
public Monde monde;
public Piece piece;
private Vivant vivant;
private Vivant vivant1;
private PiedDeBiche pieddebiche;
private PiedDeBiche pieddebiche1;
......@@ -46,8 +42,8 @@ public class TestVivant {
public void init() throws Exception{
monde = new Monde("monde");
piece = new Piece(monde, "piece");
pieddebiche = new PiedDeBiche("pieddebiche", monde);
pieddebiche1 = new PiedDeBiche("pieddebiche1", monde);
pieddebiche = new PiedDeBiche("piedebiche", monde);
pieddebiche1 = new PiedDeBiche("pieddebiche1",monde);
vivant = new Vivant("vivant", monde, 10, 10, piece, pieddebiche, pieddebiche1){};
}
......@@ -161,40 +157,42 @@ public class TestVivant {
@Test
public void test_franchir() throws NomDEntiteDejaUtiliseDansLeMondeException, PorteFermeException, PorteInexistanteDansLaPieceException, ActivationImpossibleException {
Piece piece2 = new Piece("piece2", monde1);
Porte porte1 = new Porte("porte1", monde1, piece1, piece2);
Piece piece2 = new Piece(monde, "piece2");
Piece piece1 = new Piece(monde, "piece1");
Porte porte1 = new Porte("porte1", monde, piece1, piece2);
porte1.activer();
vivant1.franchir(porte1);
assertThat(vivant1.getPiece(), equalTo(piece2));
vivant1.franchir("porte1");
assertThat(vivant1.getPiece(), equalTo(piece1));
vivant.franchir(porte1);
assertThat(vivant.getPiece(), IsEqual.equalTo(piece2));
vivant.franchir("porte1");
assertThat(vivant.getPiece(), IsEqual.equalTo(piece1));
}
@Test(expected=PorteFermeException.class)
public void test_franchir_PorteFerme() throws NomDEntiteDejaUtiliseDansLeMondeException, PorteFermeException, PorteInexistanteDansLaPieceException, ActivationImpossibleException {
Piece piece2 = new Piece("piece2", monde1);
Porte porte1 = new Porte("porte1", monde1, piece1, piece2);
vivant1.franchir(porte1);
Piece piece2 = new Piece(monde, "piece2");
Piece piece1 = new Piece(monde, "piece1");
Porte porte1 = new Porte("porte1", monde, piece1, piece2);
vivant.franchir(porte1);
}
@Test(expected=PorteInexistanteDansLaPieceException.class)
public void test_franchir_PorteInexistante() throws NomDEntiteDejaUtiliseDansLeMondeException, PorteFermeException, PorteInexistanteDansLaPieceException, ActivationImpossibleException {
Piece piece2 = new Piece("piece2", monde1);
Piece piece3 = new Piece("piece3", monde1);
Porte porte1 = new Porte("porte1", monde1, piece2, piece3);
Piece piece2 = new Piece(monde,"piece2");
Piece piece3 = new Piece(monde,"piece3");
Porte porte1 = new Porte("porte1", monde, piece2, piece3);
porte1.activer();
vivant1.franchir(porte1);
vivant.franchir(porte1);
}
@Test
public void test_activerActivable() throws NomDEntiteDejaUtiliseDansLeMondeException, PorteFermeException, PorteInexistanteDansLaPieceException, ActivationImpossibleException {
Piece piece2 = new Piece("piece2", monde1);
Piece piece3 = new Piece("piece3", monde1);
Porte porte1 = new Porte("porte1", monde1, piece2, piece3);
Porte porte2 = new Porte("porte2", monde1, piece2, piece3);
Piece piece2 = new Piece(monde,"piece2");
Piece piece3 = new Piece(monde,"piece3");
Porte porte1 = new Porte("porte1", monde, piece2, piece3);
Porte porte2 = new Porte("porte2", monde, piece2, piece3);
porte1.activer();
try{
vivant1.activerActivable(porte1);
vivant.activerActivable(porte1);
}
catch(Exception e) {
System.out.println();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment