Hi,need a little help here
i want to create enemies that pop out 5 random questions out of 6 and can't be taken twice
while the enemies number and position is fix in the world class
i already use random number method but still can be taken twice
how do i do this? any help would be appreciated
this is my world class
this is my ProEnemy class
addObject(new ProEnemy(1), 350, 510); addObject(new ProEnemy(2), 780, 510); addObject(new ProEnemy(3), 666, 294); addObject(new ProEnemy(4), 968, 210); addObject(new ProEnemy(5), 155, 210);
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.*;
import javax.swing.JOptionPane;
import java.awt.Point;
import javax.swing.JDialog;
import javax.swing.JFrame;
/**
* Write a description of class Addition here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class ProEnemy extends Enemies
{
...
...
private int number = getRandomNumber(1,6);
public int newSpot1 = getRandomNumber(120,370);
public int newSpot2 = getRandomNumber(640,850);
public int newSpot3 = getRandomNumber(656,868);
public int newSpot4 = getRandomNumber(440,550);
public int newSpot5 = getRandomNumber(179,390);
JFrame frame;
public ProEnemy(int voucher)
{
ticket = voucher;
}
public void addedToWorld(World World)
{
getPosition();
}
public void getPosition()
{
if(ticket==1)
setMove(120,370,1,-1);
if(ticket==2)
setMove(640,850,1,-1);
if(ticket==3)
setMove(656,868,1,1);
if(ticket==4)
setMove(968,968,0,-1);
if(ticket==5)
setMove(179,390,1,1);
}
public void respawn()
{
if(ticket==1)
getWorld().addObject (new ProEnemy (1), (newSpot1), 510);
if(ticket==2)
getWorld().addObject (new ProEnemy (2), (newSpot2), 510);
if(ticket==3)
getWorld().addObject (new ProEnemy (3), (newSpot3), 294);
if(ticket==4)
getWorld().addObject (new ProEnemy (4), 968, 210);
if(ticket==5)
getWorld().addObject (new ProEnemy (5), (newSpot5), 210);
}
setMove()
..
..
public void act()
{
animate();
movement
..
..
touchingPlayer();
}
animate()
..
..
public boolean touchingPlayer()
{
Actor touchingPlayer = getOneObjectAtOffset(0, 0, Player.class);
if(touchingPlayer != null)
{
throwQuestion();
getWorld().removeObject(this);
}
return touchingPlayer!=null;
}
public int getRandomNumber(int start,int end)
{
int normal = Greenfoot.getRandomNumber(end-start+1);
return normal+start;
}
public void throwQuestion()
{
if (number == 1)
{
int answer = 0;
String input = JOptionPane.showInputDialog(null, "1+1 = ?");
if (input == null)
{
errorQuestion();
}
else
{
try
{
answer = Integer.parseInt(input);
if (answer == 2)
{
JOptionPane.showMessageDialog(frame,"good");
}
else
{
int reply = JOptionPane.showConfirmDialog(null, "do you want to retry ?", "wrong answer", JOptionPane.YES_NO_OPTION);
if (reply == JOptionPane.YES_OPTION)
{
throwQuestion();
}
else
{
respawn();
}
}
}
catch(Exception ex)
{
errorQuestion();
}
}
}
..
..
repeat until number == 6
}
public void errorQuestion()
{
try
{
respawn();
}
catch(Exception ex)
{
}
}
}


