This site requires JavaScript, please enable it in your browser!
Greenfoot back
ToRu_4649
ToRu_4649 wrote ...

2016/11/26

help,, how to if i get object AAA win

ToRu_4649 ToRu_4649

2016/11/26

#
please help me master, i want if papan get object example AAA we win.. I've tried but could not.. sorry if my english so bad.. :) in here Actor A,F,L can move from left to right, and papan (rectangle) can move up and down. SS :
public class papan extends Actor
{

    /**
     * Act - do whatever the papan wants to do. This method is called whenever the 'Act' or 'Run' button gets pressed in the environment.
     */
        int counter =0;
        int A = 0;
        int L = 0;
        int F = 0;
        
        
    public void act()
    {
        counter = counter +1;
        if (Greenfoot.isKeyDown("up")) 
        {
            setLocation(getX(), getY()-10);
        }
        if (Greenfoot.isKeyDown("down")) 
        {
            setLocation(getX(), getY()+10);
        }
        if(isTouching(a.class))
        {
            removeTouching(a.class);
            //A=A +1;
            Greenfoot.playSound("catch.wav");
        }
        if(isTouching(f.class))
        {
            //F=F +1;
            Greenfoot.playSound("catch.wav");
        }
        if(isTouching(l.class))
        {
            //L=L +1;
            Greenfoot.playSound("catch.wav");
        }
        if(counter == 20)
        {
            if(Greenfoot.getRandomNumber(2)==1)
            {
                getWorld().addObject ( new a(),0/*Greenfoot.getRandomNumber(100)*/,Greenfoot.getRandomNumber(700));
            }
            else
            {
                getWorld().addObject ( new f(),0/*Greenfoot.getRandomNumber(100)*/,Greenfoot.getRandomNumber(700));
            }
            counter =0;
        }
        /*if()
        {
            getWorld().addObject ( new gameover(),459,284); //on this gameover meaning win,just test.
            Greenfoot.stop();
        }*/
    }
}
Super_Hippo Super_Hippo

2016/11/26

#
What is AAA? Should Papan catch three A in a row without touching F or L? I am not sure what the win condition should be here. Btw, all class names should start with an uppercase letter (Papan, A, F, L, GameOver, ...) and all variables should be lowercase (a, l, f, ...).
danpost danpost

2016/11/26

#
You need to remove touching 'f' and 'l' object -- like you did with 'a' objects (or their counts will be hyper-active).
ToRu_4649 ToRu_4649

2016/11/27

#
Super_Hippo wrote...
What is AAA? Should Papan catch three A in a row without touching F or L? I am not sure what the win condition should be here. Btw, all class names should start with an uppercase letter (Papan, A, F, L, GameOver, ...) and all variables should be lowercase (a, l, f, ...).
yeah, i mean if PAPAN catch three A in a row without touching F or L we win. i try with "String.length()" but not work..
Super_Hippo Super_Hippo

2016/11/27

#
You could set the variable a back to 0 whenever it touches F or L.
ToRu_4649 ToRu_4649

2016/11/27

#
danpost wrote...
You need to remove touching 'f' and 'l' object -- like you did with 'a' objects (or their counts will be hyper-active).
hahah.. yeah.. yesterday i forget to add.. you have suggestion? how if i catch three A without touching F or L we win..
ToRu_4649 ToRu_4649

2016/11/27

#
Super_Hippo wrote...
You could set the variable a back to 0 whenever it touches F or L.
yeah its work.. and i have one question.. in here i have 5 combination example A,B,C,D,E how if we catch 5 alphabet A,B,C,D,E we win.. new code
public class papan extends Actor
{

