Hi there! So I'm making Rock, Paper & Scissors on Greenfoot. So I have 3 actors:Rock, paper and scissors.I'm on the part where the player has to click on an actor when...... 'How can I code the program to generate one of the actor's randomly (as it's the Computer playing) and to show it on MyWorld'?
So far below is the coding I'm using at the moment on My world. As you can tell, I already set up 3 actors in place. I want the program to choose a random actor after the user has clicked any of the 3 actors shown on the screen. After they click on an actor, one random actor out of the three should be shown above them (to show what the player has chosen)-hence the switch case. I know I have loads of mistakes below and was hoping if anyone could help me out?
public class MyWorld extends greenfoot.World
{
public MyWorld()
{
super(650, 500,1);
prepare();
}
private void prepare()
{
Paper paper=new Paper();
addObject(paper, 200,400);
paper.setLocation(150,350);
Rock rock=new Rock();
addObject(rock, 250,400);
rock.setLocation(325,350);
Scissors scissors=new Scissors();
addObject(scissors, 200,400);
scissors.setLocation(500,350);
}
private Actor getRandomActor()
{
if (Greenfoot.mouseClicked(this))
switch (Greenfoot.getRandomNumber(3))
{
case 0: Rock rock=new Rock();
addObject(rock, 250,400);
rock.setLocation(325,100);//return new Rock();
case 1: Paper paper=new Paper();
addObject(paper, 200,400);
paper.setLocation(325,100);
case 2: Scissors scissors=new Scissors();
addObject(scissors, 200,400);
scissors.setLocation(325,100);
}
return null;
}
}