Skip to content

Commit

Permalink
Merge pull request #1 from iquelli/distribute-players-per-team
Browse files Browse the repository at this point in the history
Implement distributePlayersPerTeam function
  • Loading branch information
TiagoFar78 authored Mar 14, 2024
2 parents b9962d6 + 4b53c55 commit 7906869
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.tiagofar78.prisonescape.game;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.bukkit.Bukkit;
Expand All @@ -11,6 +12,7 @@
import net.tiagofar78.prisonescape.game.phases.Phase;
import net.tiagofar78.prisonescape.game.phases.Waiting;
import net.tiagofar78.prisonescape.game.prisonbuilding.PrisonBuilding;
import net.tiagofar78.prisonescape.managers.ConfigManager;

public class PrisonEscapeGame {

Expand Down Expand Up @@ -103,29 +105,42 @@ private boolean isPlayerOnGame(String playerName) {
return false;
}

private void distributePlayersPerTeams() {
int preferPrisioner = 0;
int preferPolice = 0;
int noPreference = 0;

for (int i = 0; i < _players.size(); i++) {
TeamPreference preference = _players.get(i).getPreference();
if (preference == TeamPreference.POLICE) {
preferPolice++;
}
else if (preference == TeamPreference.PRISIONERS) {
preferPrisioner++;
}
else if (preference == TeamPreference.RANDOM) {
noPreference++;
private void distributePlayersPerTeam() {
int numberOfPlayers = _players.size();
int requiredPrisioners = (int) Math.round(
numberOfPlayers * ConfigManager.getInstance().getPrisionerRatio()
);
int requiredOfficers = (int) Math.round(
numberOfPlayers * ConfigManager.getInstance().getOfficerRatio()
);

Collections.shuffle(_players);
List<PrisonEscapePlayer> remainingPlayers = new ArrayList<>();

for (PrisonEscapePlayer player : _players) {
TeamPreference preference = player.getPreference();

if (preference == TeamPreference.POLICE && requiredOfficers != 0) {
_policeTeam.addMember(player);
requiredOfficers--;
} else if (preference == TeamPreference.PRISIONERS && requiredPrisioners != 0) {
_prisionersTeam.addMember(player);
requiredPrisioners--;
} else {
remainingPlayers.add(player);
}
}

if (preferPrisioner <= _settings.getMaxPrisioners()) {
//TODO finish this method

for (PrisonEscapePlayer player : remainingPlayers) {

if (requiredPrisioners != 0) {
_prisionersTeam.addMember(player);
requiredPrisioners--;
} else {
_policeTeam.addMember(player);
requiredOfficers--;
}
}


}

// ########################################
Expand All @@ -137,7 +152,7 @@ private void startWaitingPhase() {
}

private void startOngoingPhase() {
distributePlayersPerTeams();
distributePlayersPerTeam();

_phase.next();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ public PrisonEscapeTeam(String name) {
public String getName() {
return _name;
}

public void addMember(PrisonEscapePlayer player) {
_players.add(player);
}

public boolean isOnTeam(PrisonEscapePlayer player) {
return _players.contains(player);
Expand Down
10 changes: 1 addition & 9 deletions src/main/java/net/tiagofar78/prisonescape/game/Settings.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
package net.tiagofar78.prisonescape.game;

public class Settings {

public Settings() {

}

public int getMaxPrisioners() {
return 0; // TODO
}

public int getMaxPoliceOfficers() {
return 0; // TODO
}

public int getSecondsInSolitary() {
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
package net.tiagofar78.prisonescape.managers;

public class ConfigManager {

private static ConfigManager instance = new ConfigManager();

public static ConfigManager getInstance() {
return instance;
}

public String getContainerName() {
return null;
}

public Double getPrisionerRatio() {
return 0.0; // TODO
}

public Double getOfficerRatio() {
return 0.0; // TODO
}
}

0 comments on commit 7906869

Please sign in to comment.