    /**
     * Act - do whatever the papan wants to do. This method is called whenever the 'Act' or 'Run' button gets pressed in the environment.
     */
        int counter =0;
        //int score = 0;
        String A = "";
        String B = "";
        String C = "";
        String D = "";
        String E = "";
        String test=A+B+C+D+E;
        
        
    public void act()
    {
        counter = counter +1;
        if (Greenfoot.isKeyDown("up")) 
        {
            setLocation(getX(), getY()-10);
        }
        if (Greenfoot.isKeyDown("down")) 
        {
            setLocation(getX(), getY()+10);
        }
        if(isTouching(a.class))
        {
            removeTouching(a.class);
            A="A";
            Greenfoot.playSound("catch.wav");
        }
        if(isTouching(b.class))
        { 
            removeTouching(b.class);
            B="B";
            Greenfoot.playSound("catch.wav");
        }
        if(isTouching(c.class))
        {
            removeTouching(c.class);
            C="C";
            Greenfoot.playSound("catch.wav");
        }
        if(isTouching(d.class))
        {
            removeTouching(d.class);
            D="D";
            Greenfoot.playSound("catch.wav");
        }
        if(isTouching(e.class))
        {
            removeTouching(e.class);
            E="E";
            Greenfoot.playSound("catch.wav");
        }
        if(counter == 80)//just try
        {
            if(Greenfoot.getRandomNumber(2)==1)
            {
                getWorld().addObject ( new a(),0/*Greenfoot.getRandomNumber(100)*/,Greenfoot.getRandomNumber(700));
            }
            else
            {
                getWorld().addObject ( new b(),0/*Greenfoot.getRandomNumber(100)*/,Greenfoot.getRandomNumber(700));
            }
//.etc
            counter =0;
        }
        if(test.length()==5)
        {
            getWorld().addObject ( new gameover(),459,284);
            Greenfoot.stop();
        }
    }
}
Super_Hippo Super_Hippo

2016/11/27

#
Maybe like this:
private String touched = "";

//in act
if (isTouching(A.class))
{
    touched = "A";
}
if (isTouching(B.class))
{
    if ("A".equals(touched))
    {
        touched = "AB";
    }
    else
    {
        touched = "";
    }
}
if (isTouching(C.class))
{
    if ("AB".equals(touched))
    {
        touched = "ABC";
    }
    else
    {
        touched = "";
    }
}
if (isTouching(D.class))
{
    if ("ABC".equals(touched))
    {
        touched = "ABCD";
    }
    else
    {
        touched = "";
    }
}
if (isTouching(E.class))
{
    if ("ABCD".equals(touched))
    {
        //win
    }
    else
    {
        touched = "";
    }
}
ToRu_4649 ToRu_4649

2016/11/27

#
yes,, its work.. thank you mastah.. :) in this project I get a new science...
danpost danpost

2016/11/27

#
If you are interested, here is another way of doing it:
private String sequence = "ABCDE";
private String caught = "";

// in act
Actor actor = getOneIntersectingObject(Actor.class);
if (actor != null && actor.getClass().getName().length() == 1)
{
    getWorld().removeObject(actor);
    caught += actor.getClass().getName();
    if (sequence.startsWith(caught))
    {
        Greenfoot.playSound("catch.wav");
        if (sequence.equals(caught))
        {
            getWorld().addObject (new GameOver(), 459, 284);
            Greenfoot.stop();
        }
    }
    else
    {
        // lose (play lose sound, show lose actor, stop scenario
    }
}
ToRu_4649 ToRu_4649

2016/11/28

#
danpost wrote...
If you are interested, here is another way of doing it:
private String sequence = "ABCDE";
private String caught = "";

// in act
Actor actor = getOneIntersectingObject(Actor.class);
if (actor != null && actor.getClass().getName().length() == 1)
{
    getWorld().removeObject(actor);
    caught += actor.getClass().getName();
    if (sequence.startsWith(caught))
    {
        Greenfoot.playSound("catch.wav");
        if (sequence.equals(caught))
        {
            getWorld().addObject (new GameOver(), 459, 284);
            Greenfoot.stop();
        }
    }
    else
    {
        // lose (play lose sound, show lose actor, stop scenario
    }
}
thank you master.. :) now i can play my game.. hihi..
You need to login to post a reply.