Hello this a my Castle class and it spawns BadKnight1 after a set ammount of time, private int KnightSpawn = (8);
the problem with this code is that it only spawns one badKnight1, so to fix this problem I need a while loop. I watched the tutorial on loops and I know the code. The thing I have a question about is where to put the loop I have tried multiple places in the code none of which seemed to work. I want the int KnightSpawn get to 0 and Spawn a BadKnight1, but after that I need the value of KnightSpawn to return to 8 so the process can be repeated and spawn another knight and so forth.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class BadCastle here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class BadCastle extends BadTroops
{
private int KnightSpawn = (8);
/**
* Act - do whatever the BadCastle wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
KnightSpawn -- ;
if(KnightSpawn == 0)
{
getWorld().addObject(new BadKnight1(), 758 , 306);
}
}
}

