so i'm trying to animate some backtracking for school
the program should combine 3 baloons in all the posibilities whithout repetitions ( ex: 2 red baloons are not allowed to be in the same combination)
The combinations are retained in a vector (st) and the baloons images should change depending on the st vector
i tried this, but it doesn't work
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class baloon here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class baloon extends Actor
{
/**
* Act - do whatever the baloon wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
private int st[],n,k;
private boolean as, ev;
private String[] a={"","baloon1.png","baloon2.png","baloon3.png"};
public void act()
{
main();
}
int main()
{
n=3;
k=1;
init(k,st);
while(k>0)
{
do
{
succesor(k,st,as);
if(as) validare(k,st,ev);
} while(as&&!ev);
if(as)
if(solutie(k))
tipar();
else
{
k++;
init(k,st);
}
else k--;
}
return 0;
}
void init(int k, int st[])
{
st[k]=0;
}
void succesor(int k, int st[],boolean as)
{
if(st[k]<3)
{
st[k]++;
as=true;
} else
as=false;
}
void validare (int k, int st[], boolean ev)
{
int i;
ev=true;
for(i=1;i<=k-1;i++)
if(st[k]==st[i])
ev=false;
}
boolean solutie(int k)
{
if(k==n) return true;
else return false;
}
void tipar()
{
getWorld().getObjects(baloon1.class);
setImage(a[st[1]]);
Greenfoot.delay(199);
getWorld().getObjects(baloon1.class);
setImage(a[st[2]]);
Greenfoot.delay(199);
getWorld().getObjects(baloon1.class);
setImage(a[st[3]]);
Greenfoot.delay(199);
}
}
