Greetings. It's been quite a while, everyone.
I've been doing a lot of code lately and have been modifying a lot of examples I'm getting my hands on. Right now, I'm trying to modify the Guessing Game by introducing players with unique names. Basically, what I did before was create multiple classes that have unique names instead of just using a single Player(). However, when I discovered arrays, I'm thinking of bringing the Player() class back instead.
The caveat, of course, is that I won't have unique names for each player. A rough idea of what I want would go like this:
Code:
blahblahblah
Player[] pl = new Player[3]; // creates 3 players, if I understand array correctly
blahblahblah
Player[x].name = { pool of names here }
blahblahblah
Jome has entered the game!
George has entered the game!
Undead has entered the game!
Now, the problems I'm seeing with this are:
1. I can create a random pool of names and use Math.random to locate a random name and use it for a player's name. However, I want to make sure that a name doesn't get picked twice. How can I do this?
2. The other problem is a bit simple but I have to make sure: if ever I pin problem (1) down, I still have to figure out a way to keep the names consistent even throughout multiple guesses. This is important because if no player gets to guess correctly, the while() block has to run again, right? So should I just put the random name code outside of the loop so that it isn't ran again?
Thanks to anyone and everyone who can help.