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

2017/6/20

Overwrite method from the act-method?

KaeptnMlapa KaeptnMlapa

2017/6/20

#
Hello, while programming Deal or no Deal I came up with a little problem. So in the act method I check, if we are in a specific round and if we are a method is called to show the offer in a text.
    public void act() 
    {  
       if(((DealWorld) getWorld()).Kofferungeöffnet ==15)
       {Angebot = ((DealWorld) getWorld()).Angebot *0.15;
        Bankerrunde();}
       else if(((DealWorld) getWorld()).Kofferungeöffnet >11)
       {keinBanker();}
       else if(((DealWorld) getWorld()).Kofferungeöffnet ==11)
       {Angebot = ((DealWorld) getWorld()).Angebot *0.22;
        Bankerrunde();}
       else if(((DealWorld) getWorld()).Kofferungeöffnet >8 )
       {keinBanker();}
        else if(((DealWorld) getWorld()).Kofferungeöffnet ==8)
       {Angebot = ((DealWorld) getWorld()).Angebot *0.37;
        Bankerrunde();}
       else if(((DealWorld) getWorld()).Kofferungeöffnet >6)
       {keinBanker();}
        else if(((DealWorld) getWorld()).Kofferungeöffnet ==6)
       {Angebot = ((DealWorld) getWorld()).Angebot *0.45;
         Bankerrunde();}
        else if(((DealWorld) getWorld()).Kofferungeöffnet ==5)
       {Angebot = ((DealWorld) getWorld()).Angebot *0.54;
        Bankerrunde();}
        else if(((DealWorld) getWorld()).Kofferungeöffnet ==4)
       {Angebot = ((DealWorld) getWorld()).Angebot *0.63;
        Bankerrunde();}
        else if(((DealWorld) getWorld()).Kofferungeöffnet ==3)
       {Angebot = ((DealWorld) getWorld()).Angebot *0.7;
        Bankerrunde();}
        else if(((DealWorld) getWorld()).Kofferungeöffnet ==2)
       {Angebot = ((DealWorld) getWorld()).Angebot *0.9;
        Bankerrunde();}
        else if(((DealWorld) getWorld()).Kofferungeöffnet ==1)
       {Angebot = ((DealWorld) getWorld()).Angebot;
        Bankerrunde();}
    }    
void Bankerrunde()
    {
        double x = Math.round(Angebot);
        int i;
        i = (int) x;        
        this.getWorld().showText(i+"€",637,87);   
    }
    void keinBanker()
    {
      this.getWorld().showText(null,637,87);
    }
Now to my question: The player has to press the "No Deal" button to continue opening cases, is it possible that the button also removes the offertext? right now this is the code:
public void act() 
    {
        if(Greenfoot.mouseClicked(this))
        {
            ((DealWorld) getWorld()).Test--;
            super.keinBanker();
            
        }
    }    
Thanks in advance!
danpost danpost

2017/6/20

#
It appears that you have the class of the "No Deal" button as a subclass of the class where the first code-set is located in. I do not believe it should be as I do not believe that the button would also be an object of that superclass type. At any rate, as to your question --
getWorld().showText(null, 637, 87);
can be used by any actor in the world to remove the text at that location.
KaeptnMlapa KaeptnMlapa

2017/6/20

#
Yeah, that's right, the superclass doesn't make sense (as many parts of my project) but still, if the text is removed, the text will appear again through the act - method as the condition didn't change. But I may just add another variable so the if - cause is wrong after performing once.
danpost danpost

2017/6/21

#
KaeptnMlapa wrote...
Yeah, that's right, the superclass doesn't make sense (as many parts of my project) but still, if the text is removed, the text will appear again through the act - method as the condition didn't change. But I may just add another variable so the if - cause is wrong after performing once.
Best might be an int field that is set to the round number when showing the text (using the condition that it is not yet the current round number).
You need to login to post a reply.