Example usage for com.badlogic.gdx.utils Array shuffle

List of usage examples for com.badlogic.gdx.utils Array shuffle

Introduction

In this page you can find the example usage for com.badlogic.gdx.utils Array shuffle.

Prototype

public void shuffle() 

Source Link

Usage

From source file:com.theosirian.ppioo.controllers.PlayerSelectionController.java

License:Open Source License

@Override
protected void createComponents() {
    percentFormatter = NumberFormat.getPercentInstance();
    percentFormatter.setMaximumFractionDigits(0);

    playerPlayerComp = new PlayerComp(Player.firstNameComparator, false);

    rootLayout = new Table();
    rootLayout.setFillParent(true);/*w w  w. j av a 2s  .co  m*/
    rootLayout.setBackground(game.skin.newDrawable("white", Color.DARK_GRAY));

    titleLabel = new Label("Please choose your players and positions:", game.skin, "big.white");
    titleLabel.setAlignment(2); // 2 == center

    randomizePlayersButton = new TextButton("Randomize Players", game.skin);
    randomizePlayersButton.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            game.getSoundController().soundPlay(1);
            Array<Player> copy = game.data.getOwnedPlayers();
            copy.shuffle();
            copy.truncate(game.data.getTeamSize());
            game.data.getTeam().clear();
            game.data.getTeam().addAll(copy);
            invalidate();
        }
    });
    randomizePositionsButton = new TextButton("Randomize Positions", game.skin);
    randomizePositionsButton.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            game.getSoundController().soundPlay(1);
            game.data.getTeam().shuffle();
            invalidate();
        }
    });
    playerSortButton = new TextButton("Sort Players", game.skin);
    playerSortButton.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            game.getSoundController().soundPlay(1);
            Dialog info = new PlayerSortDialog("Sort Players By:", game.skin, false) {
                @Override
                protected void result(Object object) {
                    if (object == null) {
                        return;
                    }
                    playerPlayerComp = (PlayerComp) object;
                    PlayerSelectionController.this.invalidate();
                }
            };
            info.show(game.stage);
            invalidate();
        }
    });
    positionSortButton = new TextButton("Sort Positions", game.skin);
    positionSortButton.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            game.getSoundController().soundPlay(1);
            Dialog info = new PlayerSortDialog("Sort Positions By:", game.skin, false) {
                @Override
                protected void result(Object object) {
                    if (object == null) {
                        return;
                    }
                    positionPlayerComp = (PlayerComp) object;
                    PlayerSelectionController.this.invalidate();
                }
            };
            info.show(game.stage);
            invalidate();
        }
    });
    clearButton = new TextButton("Clear", game.skin);
    clearButton.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            game.getSoundController().soundPlay(1);
            game.data.getTeam().clear();
            invalidate();
        }
    });

    backButton = new TextButton("Return", game.skin, "error");
    backButton.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            game.getSoundController().soundPlay(1);
            game.changeController = MenuController.class;
        }
    });
    helpButton = new TextButton("Help", game.skin);
    helpButton.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            game.getSoundController().soundPlay(1);
            Dialog info = new Dialog("Help!", game.skin);
            info.text(
                    "In this screen you are shown your players in the left and the current team setup in the right.\n"
                            + "To advance you need to select 6 players and their positions, one goalkeeper and five kickers.");
            info.button("Close", false);
            info.key(Input.Keys.ENTER, false);
            info.key(Keys.ESCAPE, false);
            info.show(game.stage);
        }
    });
    proceedButton = new TextButton("Proceed", game.skin, "success");
    proceedButton.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            if (game.data.getTeam().size == game.data.getTeamSize()) {
                game.getSoundController().soundPlay(1);
                game.changeController = GameController.class;
            } else {
                Dialog info = new Dialog("Team not selected!", game.skin);
                info.text("You haven't selected the right amount of players.\nPlease select "
                        + game.data.getTeamSize() + " players.");
                info.button("Close", false);
                info.key(Input.Keys.ENTER, false);
                info.key(Keys.ESCAPE, false);
                info.show(game.stage);
            }
        }
    });

    playersTable = new Table();
    positionsTable = new Table();
    playersPane = new ScrollPane(playersTable, game.skin);
    positionsPane = new ScrollPane(positionsTable, game.skin);
}

