mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 21:12:04 -08:00
playertype, enum singleton
This commit is contained in:
parent
b19170f34f
commit
211d433ea9
50 changed files with 642 additions and 675 deletions
|
|
@ -27,8 +27,10 @@
|
|||
*/
|
||||
package mage.game;
|
||||
|
||||
import java.io.Serializable;
|
||||
import mage.players.Player;
|
||||
import mage.players.PlayerType;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -37,18 +39,18 @@ import mage.players.Player;
|
|||
public class Seat implements Serializable {
|
||||
|
||||
// private static final Logger logger = Logger.getLogger(Seat.class);
|
||||
private String playerType;
|
||||
private PlayerType playerType;
|
||||
private Player player;
|
||||
|
||||
public Seat(String playerType) {
|
||||
public Seat(PlayerType playerType) {
|
||||
this.playerType = playerType;
|
||||
}
|
||||
|
||||
public String getPlayerType() {
|
||||
public PlayerType getPlayerType() {
|
||||
return playerType;
|
||||
}
|
||||
|
||||
public void setPlayerType(String playerType) {
|
||||
public void setPlayerType(PlayerType playerType) {
|
||||
this.playerType = playerType;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,13 +27,6 @@
|
|||
*/
|
||||
package mage.game;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import mage.cards.decks.DeckValidator;
|
||||
import mage.constants.TableState;
|
||||
import mage.game.events.Listener;
|
||||
|
|
@ -43,9 +36,12 @@ import mage.game.match.Match;
|
|||
import mage.game.result.ResultProtos.TableProto;
|
||||
import mage.game.tournament.Tournament;
|
||||
import mage.players.Player;
|
||||
import mage.players.PlayerType;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class Table implements Serializable {
|
||||
|
|
@ -74,21 +70,21 @@ public class Table implements Serializable {
|
|||
|
||||
protected TableEventSource tableEventSource = new TableEventSource();
|
||||
|
||||
public Table(UUID roomId, String gameType, String name, String controllerName, DeckValidator validator, List<String> playerTypes, TableRecorder recorder, Tournament tournament, Set<String> bannedUsernames) {
|
||||
public Table(UUID roomId, String gameType, String name, String controllerName, DeckValidator validator, List<PlayerType> playerTypes, TableRecorder recorder, Tournament tournament, Set<String> bannedUsernames) {
|
||||
this(roomId, gameType, name, controllerName, validator, playerTypes, recorder, bannedUsernames);
|
||||
this.tournament = tournament;
|
||||
this.isTournament = true;
|
||||
setState(TableState.WAITING);
|
||||
}
|
||||
|
||||
public Table(UUID roomId, String gameType, String name, String controllerName, DeckValidator validator, List<String> playerTypes, TableRecorder recorder, Match match, Set<String> bannedUsernames) {
|
||||
public Table(UUID roomId, String gameType, String name, String controllerName, DeckValidator validator, List<PlayerType> playerTypes, TableRecorder recorder, Match match, Set<String> bannedUsernames) {
|
||||
this(roomId, gameType, name, controllerName, validator, playerTypes, recorder, bannedUsernames);
|
||||
this.match = match;
|
||||
this.isTournament = false;
|
||||
setState(TableState.WAITING);
|
||||
}
|
||||
|
||||
protected Table(UUID roomId, String gameType, String name, String controllerName, DeckValidator validator, List<String> playerTypes, TableRecorder recorder, Set<String> bannedUsernames) {
|
||||
protected Table(UUID roomId, String gameType, String name, String controllerName, DeckValidator validator, List<PlayerType> playerTypes, TableRecorder recorder, Set<String> bannedUsernames) {
|
||||
tableId = UUID.randomUUID();
|
||||
this.roomId = roomId;
|
||||
this.numSeats = playerTypes.size();
|
||||
|
|
@ -102,10 +98,10 @@ public class Table implements Serializable {
|
|||
this.bannedUsernames = new HashSet<>(bannedUsernames);
|
||||
}
|
||||
|
||||
private void createSeats(List<String> playerTypes) {
|
||||
private void createSeats(List<PlayerType> playerTypes) {
|
||||
int i = 0;
|
||||
seats = new Seat[numSeats];
|
||||
for (String playerType : playerTypes) {
|
||||
for (PlayerType playerType : playerTypes) {
|
||||
seats[i] = new Seat(playerType);
|
||||
i++;
|
||||
}
|
||||
|
|
@ -145,7 +141,6 @@ public class Table implements Serializable {
|
|||
/**
|
||||
* All activities of the table end (only replay of games (if active) and
|
||||
* display tournament results)
|
||||
*
|
||||
*/
|
||||
public void closeTable() {
|
||||
if (getState() != TableState.WAITING && getState() != TableState.READY_TO_START) {
|
||||
|
|
@ -156,7 +151,6 @@ public class Table implements Serializable {
|
|||
|
||||
/**
|
||||
* Complete remove of the table, release all objects
|
||||
*
|
||||
*/
|
||||
public void cleanUp() {
|
||||
if (match != null) {
|
||||
|
|
@ -211,9 +205,9 @@ public class Table implements Serializable {
|
|||
return numSeats;
|
||||
}
|
||||
|
||||
public Seat getNextAvailableSeat(String playerType) {
|
||||
public Seat getNextAvailableSeat(PlayerType playerType) {
|
||||
for (int i = 0; i < numSeats; i++) {
|
||||
if (seats[i].getPlayer() == null && seats[i].getPlayerType().equals(playerType)) {
|
||||
if (seats[i].getPlayer() == null && seats[i].getPlayerType() == (playerType)) {
|
||||
return seats[i];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,16 +28,18 @@
|
|||
|
||||
package mage.game.match;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import mage.constants.MatchTimeLimit;
|
||||
import mage.constants.MultiplayerAttackOption;
|
||||
import mage.constants.RangeOfInfluence;
|
||||
import mage.constants.SkillLevel;
|
||||
import mage.game.result.ResultProtos;
|
||||
import mage.players.PlayerType;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -53,7 +55,7 @@ public class MatchOptions implements Serializable {
|
|||
protected String gameType;
|
||||
protected String deckType;
|
||||
protected boolean limited;
|
||||
protected List<String> playerTypes = new ArrayList<>();
|
||||
protected List<PlayerType> playerTypes = new ArrayList<>();
|
||||
protected boolean multiPlayer;
|
||||
protected int numSeats;
|
||||
protected String password;
|
||||
|
|
@ -154,7 +156,7 @@ public class MatchOptions implements Serializable {
|
|||
this.deckType = deckType;
|
||||
}
|
||||
|
||||
public List<String> getPlayerTypes() {
|
||||
public List<PlayerType> getPlayerTypes() {
|
||||
return playerTypes;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,10 +27,6 @@
|
|||
*/
|
||||
package mage.game.tournament;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import mage.cards.ExpansionSet;
|
||||
import mage.cards.decks.Deck;
|
||||
import mage.game.draft.Draft;
|
||||
|
|
@ -39,6 +35,12 @@ import mage.game.events.PlayerQueryEvent;
|
|||
import mage.game.events.TableEvent;
|
||||
import mage.game.result.ResultProtos.TourneyProto;
|
||||
import mage.players.Player;
|
||||
import mage.players.PlayerType;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -48,7 +50,7 @@ public interface Tournament {
|
|||
|
||||
UUID getId();
|
||||
|
||||
void addPlayer(Player player, String playerType);
|
||||
void addPlayer(Player player, PlayerType playerType);
|
||||
|
||||
void removePlayer(UUID playerId);
|
||||
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ import mage.game.match.Match;
|
|||
import mage.game.match.MatchPlayer;
|
||||
import mage.game.result.ResultProtos.*;
|
||||
import mage.players.Player;
|
||||
import mage.players.PlayerType;
|
||||
import mage.util.RandomUtil;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
|
|
@ -82,7 +83,7 @@ public abstract class TournamentImpl implements Tournament {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void addPlayer(Player player, String playerType) {
|
||||
public void addPlayer(Player player, PlayerType playerType) {
|
||||
players.put(player.getId(), new TournamentPlayer(player, playerType));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,10 +27,12 @@
|
|||
*/
|
||||
package mage.game.tournament;
|
||||
|
||||
import mage.game.match.MatchOptions;
|
||||
import mage.players.PlayerType;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import mage.game.match.MatchOptions;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -40,7 +42,7 @@ public class TournamentOptions implements Serializable {
|
|||
|
||||
protected String name;
|
||||
protected String tournamentType;
|
||||
protected List<String> playerTypes = new ArrayList<>();
|
||||
protected List<PlayerType> playerTypes = new ArrayList<>();
|
||||
protected MatchOptions matchOptions;
|
||||
protected LimitedOptions limitedOptions;
|
||||
protected boolean watchingAllowed = true;
|
||||
|
|
@ -65,7 +67,7 @@ public class TournamentOptions implements Serializable {
|
|||
this.tournamentType = tournamentType;
|
||||
}
|
||||
|
||||
public List<String> getPlayerTypes() {
|
||||
public List<PlayerType> getPlayerTypes() {
|
||||
return playerTypes;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,14 +28,16 @@
|
|||
|
||||
package mage.game.tournament;
|
||||
|
||||
import java.util.Set;
|
||||
import mage.cards.decks.Deck;
|
||||
import mage.constants.TournamentPlayerState;
|
||||
import mage.game.result.ResultProtos.TourneyPlayerProto;
|
||||
import mage.game.result.ResultProtos.TourneyQuitStatus;
|
||||
import mage.players.Player;
|
||||
import mage.players.PlayerType;
|
||||
import mage.util.TournamentUtil;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
|
|
@ -43,7 +45,7 @@ import mage.util.TournamentUtil;
|
|||
public class TournamentPlayer {
|
||||
|
||||
protected int points;
|
||||
protected String playerType;
|
||||
protected PlayerType playerType;
|
||||
protected TournamentPlayerState state;
|
||||
protected String stateInfo;
|
||||
protected String disconnectInfo;
|
||||
|
|
@ -57,7 +59,7 @@ public class TournamentPlayer {
|
|||
protected TourneyQuitStatus quitStatus = TourneyQuitStatus.NO_TOURNEY_QUIT;
|
||||
protected TournamentPlayer replacedTournamentPlayer;
|
||||
|
||||
public TournamentPlayer(Player player, String playerType) {
|
||||
public TournamentPlayer(Player player, PlayerType playerType) {
|
||||
this.player = player;
|
||||
this.playerType = playerType;
|
||||
this.state = TournamentPlayerState.JOINED;
|
||||
|
|
@ -70,7 +72,7 @@ public class TournamentPlayer {
|
|||
return player;
|
||||
}
|
||||
|
||||
public String getPlayerType() {
|
||||
public PlayerType getPlayerType() {
|
||||
return playerType;
|
||||
}
|
||||
|
||||
|
|
@ -232,7 +234,7 @@ public class TournamentPlayer {
|
|||
public TourneyPlayerProto toProto() {
|
||||
return TourneyPlayerProto.newBuilder()
|
||||
.setName(this.player.getName())
|
||||
.setPlayerType(this.playerType)
|
||||
.setPlayerType(this.playerType.toString())
|
||||
.setQuit(this.quitStatus)
|
||||
.build();
|
||||
}
|
||||
|
|
|
|||
31
Mage/src/main/java/mage/players/PlayerType.java
Normal file
31
Mage/src/main/java/mage/players/PlayerType.java
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
package mage.players;
|
||||
|
||||
/**
|
||||
* Created by IGOUDT on 2-4-2017.
|
||||
*/
|
||||
public enum PlayerType {
|
||||
HUMAN("Human"),
|
||||
COMPUTER_DRAFT_BOT("Computer - draftbot"),
|
||||
COMPUTER_MINIMAX_HYBRID("Computer - minimax hybrid"),
|
||||
COMPUTER_MAD("Computer - mad");
|
||||
|
||||
String description;
|
||||
|
||||
PlayerType(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public static PlayerType getByDescription(String description) {
|
||||
for (PlayerType type : values()) {
|
||||
if (type.description.equals(description)) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException(String.format("PlayerType (%s) is not configured", description));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue