Example usage for com.badlogic.gdx.utils ArrayMap containsKey

List of usage examples for com.badlogic.gdx.utils ArrayMap containsKey

Introduction

In this page you can find the example usage for com.badlogic.gdx.utils ArrayMap containsKey.

Prototype

public boolean containsKey(K key) 

Source Link

Usage

From source file:com.algodal.gdxscreen.GdxGame.java

License:Apache License

private <T extends GdxScreen> void registerScreen(ArrayMap<String, GdxScreen> map, String name, String ref,
        Class<T> clazz) {//from   w  w w. ja  va2 s  .c  om
    debug.assertEqual("method is called in initialize", currentState, State.Initializing);
    debug.assertNotNull(name + " ref is not null", ref);
    debug.assertNotNull(name + " class is not null", clazz);
    debug.assertStringNotEmpty(name + " ref is not empty", (ref = ref.trim())); //The trimmed down version of the string is used
    debug.assertContructorEmpty(name + " class has a empty constructor", clazz);

    //generate screen object
    T screen = debug.assertNoException("no allocation excepton", new Operation<T>() {
        @Override
        public T resultOf() throws Exception {
            return clazz.newInstance();
        }
    });
    screen.setGame(this); //This is a must.  Every screen must know their game.

    debug.assertNotNull(name + " is not null", screen);
    debug.assertFalse(name + " ref is unique", map.containsKey(ref)); //unique reference
    debug.assertFalse(name + " object is unique", map.containsValue(screen, false)); //unique screen: see GdxScreen equals(ObjectS) method

    //add new reference
    map.put(ref, screen);
}

From source file:com.algodal.gdxscreen.GdxGame.java

License:Apache License

private void attachAssetToScreen(ArrayMap<String, GdxScreen> map, String name, String screenRef,
        String assetRef) {/*from w w  w.j  a v a2  s.  co m*/
    debug.assertEqual("method is called in initialize", currentState, State.Initializing);
    debug.assertNotNull(name + " ref is not null", screenRef);
    debug.assertNotNull("asset ref is not null", assetRef);
    debug.assertStringNotEmpty(name + "ref is not empty", (screenRef = screenRef.trim()));
    debug.assertStringNotEmpty("asset ref is not empty", (assetRef = assetRef.trim()));
    debug.assertTrue(name + " ref exists", map.containsKey(screenRef));
    debug.assertTrue("asset ref exists", assetMap.containsKey(assetRef));

    //get objects
    GdxScreen screen = map.get(screenRef);

    debug.assertFalse(name + " ref gets new asset ref", screen.assetRefs.contains(assetRef, false));

    //attachment
    screen.assetRefs.add(assetRef);
}

From source file:org.darkhood.games.texasholdem.core.Table.java

License:Open Source License

public void contribute(Player contributor, int chips) {
    int remainingChips = 0;

    if (contributor.chips <= chips) {
        // All-In, baby
        remainingChips = contributor.chips;
    } else {//www.  j  a v a  2 s .c  om
        remainingChips = chips;
    }

    Pot pot = null;

    while (remainingChips > 0) {
        if (pot == null) {
            pot = pots.first();
        } else {
            pot = getNextPotAfter(pot);
        }

        ArrayMap<Player, Integer> potContributions = pot.getContributions();

        int contributorSum = 0;
        if (potContributions.containsKey(contributor)) {
            contributorSum = potContributions.get(contributor);
        }

        int potCap = pot.getCap();
        // If there is a cap in this pot, contribute the difference to the pot
        if (potCap > 0) {
            if (contributorSum < potCap) {
                int potSumLeft = potCap - contributorSum;
                remainingChips -= potSumLeft;
                contributor.chips -= potSumLeft;
                pot.addChips(contributor, potSumLeft);
            } else {
                // This pot is full, move to the next one
                continue;
            }
        } else {
            // This pot is unlimited, we are free to contribute the remaining chips               
            // However, it's essential that we check other players' contributions
            // It may happen that we need to create another pot if someone has 
            // already contributed more than current player has.
            int contributorFutureSum = contributorSum + remainingChips;

            Pot newSidePot = getNextPotAfter(pot);

            boolean potGetsCapped = false;
            // The sums in the current pot get equalized if there are values
            // higher than contributed chips. 
            // The difference will be transfered to the new pot
            for (Player player : game.players) {
                if (player != contributor && potContributions.containsKey(player)) {
                    int otherPlayerContributedSum = potContributions.get(player);
                    if (otherPlayerContributedSum > contributorFutureSum) {
                        potGetsCapped = true;
                        int difference = otherPlayerContributedSum - contributorFutureSum;
                        pot.removeChips(player, difference);
                        newSidePot.addChips(player, difference);
                    }
                }
            }
            if (potGetsCapped) {
                pot.setCap(contributorFutureSum);
            }
            pot.addChips(contributor, remainingChips);
            contributor.chips -= remainingChips;
        }
    }

}