Bonjour, je suis débutante en JAVA, j’utilise IntelliJ et je voudrais exécuter un petit programme qui permet à des joueurs de se battre, de générer des vies, de perdre des vie et j’ai commencé ma programmation seulement je suis bloqué quand j’essaie de faire choisir un joueur à l’utilisateur ,normalement le nom du joueur avec ses armes et vies devraient s’afficher seulement ça ne s’affiche pas et ma question c’est comment je pourrais stocker une valeur dans une variable et je pourrais toujours le réafficher plus tard. 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);
Player player2 = new Player("Rajao",100,50);
Player player3 = new Player("Raly",100,50);
Player player4 = new Player("Rakoto",100,50);
/* 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 */
System.out.println("Choose a player between A,B,C,D : ");
/*String A=" ";
String B=" ";
String C=" ";
String D=" ";*/
String answer1 = " ";
String answer2 = " ";
Scanner ptscan = new Scanner(System.in);
answer1 = ptscan.nextLine();
if (answer1 =="A")
{
answer1 = ("A -" + player1.getName() + "/ Number of life : "+ player1.getNb_life() + " / Weapon: " + weapon1.getName() + " / Damage: " + weapon1.getDamagew());
System.out.println (answer1);
}
else if (answer1 == "B") {
answer1 = ("B -" + player2.getName() + "/ Number of life : "+ player2.getNb_life() + " / Weapon: " + weapon2.getName() + " / Damage: " + weapon2.getDamagew());
System.out.println(answer1);
}
else if (answer1 == "C")
{
answer1= ("C -" + player3.getName() + "/ Number of life : "+ player3.getNb_life() + " / Weapon: " + weapon3.getName() + " / Damage: " + weapon3.getDamagew());
System.out.println(answer1);
}
else if (answer1 == "D") {
answer1 = ptscan.nextLine();
answer1 = ("D -" + player4.getName() + "/ Number of life : "+ player4.getNb_life() + " / Weapon: " + weapon4.getName() + " / Damage: " + weapon4.getDamagew());
System.out.println(answer1);
}
}
}
Et dans le terminal, j’ai uniquement : Welcome on Battle Weapon!
Choose a player between A,B,C,D : A
Process finished with exit code 0
+0
-0