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

2018/12/4

Time based point system

MemThef MemThef

2018/12/4

#
So I'm making a game where you can buy items with the points you have gotten so far and over a period of seconds, you will get more points based on the amount of that item you bought. I have the counter down and the buying, I just can't get the it to add the points back. I have a button and an actor of each button so I will post both on one of them. Button:
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class GrandmaButton here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class 10pButton extends Buttons
{
public  10pButton()
    {
        setImage(new GreenfootImage("Buy 10p: " + cost1, 20, Color.WHITE, Color.BLUE));
    }
    public int cost1 = 25;
    public int GN = 0;
    
    public void act() 
    {
        checkBuy();
        setImage(new GreenfootImage("Buy 10p: " + cost1, 20, Color.WHITE, Color.BLUE));
    }    
    
    public void checkBuy()
    {
        BackGround theWorld = (BackGround) getWorld();
            Counter counter = theWorld.getCounter();
        if(counter.getValue() >=cost1 ){
        if(Greenfoot.mouseClicked(this)==true) {
            counter.subtract(cost1);
            GN ++;
            decideCost();
        }
    }
    }
    
    public void decideCost(){
        
        cost1 = cost1 + ((3^(GN+1))*GN) + (1+(3^GN)*(GN));
        
        
    }  
}
Actor:
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

public class 10p extends Actor
{
    public void act() 
    {
        WaitTime();
    }
    public int timer2 = 10;
    public void WaitTime()
    {
        if(timer2 > 0) {
            timer2 --;
        }

        if(timer2 == 0){
            BackGround theWorld = (BackGround) getWorld();  
             Counter counter = theWorld.getCounter();  
              counter.add(50);                  
              timer2 = 10;
        }
    }
}
Thanks in advanced.
You need to login to post a reply.