Package mage.game.tournament

Examples of mage.game.tournament.Tournament


    private TournamentFactory() {}

    public Tournament createTournament(String tournamentType, TournamentOptions options) {

        Tournament tournament;
        Constructor<Tournament> con;
        try {
            con = tournaments.get(tournamentType).getConstructor(new Class[]{TournamentOptions.class});
            tournament = con.newInstance(new Object[] {options});
            // transfer set information, create short info string for included sets
            tournament.setTournamentType(tournamentTypes.get(tournamentType));
            if (tournament.getTournamentType().isLimited()) {
                Map<String,Integer> setInfo = new LinkedHashMap<>();
                for (String setCode: options.getLimitedOptions().getSetCodes()) {
                    tournament.getSets().add(Sets.findSet(setCode));
                    int count = setInfo.containsKey(setCode) ? setInfo.get(setCode) : 0;
                    setInfo.put(setCode, count + 1);
                }
                tournament.getOptions().getLimitedOptions().setNumberBoosters(tournament.getTournamentType().getNumBoosters());
                if (tournament.getTournamentType().isCubeBooster()) {
                    tournament.getOptions().getLimitedOptions().setDraftCube(CubeFactory.getInstance().createDraftCube(tournament.getOptions().getLimitedOptions().getDraftCubeName()));
                    tournament.setBoosterInfo(tournament.getOptions().getLimitedOptions().getDraftCubeName());
                } else {
                    StringBuilder sb = new StringBuilder();
                    for (Map.Entry<String,Integer> entry:setInfo.entrySet()) {
                        sb.append(entry.getValue().toString()).append("x").append(entry.getKey()).append(" ");
                    }
                    tournament.setBoosterInfo(sb.toString());
                }
            } else {
                tournament.setBoosterInfo("");
            }

        } catch (Exception ex) {
            logger.fatal("TournamentFactory error ", ex);
            return null;
        }
        logger.debug("Tournament created: " + tournamentType + " " + tournament.getId());

        return tournament;
    }
View Full Code Here

TOP

Related Classes of mage.game.tournament.Tournament

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.