I'm trying to create a basic "addPlayer" method for a game. The method should add a "Player" to the array of players.
Current code:
@Override
public void addNewPlayer(String name) {
Player one = new Player(name);
players.add(one);
}
The problem I have is that this can only create one Player, as the creation of the second will cause the second player to be associated with the name "one".
Ideally I'd like to make the name of the Player object dependant on the parameter "name" passed in. Is this possible?
I'm using Player objects to have a name and int final identification for the game. Maybe I need to rethink that design?
Playervariable doesn't matter, you should just call thatplayer. Everytime you need to add a new player, you invokeaddNewPlayer. So the caller is the one that'll be doing the multiple calls to this method.