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

2012/6/15

Removing a object help

DAustin15 DAustin15

2012/6/15

#
Hello Everyone, My group and I have still been continuing our work on Sociapoly (a version of Monopoly,) but we came across a small problem. Each time one of the four player pieces lands on a spot on the board, the game spawns the title deed. When a player does not "purchase" a title deed during his/her turn, the title deed is not removed. This causes a few complications, and so we are looking for a way to remove the unpurchased title deed. I will post the code below and attach a link to the current version of Sociapoly. Any help will be very much appreciated, thank you for your time. Our scenario
public class TitleDeeds extends Actor
{
    /**
     * Act - do whatever the PropertyDeeds wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        // Add your action code here.
    }

    public void purchased()
    {
        if(getX() != 832)
        {
            if(Purchase.bought == true)
            {
                if(Chrome.turn == true)
                {
                    setLocation(832,117);
                }
                if(Safari.turn == true)
                {
                    setLocation(832,268);
                }
                if(Explorer.turn == true)
                {
                    setLocation(832,418);
                }
                if(Firefox.turn == true)
                {
                    setLocation(832,571);
                }
            }
        }        
        Actor old = getOneIntersectingObject(null);
        if(old != null)
        {
            getWorld().removeObject(old);
        }
    }
}
danpost danpost

2012/6/16

#
Add a TitleDeeds variable to your sub-class of World, call it unownedDeed and set it to 'null'. When one is spawned, instead of 'addObject(new TitleDeeds(...), x, y)', use 'unownedDeed = new TitleDeeds(...); addObject(unownedDeed, x, y);'. Then at the end of a player's turn 'if (unownedDeed != null) { removeObject(unownedDeed); unownedDeed = null; }'. Of course, if an unownedDeed is purchased, you must change the value of unownedDeed back to 'null'.
You need to login to post a reply.