I'm trying to add a play card to a list of cards for the players (player 0 and player 1). I tried to be generic and to implement the code that will be easy to change for a game of n players. But, I'm confused with the syntax, adding a new card for a specific player isn't work... Please help:
public class GameThread extends Thread{
private Socket socket = null;
private Socket[] connections = new Socket[2];
private List<List<Card>> player = new ArrayList<List<Card>>();
CardPack cardPack = new CardPack(); //creating a new card pack
public GameThread(int sessionID, Socket s) {
socket = s;
// Initial card for two players
for (int i = 0; i < 2; i++){
player.add(0, this.cardPack.getRandomCard());
player.add(1, this.cardPack.getRandomCard());
}
}
PS. This is a specific problem with a specific answer. Thanks Sotirios Delimanolis, Tunaki for your help of signing my question as a duplicate to question of somebody who transfers tables from SQL to ArrayLists, but why to change the reputation?
Real T H A N K S for InfernalRapture
> you can't just add objects to a list
– Adam Jun 29 '16 at 15:16like that. You need to do `player[index].add(new Card())` format. Or define `List person1`, `List person2` and add them from there