Package transientlibs.objects.general

Source Code of transientlibs.objects.general.GameDate

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package transientlibs.objects.general;

import transientlibs.objects.primitives.TBoolean;
import transientlibs.objects.primitives.Int;
import transientlibs.slick2d.util.Log;

/**
*
* @author kibertoad
*/
public class GameDate {

    public static final int SecondType = 0;
    public static final int MinuteType = 1;
    public static final int HourType = 2;
    public static final int DayType = 3;
    public static final int MonthType = 4;
    public static final int YearType = 5;

    public static final int MinutesInDay = 1440;
    public static final int TimeTypes = 5;

    public static final String[] WeekDayName = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
    public static final int TimeSize[] = {60, 60, 24, 31, 13, 32000};
    public static final int MinTimeValue[] = {0, 0, 0, 1, 1, 1};

    public static TBoolean[] endOfCycle = new TBoolean[] {new TBoolean(false), new TBoolean(false), new TBoolean(false), new TBoolean(false), new TBoolean(false), new TBoolean(false)};
    public static final GameDate gameDate = new GameDate();


    public Int[] timeValue = new Int[10];
    public int dayOfWeek = 1;
    public long tickCount;



    public void setYear (int toValue){
        timeValue[YearType].value = toValue;
    }

    public GameDate (){
      //  Log.info("New GameDate");
        for (int x = 0; x<6; x++) {
            timeValue[x] = new Int(0);
        }

        //Log.info("default GameDate");

        timeValue[SecondType].value = 0;
        timeValue[MinuteType].value = 0;
        timeValue[HourType].value = 0;
        timeValue[DayType].value = 1;
        timeValue[MonthType].value = 1;
        timeValue[YearType].value = 2071;
        //Log.info("New GameDate done");
    }


    public void checkComplete (int ofType){

while (timeValue[ofType].value>=TimeSize[ofType]) {
timeValue[ofType].value = timeValue[ofType].value-TimeSize[ofType];

if (ofType<TimeTypes) {
timeValue[ofType+1].value++; if ((ofType + 1) == DayType) {dayOfWeek++; if (dayOfWeek > 7) {dayOfWeek = 1;}}
endOfCycle[ofType+1].value = true; //Day\year\month is over
}
}

if (timeValue[ofType].value<MinTimeValue[ofType]) {timeValue[ofType].value = MinTimeValue[ofType];}
if (ofType<TimeTypes) {checkComplete (ofType+1);}

    }


public void PassTime (int ofType, int howMuch) {

    Log.info("pass time");

endOfCycle[DayType].value   = false;
endOfCycle[MonthType].value = false;
endOfCycle[YearType].value  = false;

while (howMuch>0) {

//inc (TickCount);
timeValue[ofType].value++;
if (ofType == DayType) {dayOfWeek++; if (dayOfWeek > 7) {dayOfWeek = 1;}

}
checkComplete (ofType);
//CheckInterrupt;
//Check if some event interrupts time flow; maybe delegate this to Chrono?..}
howMuch--;
}
}

public String Day (){
    //return Integer.toString(timeValue[DayType].value);

    return timeValue[DayType].toString();

}

public String Month (){
    return Integer.toString(timeValue[MonthType].value);
}

public String Year (){
    return Integer.toString(timeValue[YearType].value);
}


public String returnFullString (){
    //Log.info("Start building");
    StringBuilder buildString = new StringBuilder();

    //Log.info(timeValue[DayType].value+" day");
    //Log.info(timeValue[DayType].toString()+" dday");

    buildString.append("Year ");
    buildString.append(Year());
    buildString.append(" Month ");
    buildString.append(Month());
    buildString.append(" Day ");
    buildString.append(Day());
    buildString.append(".");

    //Log.info(buildString+" str");
    //Log.info(buildString.toString()+" str");


    return buildString.toString();
}


}
TOP

Related Classes of transientlibs.objects.general.GameDate

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.