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

2014/11/18

Click Two or More Places

1
2
danpost danpost

2014/11/24

#
That is quite a lot of adding and removing of actors. I think you are over-complicating things a bit. If I was doing this my way, I would have four Actor subclasses -- StartPoint, EndPoint, Wire, and Button. The only thing being added and removed from the world would be the wires. The arrangement of wires would be checked only when the button is clicked. The checking code would use current state only, not using field values to determine pass or fail. I would have the checking code set an instance boolean field in the world class to the pass/fail value. I would set it to 'false' when I use the 'addedToWorld' or 'removeObject' methods for the wires. That way, the only way it will be true is immediately after clicking the button with the correct connectivity.
meazalplaq meazalplaq

2014/11/24

#
Could you provide an example? How do you create an instance boolean field in the world class? I could be mistaken, but does the World Class constantly operate in the background of the game? So, if you wanted a situation that constantly required checking true and false conditions, the World Class would be the ideal place to put a system like that?
danpost danpost

2014/11/24

#
meazalplaq wrote...
does the World Class constantly operate in the background of the game?
Basically, the active World object operates while the scenario is running -- just like the actors within that world. That is, their act methods are repeated cycled through (the World class has an act method also).
So, if you wanted a situation that constantly required checking ... the World Class would be the ideal place to put a system like that?
The act method is one place you can do this; however, this can be done from the act method of any Actor class, provided one instance of that class is in the active world. Usually, code that is specific to a certain object should be located in the class of the object. Again the act method of all actors in the active world, plus the act method of the active world itself, are repeatedly called while the scenario is running and therefore any checks done within them will be constant checks. An instance Boolean field with a name possibly suited for your case, might be:
public boolean circuitCompleted;
Placing this line inside the class, but not within any constructor or method within the class, gives your World objects a field to store the state of the circuit. Again, any change (adding or removing of wires) should accompany a line of code setting the value of the field to false. When the button is clicked, perform the checks necessary to determine the state of the circuitry and set the field to the result.
meazalplaq meazalplaq

2014/11/25

#
Well, I believe that I got the code to work. I did not have the true and false conditions (example: connected_Red = true, connected_Red = false; ) in the correct place. I originally placed them in the if (Greenfoot.mouseClicked(this) statement. After I moved them into the if (clickTimer_ _01 > 0 && Greenfoot.mouseClicked(null) statement, the scenario worked. Thank you for your help danpost. I will try to implement the instance boolean field in the world class. It sounds like it's more straight forward. Again, thank you for your help.
meazalplaq meazalplaq

2014/12/2

#
Is it possible to utilize an instance Boolean field to register whether a mouse click has occurred, and store that response? For example, if a mouse click has occurred in the Location_11.class, then when the user re-enters Location_11 again, remove Dialog_10.class and replace it with Dialog_11.class? Is there a way to do this?
danpost danpost

2014/12/2

#
meazalplaq wrote...
Is it possible to utilize an instance Boolean field to register whether a mouse click has occurred, and store that response? For example, if a mouse click has occurred in the Location_11.class, then when the user re-enters Location_11 again, remove Dialog_10.class and replace it with Dialog_11.class? Is there a way to do this?
Absolutely. A boolean field could be used to display two different dialogs, which may be fine in your case. You can display the second one over and over after the first or you could alternate between the two. On the other hand, you could use an int field to display a multitude of dialogs depending on its value (the boolean has only two possible values -- true or false).
You need to login to post a reply.
1
2