I am making a roulette game, I have created a Arraylist for the slots, they have been defined in a ordered list, there are 38 slots with positions (0-37), a color and number.
In "Spin method" I am trying to select a random starting slot from the wheel collection/list, then spin through some slots based on delay functionality.
How would I select a random slot from my collection to start this process?
My collection
List<Slot> wheel = new ArrayList<Slot>();
GameEngine gameEngine;
public GameEngineImpl() {
Color colorArray[] = new Color[] { Color.GREEN00, Color.RED, Color.BLACK, Color.RED, Color.BLACK, Color.RED,
Color.BLACK, Color.RED, Color.BLACK, Color.RED, Color.BLACK, Color.RED, Color.BLACK, Color.RED,
Color.BLACK, Color.RED, Color.BLACK, Color.RED, Color.BLACK, Color.GREEN0, Color.BLACK, Color.RED,
Color.BLACK, Color.RED, Color.BLACK, Color.RED, Color.BLACK, Color.RED, Color.BLACK, Color.RED,
Color.BLACK, Color.RED, Color.BLACK, Color.RED, Color.BLACK, Color.RED, Color.BLACK, Color.RED };
int numberArray[] = new int[] { 00, 27, 10, 25, 29, 12, 8, 19, 31, 18, 6, 21, 33, 16, 4, 23, 35, 14, 2, 0, 28,
9, 26, 30, 11, 7, 20, 32, 17, 5, 22, 34, 15, 3, 24, 36, 13, 1 };
for (int position = 0; position < 38; position++) {
wheel.add(new SlotImpl(position, colorArray[position], numberArray[position]));
}
}
Spin method
@Override
public void spin(int initialDelay, int finalDelay, int delayIncrement) {
Slot slot;
while (initialDelay < finalDelay) {
// TODO selecting a random starting slot on the wheel
}
}
// Delay function
delay(delayIncrement);
// Increase increment
initialDelay += delayIncrement;
}
}
// Method to delay spinning
private void delay(int delay) {
try {
Thread.sleep(delay);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}