0

I am a beginner and java and making a ludo board. I am making a Drop Down MenuJOptionPane where Player # 1 picks what color he wants to be (green, yellow, blue, red). When it comes to Player # 2 I want him to be able to choose all the colors except for what Player # 1 chose.

Here is my code so far (probably crappy but I am programming for the first time):

String player1;    

String[] numberOfPlayers = {"two", "three", "four"};

String inputNumberOfPlayers = (String) JOptionPane.showInputDialog(null, "How many people are playing?", "Number of Players", JOptionPane.QUESTION_MESSAGE, null, numberOfPlayers, numberOfPlayers[0]);

if(inputNumberOfPlayers.equals("two")) {

    String[] player1Color = {"green", "yellow", "blue", "red"};
    String inputColorChoices1 = (String) JOptionPane.showInputDialog(null, "What color what you like to be", "Message to Player 1", JOptionPane.QUESTION_MESSAGE, null, player1Color, player1Color[0]);

    player1 = inputColorChoices1; 

    String[] player2Color = {"green", "yellow", "blue", "red"}; 

    //and then I don't know... 

Could anybody please help me or tell me where I can find the right answer?

tenorsax
  • 21,123
  • 9
  • 60
  • 107
user2399525
  • 91
  • 1
  • 1
  • 7

1 Answers1

1

You can use a list of available colors. Then after user selects a color, remove it from the available list. For example:

List<String> availableColors = new ArrayList<String>(Arrays.asList(
        "green", "yellow", "blue", "red"));

String player1Color = (String) JOptionPane.showInputDialog(
        null, "What color what you like to be",
        "Message to Player 1", JOptionPane.QUESTION_MESSAGE, null,
        availableColors.toArray(), availableColors.get(0));

availableColors.remove(player1Color);

String player2Color = (String) JOptionPane.showInputDialog(
        null, "What color what you like to be",
        "Message to Player 2", JOptionPane.QUESTION_MESSAGE, null,
        availableColors.toArray(), availableColors.get(0));
tenorsax
  • 21,123
  • 9
  • 60
  • 107