I have a counter that I use for an array that goes up by one(until it hits seven then it restarts) and keeps track of it but the problem is that it goes in order I want it to be random and then once it has been used that it won't be reused until it restarts(I have it hardcoded so that when it hit the end) is there anybody who can help me?
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class soundButton here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class soundButton extends Actor
{
private String[] animalSounds =
{"dog3.mp3", "lion.wav", "pig.wav", "platypus.wav", "cow.wav", "cat2.mp3", "Lion#2.mp3"};
public static int count = 0;
private String sound;
/**
* Act - do whatever the soundButton wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
if (Greenfoot.mouseClicked(this)){
play();
}
}
public soundButton(){
GreenfootImage image=getImage();
image.scale(image.getWidth()-1925, image.getHeight()-1925);
setImage(image);
}
public void play(){
if (count == 7){
count = 0;
}
Greenfoot.playSound(animalSounds[count]);
count = count + 1;
}
}
