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

2014/1/19

Determine right or wrong

1
2
3
4
danpost danpost

2014/1/20

#
How do you know it is checking the wrong combination? How do you know what combination will be next? It is randomly selected and should not be available until after the current selection has been answered and checked. You still did not answer my question about the health and lives.
danpost wrote...
you are referring to health and lives; and you have methods for 'removeHealth' and 'removeLive'. How is each represented in your world (what type of actor shows what value).
Blhaar2014 Blhaar2014

2014/1/20

#
danpost wrote...
How do you know it is checking the wrong combination? How do you know what combination will be next? It is randomly selected and should not be available until after the current selection has been answered and checked. You still did not answer my question about the health and lives.
danpost wrote...
you are referring to health and lives; and you have methods for 'removeHealth' and 'removeLive'. How is each represented in your world (what type of actor shows what value).
ow I'm sorry! Well in the first place; it's either right or wrong (the combination that is), and based on that you're supposed to press allow or deny. But when the combination is (for example) wrong, and you press 'deny' it only deletes a heart when the néxt combination is right. And the other way around is just the same... so it's quite obvious what goes wrong, it determines if a heart should be deleted by the combination it generates by clicking. Now about how my Health is represented in the world; I have the functions removeHealth(), and removeLive() both created in the buttons 'allow' and 'deny', which both reach out for the "Heart" actor. In my world the Heart is added like I've shown you. If it helps, and I hope it does, this is the code within my World class;
public class Controlecentrum extends World
{

    /**
     * Constructor for objects of class Controlecentrum.
     * 
     */
    public Controlecentrum()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(760, 760, 1); 
        
        int random = (int )(Math.random() * 4 + 1);
        addObject(new Mute(),710,20);
                
        Toestaan j = new Toestaan();
        addObject(j,660,560);
        
        Weigeren n = new Weigeren();
        addObject(n,500,560);
        
       
        addHeart();
        
 
       // prepare();      

   
    }
    
     private void addHeart()
    {
        Heart Heart = new Heart();
        addObject(Heart, 390, 40);    
    }
    
   }
Now, since my English skills are far from perfect I may have missinterpreted your question, but I sure hope this is a sufficient answer! If you like to see any more of my code to make it more clear, please say so! Thanks for the help
danpost danpost

2014/1/20

#
What class is the first 60 lines of your initial code post in? if not the world class, explain what the purpose of the object created from that class is. Or rather, just show the entire class. Also, what are the three actors being added into the world in the world class constructor (the first is of the class 'Mute', the second 'Toestaan' , and the third 'Weigeren')?
Blhaar2014 Blhaar2014

2014/1/20

#
danpost wrote...
What class is the first 60 lines of your initial code post in? if not the world class, explain what the purpose of the object created from that class is. Or rather, just show the entire class. Also, what are the three actors being added into the world in the world class constructor (the first is of the class 'Mute', the second 'Toestaan' , and the third 'Weigeren')?
The first 60 lines of my initial post are from my "deny" button, within the public void act() The same code is in my "allow" button as well. Those buttons are to be clickable, and when clicked have to either get the next random pair of actors (picture & ID card) or delete a heart and get the next pair of random actors.
Blhaar2014 Blhaar2014

2014/1/20

#
danpost wrote...
What class is the first 60 lines of your initial code post in? if not the world class, explain what the purpose of the object created from that class is. Or rather, just show the entire class. Also, what are the three actors being added into the world in the world class constructor (the first is of the class 'Mute', the second 'Toestaan' , and the third 'Weigeren')?
Ow yes sorry, forgot to mention that "mute" is a mute button where my soundtrack can be muted or unmuted (works perfectly). Toestaan is Dutch for allow, and Weigeren is Dutch for deny, so those are the allow and deny buttons that are displayed from the beginning.
danpost danpost

2014/1/20

#
That explains a lot. Better would be to have the world create the pair of actors and do the correctness checking. All the buttons should have to do is exist and get clicked and the world can check for that also. So, basically no code within the Toestaan and Weigeren classes and a World class whose code layout will look like the following:
import greenfoot.*;

public class Controlecentrum extends World
{
    // these references help in accessing these objects
    Actor deny = new Weigeren(), allow = new Toestaan();
    Heart heart = new Heart();
    boolean matching; // this holds the answer

    public Controlecentrum()
    {
        super(760, 760, 1);
        addObject(new Mute(), 710, 20);
        addObject(allow, 660, 560);
        addObject(deny, 500, 560);
        addObject(heart, 390, 40);
    }

