I'm trying to make a Monopoly (board game) system, which first asks how many are playing the game, and then asks what their names are. I'm having trouble making it so each time the showInputDialog
is run, it changes which player
it is setting the name to.
The program will do more eventually, like manage transactions and keep track of how much money each player has. But that's a bit further down the line.
I have just started learning Java in school and I'm doing this as personal project, so keep in mind I'm not very familiar with the language.
Does anyone have any suggestions? Thanks in advance.
Here is my code so far:
import static java.lang.System.*;
import static javax.swing.JOptionPane.*;
import static java.lang.Integer.*;
import static java.lang.Double.*;
import static java.lang.Math.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
public class Template {
public static void main(String[] args){
int nr=1;
int MoneyBank = 20580;
int players = 0;
players = parseInt (showInputDialog(null,"How many are playing?"));
do{
String Name = showInputDialog(null,"Who is player nr." + nr +"?");
String player = Name;
nr++;
}
while (nr <= players);
}
}
Create an array.
String playersArray[] = new String[players];
Then each iteration, load the name into the array
playersArray[nr] = Name;
Once your loop finishes, you'll have an array of player names index in order of their entry.