Bonjour, Je voudrais récupérer juste une partie de la valeur contenue dans mon variable answer1 et j’y arrive pas, voici mon code: package com.jeu.projetjava.examen; import com.jeu.projetjava.examen.Player; import com.jeu.projetjava.examen.Weapon; import java.util.Scanner;
public class Execution{
public static void main(String[]args)
{
/* Création de variable pour stocker mes données*/
System.out.println("Welcome on Battle Weapon!");
System.out.println("________________________________________________________________________");
/* Initialisation de player*/
Player player1 = new Player("Rintonala",100,50 ,"Sabre");
Player player2 = new Player("Rajao",100,50,"Flèche");
Player player3 = new Player("Raly",100,50,"épée");
Player player4 = new Player("Rakoto",100,50,"Lance pierre");
/* Initialisation of weapon*/
Weapon weapon1 = new Weapon("Sabre",40);
Weapon weapon2 = new Weapon("Flèche",20);
Weapon weapon3 = new Weapon("épée",50);
Weapon weapon4 = new Weapon("Lance pierre",30);
/* Affichage et choix des deux joueurs */
String answer1 = " ";
String answer2 = " ";
//Premier boucle tant que l'utilisateur ne choisit pas une réponse entre A,B,C,D il resaisit la valeur
do
{
System.out.println("Choose first player between A,B,C,D : ");
Scanner ptscan = new Scanner(System.in);
answer1 = ptscan.nextLine().toUpperCase();
if (answer1.equals("A"))
{
//int damage = weapon1.getDamagew() ;
//player1.damage( damage ) ;
answer1 = ("A -" + player1.getName() + "/ Number of life : " + player1.getNb_life() + " / Weapon: " + weapon1.getName() + " / Damage: " + weapon1.getDamagew());
System.out.println(answer1);
break;
}
else if (answer1.equals("B"))
{
answer1 = ("B -" + player2.getName() + "/ Number of life : " + player2.getNb_life() + " / Weapon: " + weapon2.getName() + " / Damage: " + weapon2.getDamagew());
System.out.println(answer1);
break;
} else if (answer1.equals("C"))
{
answer1 = ("C -" + player3.getName() + "/ Number of life : " + player3.getNb_life() + " / Weapon: " + weapon3.getName() + " / Damage: " + weapon3.getDamagew());
System.out.println(answer1);
break;
} else if (answer1.equals("D"))
{
answer1 = ptscan.nextLine();
answer1 = ("D -" + player4.getName() + "/ Number of life : " + player4.getNb_life() + " / Weapon: " + weapon4.getName() + " / Damage: " + weapon4.getDamagew());
System.out.println(answer1);
break;
}
else
{
System.out.println("No player for this letter!");
}
} while (true);
//Deuxième boucle tant que l'utilisateur ne choisit pas une réponse entre A,B,C,D il resaisit la valeur
System.out.println("________________________________________________________________________");
do {
System.out.println("Choose second player between A,B,C,D : ");
Scanner ptscan1 = new Scanner(System.in);
answer2 = ptscan1.nextLine().toUpperCase();
if (answer2.equals("A"))
{
answer2 = ("A -" + player1.getName() + "/ Number of life : " + player1.getNb_life() + " / Weapon: " + weapon1.getName() + " / Damage: " + weapon1.getDamagew());
System.out.println(answer2);
break;
} else if (answer2.equals("B"))
{
answer2 = ("B -" + player2.getName() + "/ Number of life : " + player2.getNb_life() + " / Weapon: " + weapon2.getName() + " / Damage: " + weapon2.getDamagew());
System.out.println(answer2);
break;
} else if (answer2.equals("C"))
{
answer2 = ("C -" + player3.getName() + "/ Number of life : " + player3.getNb_life() + " / Weapon: " + weapon3.getName() + " / Damage: " + weapon3.getDamagew());
System.out.println(answer2);
} else if (answer2.equals("D"))
{
answer2 = ("D -" + player4.getName() + "/ Number of life : " + player4.getNb_life() + " / Weapon: " + weapon4.getName() + " / Damage: " + weapon4.getDamagew());
System.out.println(answer2);
break;
} else
{
System.out.println("No player for this letter!");
}
}while (true);
//Affichage des deux joueurs séléctionnés si valeur=correctes
System.out.println("________________________________________________________________________");
System.out.println(answer1+ "\n*****ATTAQUE******\n" + answer2);
System.out.println("________________________________________________________________________");
}
}
Du coup après affichage de answer1 et 2 je veux juste afficher le nombre de vie restant de answer2 mais je n’arrive pas à récupérer la valeur,;Merci
+0
-0