public class VueShadock {

    private Piece[] listePiece;
    private Donjon donjon;
    private boolean isAvance; // true si la derniere direction est avance() / false si derniere direction est recule()

    public VueShadock(Donjon donjon, int porteeVision) {
        this.donjon = donjon;
        this.listePiece = new PieceConcrete[porteeVision];
        int i, taille=this.listePiece.length;
        for (i=0; i<taille; i++){
            this.listePiece[i] = this.donjon.apres();
        }
        this.isAvance = true;
    }

    public void avance(){
        int i, taille=(this.listePiece.length-1);
        if (this.isAvance){
            for (i=0; i<taille; i++){
                this.listePiece[i] = this.listePiece[i+1];
            }
            this.listePiece[taille] = this.donjon.apres();
        }
        else{
            for (i=0; i<=taille; i++){
                this.listePiece[i] = this.donjon.apres();
            }
        }
        this.isAvance =true;
    }

    public void recule(){
        int i, taille=(this.listePiece.length-1); 
        if (this.isAvance == false){
            for (i=taille; i>0; i--){
                this.listePiece[i] = this.listePiece[i-1];
            }
            this.listePiece[0] = this.donjon.avant();
        }
        else{
            for (i=taille; i>=0; i--){
                this.listePiece[i] = this.donjon.avant();
            }
        }
        this.isAvance = false;
    }

    @Override
    public String toString() {
        String resultat = new String();
        for (Piece piece : this.listePiece){
            resultat += piece+" ";
        }
        return resultat;
    }
}