From source file:com.vlaaad.dice.game.config.rewards.imp.AbilityReward.java

License:Open Source License

private RewardResult.AddedAbility calcNextReward(UserData userData) {
    //shuffle abilities
    abilities.shuffle();/*from w  ww. j av a2  s . c o m*/
    //sort by least count in dice
    abilities.sort(Ability.countComparator(userData));

    //for every ability:
    final Array<Die> dice = new Array<Die>();
    for (Die die : userData.dice()) {
        if (MapHelper.countPositive(die.inventory) < StoreWindow.INVENTORY_SIZE)
            dice.add(die);
    }
    for (Ability ability : abilities) {
        //shuffle dice
        dice.shuffle();
        //sort dice by suitability for ability: has least abilities of the same type
        dice.sort(Die.abilitiesCountComparator(ability));
        //try to give to die
        for (Die die : dice) {
            if (ability.requirement.isSatisfied(die)) {
                return new RewardResult.AddedAbility(ability, die);
            }
        }
    }
    throw new IllegalStateException("There is no ability any die can use!");
}

From source file:com.vlaaad.dice.game.world.controllers.SpawnController.java

License:Open Source License

@SuppressWarnings("unchecked")
private void autoPlace() {
    if (placed.size > 0) {
        ObjectSet<Creature> tmp = Pools.obtain(ObjectSet.class);
        tmp.addAll(placed);/*  ww w . jav  a 2s .c om*/
        for (Creature c : tmp) {
            removeFromPlaced(c);
        }
        tmp.clear();
        Pools.free(tmp);
    }
    Array<Grid2D.Coordinate> coordinates = Pools.obtain(Array.class);
    Set<Map.Entry<Grid2D.Coordinate, Fraction>> spawns = world.level.getElements(LevelElementType.spawn);
    for (Map.Entry<Grid2D.Coordinate, Fraction> e : spawns) {
        if (e.getValue() == world.viewer.fraction) {
            coordinates.add(e.getKey());
        }
    }
    coordinates.shuffle();
    int usedCount = Math.min(creatures.size, coordinates.size);
    Array<Creature> toPlace = Pools.obtain(Array.class);
    toPlace.addAll(creatures);
    toPlace.shuffle();
    toPlace.truncate(usedCount);
    for (Creature creature : toPlace) {
        Grid2D.Coordinate coordinate = coordinates.pop();
        place(creature, coordinate.x(), coordinate.y());
    }
    toPlace.clear();
    coordinates.clear();
    Pools.free(toPlace);
    Pools.free(coordinates);
}

From source file:com.vlaaad.dice.game.world.view.AbilitiesSubView.java

License:Open Source License

public AbilitiesSubView(String main, Array<String> frames) {
    this.frames = frames;

    Array<TextureRegion> regions = new Array<TextureRegion>();
    for (String frame : frames) {
        regions.add(Config.skin.getRegion("ability/" + frame));
    }/*  w w w.ja va 2s  .c  o  m*/

    idleDrawable = new TextureRegionDrawable(Config.skin.getRegion("ability/" + main));
    regions.shuffle();
    animationDrawable = new AnimationDrawable(regions);
    image.setSize(ViewController.CELL_SIZE, ViewController.CELL_SIZE);
}

From source file:com.vlaaad.dice.pvp.ServerMessageListener.java

License:Open Source License

private void initMatch(PvpPlayState state) {
    Logger.debug("server: init match " + this.state.session.getMode().name);
    PvpMode mode = this.state.session.getMode();
    LevelDescription level = mode.levels.random();
    String levelName = level.name;
    Array<Fraction> fractions = new Array<Fraction>(level.fractions.size);
    for (Fraction fraction : level.fractions) {
        fractions.add(fraction);// w w  w.  jav  a 2 s .  com
    }
    Array<String> ids = this.state.session.getAll().keys().toArray();
    ids.shuffle();
    ObjectMap<String, String> fMap = new ObjectMap<String, String>();
    for (int i = 0; i < ids.size; i++) {
        fMap.put(ids.get(i), fractions.get(i).name);
    }
    int seed = MathUtils.random.nextInt();
    awaitSpawning(state);
    sendToAll(new Init(levelName, fMap, seed));
}