    public void act()
    {
        if (getObjects(Idcard.class).isEmpty())
        {
            // add pair of actors
            // set the 'matching' field to proper value
        }
        else
        {
            if (Greenfoot.mouseClicked(deny))
            {
                if (matching) heart.adjustValue(-1);
                // remove pair
            }
            if (Greenfoot.mouseClicked(allow))
            {
                if (!matching) heart.adjustValue(-1);
                // remove pair
            }
            if (heart.getValue() == 0) Greenfoot.stop();
        }
    }
}
Blhaar2014 Blhaar2014

2014/1/20

#
Ow wow! Makes sense! Thanks. I will try to make everything work out that way. I will let you know if I run into any problems doing this or after this! Thanks, this also saves me a lot of unnecessary code!
danpost danpost

2014/1/20

#
Since both 'if' blocks are basically the same between lines 28 and 38, this can be condensed even more to the following:
if ((Greenfoot.mouseClicked(deny) && matching) || (Greenfoot.mouseClicked(allow) && !matching))
{
    heart.adjustValue(-1);
    if (heart.getValue() == 0) Greenfoot.stop();
    // remove pair
}
Blhaar2014 Blhaar2014

2014/1/20

#
Still having some trouble in finding out how to place the ID card en picture actors right now, but if i'm correct I should just connect the correct ones beforehand, and let the random spawning do the rest? And with the code you have supplied me with it should eventually check if the right button is pressed?
Blhaar2014 Blhaar2014

2014/1/20

#
danpost wrote...
Since both 'if' blocks are basically the same between lines 28 and 38, this can be condensed even more to the following:
if ((Greenfoot.mouseClicked(deny) && matching) || (Greenfoot.mouseClicked(allow) && !matching))
{
    heart.adjustValue(-1);
    if (heart.getValue() == 0) Greenfoot.stop();
    // remove pair
}
Hmm just a couple of questions left, deleting an object/actor from the world, doesn't seem to work through the removeObjects method, is that right? How is it done, then? And should I get a seperate button to start up with the first pair of Picture and ID card, so that from that point on the deny and allow buttons can be used?
danpost danpost

2014/1/20

#
I would just create an array with the four ID cards and an array with the four pics. Something like:
Actor[] pics = { new Dirk(), new Fleur(), new Coen(), new Remco() };
int RandomNum = Greenfoot.getRandomNumber(4);
Actor pic = pics[RandomNum];
Then determine which ID to display using your long method (make sure to use the 'if (RandomNum2 <= 30)' first every time or you may get some wrong results). There are (I am sure) better ways to randomly select an ID to display; like you could do similar to how the picture actor was done with a little modification to get the matching one most of the time. Something like:
Actors[] ids = { new IdcardDirk(), new IdcardFleur(), new IdcardCoen(), new IdcardRemco() };
int RandomNum2 = Greenfoot.getRandomNumber(13);
if (RandomNum2 > 7) RandomNum2 = 0; // giving better chance to match
matching = RandomNum2 < 2; // setting 'matching' field appropriately
Actor id = ids[(RandomNum2/2+RandomNum)%4]; // a little math play to align with pic
This should produce a better than average chance that there will be a match (7 in 13); and when not matching, an even chance for each of the wrong entries (2 in 13 for each of the wrong 3).
Blhaar2014 Blhaar2014

2014/1/20

#
Is this the right way of giving the boolean 'matching' the proper value?;
 if (RandomNum2 <= 30){
                  matching = true;
                }
                else {
                    matching = false;
                }
In theory the piece you sent makes so much sense, but it's still quite obvious I'm fairly new to all this Greenfoot magic! I really appreciate the time and effort you're willing to put into this!
danpost danpost

2014/1/20

#
Blhaar2014 wrote...
Hmm just a couple of questions left, deleting an object/actor from the world, doesn't seem to work through the removeObjects method, is that right? How is it done, then? And should I get a seperate button to start up with the first pair of Picture and ID card, so that from that point on the deny and allow buttons can be used?
The 'removeObjects' method requires a list of objects; the 'removeObject' method requires an Actor (the first is plural). A separate button is not needed. I meant to ask what class the 4 picture and 4 idcard classes extend.
Blhaar2014 Blhaar2014

2014/1/20

#
But now I'm still wondering how you can say what is a match and what not? Like, how is the programm supposed to know whats wrong and right now? I'm sorry if Im asking so much annoying questions!
Blhaar2014 Blhaar2014

2014/1/20

#
The 4 pictures have nothing in them, no code what so ever, but the ID cards have just a few lines;
public class IdcardDirk extends Idcard
{
    /**
     * Act - do whatever the IdcardDirk wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        if(Greenfoot.mouseClicked(this))
        {
            getWorld().addObject (new IdcardDirkbig(), 360, 280);
        }
        
    }    
}
This is (for example) the IdcardDirk actor, which, when clicked, makes a big IDcard pop up. nothing more.
There are more replies on the next page.
1
2
3
4