recognizing a standby phase

fukurou

Administrator

alg :
timeGateOpen ?{close;standBy=true; reset;return}
else{output?reset timeGates time to wait;}

so I need to adapt the time gate class to work with minutes

Java:
class JikanMon {
    private val playGround = PlayGround()
    private var x = -1
    private var timePause = 3
    val isBlocked:Boolean
        get() {
            val nowSeconds = playGround.getSecondsAsInt()
            if ((x < 0 || nowSeconds > x) || (x > 60 && nowSeconds > (x - 60)))
            {
                x = -1
                return false
            }
            return true
        }
    fun block() {
        this.x = playGround.getSecondsAsInt() + timePause
    }
    fun setTimePause(timePause:Int) {
        if ((timePause > 0) && (timePause < 30))
        {
            this.timePause = timePause
        }
    }
}
 

fukurou

Administrator
Java:
import java.util.Calendar;
import java.util.Date;

public class TimeGate {
    private int pause = 1;
    private Date openedGate = addMinutesToJavaUtilDate(new Date(), pause);
    public Boolean isClosed() {
        return openedGate.before(new Date());
    }
    public void close() {
        this.openedGate = addMinutesToJavaUtilDate(new Date(), pause);
    }
    public void close(int minutes) {
        Date now = new Date();
        openedGate = addMinutesToJavaUtilDate(now, minutes);
    }
    private Date addMinutesToJavaUtilDate(Date date, int minutes) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.MINUTE, minutes);
        return calendar.getTime();
    }
    public void setPause(int pause) {
        if(pause <60 && pause >0) {
        this.pause = pause;}
    }
}
 
Top