state: Added addPlayer function

This commit is contained in:
Nathan Woodburn 2023-04-24 21:33:05 +10:00
parent 8bab67bcba
commit 10b23e8a8c
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1

View File

@ -13,6 +13,12 @@ import java.util.Random;
*/
public class State {
// region Constants
// Constants for the game. Changing these could create errors
final int maxPlayers = 4;
// endregion
// region Variables
final int boardHeight;
private int numPlayers;
@ -138,6 +144,19 @@ public class State {
}
}
public void addPlayer(){
if (numPlayers >= maxPlayers) return; // There are already the maximum number of players
Player[] oldPlayers = players;
players = new Player[numPlayers+1];
for (int i=0; i<numPlayers; i++)
{
players[i] = oldPlayers[i];
}
players[numPlayers] = new Player(numPlayers);
numPlayers++;
}
public void distributeResources() {
if (stonesCoords.length != 32) return; // There are not enough stones to distribute resources