Bonjour à tous, je développe un programme en java.
J'utilise 2 fonctions. La fonction combat :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
 public String combat(Fighter f1, Fighter f2)
est appelée par la fonction combatRoom
Code : Sélectionner tout - Visualiser dans une fenêtre à part
public String combatRoom (){
.

La fonction combat est censée rendre une chaine de caractère à la fonction combatRoom. Je peux afficher sur le terminal, la chaine rendue par la fonction combat. En revanche, dans la fonction combatRoom qui appelle combat, la chaine de caractère rendue par combat est vide...

Je ne comprends pas mon erreur....
voici les codes des 2 fonctions :
-fonction combat :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
    public String combat(Fighter f1, Fighter f2){
    	String txt=new String("");
    	Random rdm = new Random ();
    	int puissance=0;
    	//int score=0;
    	Float percent;
    	Attack at = new Attack();
 
 
    	while(f1.getHp()>0 && f2.getHp()>0)
    	{
    		at=f1.attack();
    		txt+=f1.getName() + "  attacks : \n";
    		txt+=at.getName() +" "+at.getDescription() +" "+at.getForce()  ;
    		puissance= (f1.getEp()/10) * random.Hazard.aleat_borne(at.getMin(),at.getMax(),rdm)* at.getForce() ;
 
    		percent=(float)puissance / ((f1.getEp()/10) *at.getMax()*at.getForce())  ;
    		percent*=100;
    		txt+="Force attack : " + puissance + " (efficency : " + percent+"%) \n";
 
        	//score=f1.attack();
        	f2.setHp(f2.getHp()-puissance);
        	f2.showPoints();
        	if (f2.isDie()) {
        		//System.out.println(f1.getName() + " wins");System.out.println("");
        		txt+=f1.getName() + " wins";
        	}
 
        	if (f2.getHp()>0){
        		txt+=f2.getName() + "  attacks : \n";
        		txt+=at.getName() +" "+at.getDescription() +" "+at.getForce()  ;
        		puissance= (f2.getEp()/10) * random.Hazard.aleat_borne(at.getMin(),at.getMax(),rdm)* at.getForce() ;
        		f1.setHp(f1.getHp()- puissance);
        		f1.showPoints(); 
            	if (f1.isDie()) {
            		//System.out.println(f2.getName() + " wins");System.out.println("");
            		txt+=f2.getName() + " wins";
            	}
        	}
    	}
		//f1.showPoints();
		//f2.showPoints();
    	System.out.println(txt);
		return (txt);
    }

combatRoom :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
    /**
     * Gere le combat general dans une piece
     *
     */
    public String combatRoom (){
        int i=0;// indice hero
        int j=0;//indice guard
        int k=0;//indice boss
        String chaine = new String ();
        /*
         * the following variables are token. The fighter list which has the token starts the fight
         */
        boolean token_h=true;boolean token_g=false; boolean token_b=false;
 
        int exp=0; //if you win, your exp point increase of 33 and 10% of your opponent
        Random rdm = new Random (); 
 
        //System.out.println("The fight starts.");
        chaine+="The fight starts.\n";
 
        while(!getHero_col().isEmpty()&&!getGuard_col().isEmpty() &&
        		i<=getHero_col().size()-1 && j <=getGuard_col().size()-1 ) { //combat avec les guards
 
        	//System.out.println("--------------------------");
        	//System.out.println("let's fight with the guard !");System.out.println(i+"  "+j+"  "+k+"   ");
        	//System.out.println("--------------------------");
 
        	chaine+="--------------------------\n";
        	chaine+="let's fight with the guard !\n";
        	chaine+="--------------------------\n";
 
 
        	if(token_h && !token_g && !token_b) //hero has the token
        		{//hero starts
        		chaine+=combat(getHero_col().get(i), getGuard_col().get(j));
        		System.out.println(combat(getHero_col().get(i), getGuard_col().get(j)));
        		} 
 
        	if(!(token_h) &&!(token_b) && token_g) //guard has the token 
        		{chaine+=combat(getGuard_col().get(j), getHero_col().get(i));} //guard starts
 
    	    if(getHero_col().get(i).getHp()<=0) { //the hero is die
    	    	i++;
    	    	token_h=true;
    	    	token_b=false;
    	    	token_g=false;
 
    	    }
    	    if(getGuard_col().get(j).getHp()<=0) { //the gaurd is die
    	    	exp=getGuard_col().get(j).getEp()/random.Hazard.aleat_borne(3,10,rdm);//calculate the exp
    	    	getHero_col().get(i).setEp( getHero_col().get(i).getEp()+exp );//set the hero exp points
    	    	//System.out.println(getHero_col().get(i).getName() +" experience points increase : + "+ exp );
    	    	chaine+=getHero_col().get(i).getName() +" experience points increase : + "+ exp +"\n";
    	    	j++;
    	    	token_g=true;
    	    	token_h=false; 
    	    	token_b=false; 
 
    	    	if(j==getGuard_col().size()){ //if the last guard has been killed, go to the boss
        	    	token_h=false;
        	    	token_b=true;
        	    	token_g=false;
    	    	}
 
    	    }
        }
 
 
        while(!getBoss_col().isEmpty() &&!getHero_col().isEmpty() 
        		&& i<=getHero_col().size()-1 && k <=getBoss_col().size()-1 ) {    //combat boss
        	//System.out.println("--------------------------");
        	//System.out.println("let's fight with the boss !");
        	//System.out.println("--------------------------");
 
        	chaine+="--------------------------\n";
        	chaine+="let's fight with the boss !\n";
        	chaine+="--------------------------\n";
 
 
        	if(token_h && !token_b && !token_g) //hero has the token
        		{chaine+=combat(getHero_col().get(i), getBoss_col().get(k));}
        	if(token_b) //boss has the token
        		{chaine+=combat(getBoss_col().get(k), getHero_col().get(i));}
 
    	    if(getHero_col().get(i).getHp()<=0) {//hero died
    	    	i++;
    	    	token_h=true;
    	    	token_b=false;
    	    	token_g=false;
 
    	    }
    	    if(getBoss_col().get(k).getHp()<=0) {//boss died
    	    	exp=getBoss_col().get(k).getEp()/random.Hazard.aleat_borne(3,10,rdm);	;//calculate the exp
    	    	getHero_col().get(i).setEp( getHero_col().get(i).getEp()+exp );//set the hero exp points
    	    	chaine+=getHero_col().get(i).getName() +" experience points increase : + "+ exp +"\n";
 
    	    	//System.out.println(getHero_col().get(i).getName() +" experience points increase : + "+ exp );
    	    	k++;
    	    	token_h=false;
    	    	token_b=true;
    	    	token_g=false;
    	    }
        }
        //System.out.println("The fight is over.");
        chaine+="The fight is over.";
        return(chaine);
    }
merci d'avance.
cordialement
Benilto