List of usage examples for com.google.gwt.user.client Random nextInt
public static native int nextInt(int upperBound) ;
int
between 0 (inclusive) and upperBound
(exclusive) with roughly equal probability of returning any particular int
in this range. From source file:us.asciiroth.client.core.Color.java
License:Apache License
public static Color random() { // Pretty expensive... only used for the win game animation. Collection<Color> values = byName.values(); return (Color) values.toArray()[Random.nextInt(values.size())]; // return Collections.asList(byName.values()); // return byName.values(); }
From source file:us.asciiroth.client.core.Player.java
License:Apache License
public boolean testResistance(int resistance) { if (is(resistance)) { // But, these resistances are never actually tested anywhere... if (is(FIRE_RESISTANT) && bag.getSelected() instanceof RedRing || is(WATER_RESISTANT) && bag.getSelected() instanceof BlueRing) { return true; }/*from w ww . java 2 s . c o m*/ if (Random.nextInt(100) < 15) { remove(resistance); } return true; } return false; }
From source file:us.asciiroth.client.items.Bone.java
License:Apache License
@Override public void onSteppedOn(Event event, Cell agentLoc, Agent agent) { if (agent.is(CARNIVORE)) { if (Random.nextInt(100) < 5) { agentLoc.getBag().remove(this); }/*www . j av a2 s .c om*/ } }
From source file:us.asciiroth.client.items.Fish.java
License:Apache License
@Override public void onSteppedOn(Event event, Cell agentLoc, Agent agent) { if (agent.is(CARNIVORE)) { if (Random.nextInt(100) < 15) { agentLoc.getBag().remove(this); agentLoc.getBag().add((Bone) Registry.get().getPiece(Bone.class)); }//from ww w. j a va 2 s .c o m } }
From source file:us.asciiroth.client.items.Stoneray.java
License:Apache License
@Override public Symbol getSymbol() { return SYMBOLS[Random.nextInt(2)]; }
From source file:us.asciiroth.client.terrain.FishPool.java
License:Apache License
private void catchFish(Event event, Player player, Cell to) { player.getBag().add(fish);/*from w w w .j a v a 2s. c o m*/ Events.get().fireMessage(to, "You caught a fish!"); if ((Random.nextInt(100) < chanceToReplenish)) { turnOff(to); } else { to.setTerrain(terrain); } }
From source file:us.asciiroth.client.terrain.FishPool.java
License:Apache License
/** * When off, the fish pool periodically tests to see if it should go * "on". When on, after a period, it turns off and moves. *//* w w w . ja v a2s . co m*/ public void onFrame(Context ctx, Cell cell, int frame) { if (frame % 8 != 0) { return; } boolean changeState = (state.isOn()) ? (Random.nextInt(100) < chanceToGoOff) : (Random.nextInt(100) < chanceToGoOn); if (!changeState) { return; } if (state.isOn()) { turnOff(cell); } else { turnOn(cell); } }
From source file:us.asciiroth.client.terrain.TerrainUtils.java
License:Apache License
/** * Given a list of directions, choose one at random. * @return a randomly chosen direction taken from the list of directions *//*from www . ja v a2s . c om*/ public static Direction getRandomDirection() { int i = Random.nextInt(Direction.getAdjacentDirections().size()); return (Direction) Direction.getAdjacentDirections().get(i); }
From source file:us.asciiroth.client.terrain.TerrainUtils.java
License:Apache License
/** * Give a list of cells, choose one at random. * @param cells// www.j av a 2 s. com * @return a randomly chosen cell taken from the list of cells */ public static Cell getRandomCell(List<Cell> cells) { return (cells.isEmpty()) ? null : (Cell) cells.get(Random.nextInt(cells.size())); }
From source file:us.asciiroth.editor.client.NameGenerator.java
License:Apache License
public String getName() { return bits[Random.nextInt(bits.length)] + bits[Random.nextInt(bits.length)]; }