12/31/2023 0 Comments Greenfoot addobject from other classUpon any comparison, flip the cards back over if not matched and reset the field back to 'null'. ClassNamr object (ClassName)getOneIntersectingObject (ClassName. For example, if you want to call the method on an actor that intersects this actor, you can use. The other classes belong to the wombat scenario, and will be different if you use different scenarios. To simplify, you can replace lines 4 and 5 with: getImage ().fill () TNesler. A new GreenfootImage object initially has black set as its drawing color. The classes World and Actor will always be there they come with the Greenfoot system. The color black is referenced by: Color black Color.BLACK It is part of greenfoot's Color class, not its Greenfoot class. An attempt was made to use the actor's location while it is not in the world. Here you can see all Java classes that are involved in the project. When needed, set its location, rotation and length and have it move a distance of half its length then call a method of the line-of-sight class to get any information required (like number of intersectors - if only 2, the targeting and the targeted, then the line of sight is clear). If a card is flipped and its value is 'null' it is the first card (set it to the field) otherwise, it is the second card, which can then be compared to the one referenced in the field. If however, and that's what I am expecting, it's not a static method, you need to specifiy the instance of that class that you want to call that method on. Normally nothing happens, but sometimes the treminal says: : Actor not in world. As far as a line-of-sight actor, have each actor of the class create its own line-of-sight actor for it to use. You can add a reference field in the world class to hold the first flipped card. The actions taken there really belong in your World subclass (where the game is controlled). The addObject method is a World class method that adds a new object to the. I really do not thing that you should have what the 'act' and 'ifCorrecct' methods are doing in the Cards class, however. You will refer to this documentation often. Now, something like the image on the back of the card, which all cards will have when flipped down - that could be declared static (and final) in the Cards class and used for all the cards. So, it is the state of an instance of the Cards class. 'Flipped' is a state of a card and is not something that pertains to all cards as a whole. So, yes.įor example, your static Boolean fields for card#flipped - you only need to declare one non-static boolean in the Cards class for that. ![]() Carter wrote.Can I use this code in the class Cards, or does it have to be in Card1, Card2 etc.?If you have similar members (methods and/or fields) in all the subclasses, then you only need to code it once, in the superclass - as 'public' or 'protected'.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |