Samasaur1 / CityManagement

A text-based city management game
3 stars 7 forks source link

Birthdays change every day #6

Closed Samasaur1 closed 6 years ago

Samasaur1 commented 6 years ago

Currently, every day, all citizens' birthdays change to the new date. That means they get 'a year' older every day. I've isolated it to this method (line 129, SimpleDate.java)

public void proceedOneDay() {
    SimpleDate newDate = nextDay(this);
    this.setDate(monthToNumber(newDate.getMonth()), newDate.getDayOfMonth(), newDate.getYear());
}

and it appears to be when the line

SimpleDate newDate = nextDay(this);

is called. This is kind of important.

Samasaur1 commented 6 years ago

Has now been isolated to this function

public static SimpleDate nextDay(SimpleDate old) {
    old.dayOfMonth += 1;
    if (old.getDayOfMonth() > old.month.getNumberOfDays()) {
        old.dayOfMonth = 1;
        int newMonth = monthToNumber(old.getMonth()) + 1;
        int newYear = old.getYear();
        while (newMonth > 12) {
            newMonth -= 12;
            newYear += 1;
        }
        old.setDate(newMonth, old.getDayOfMonth(), newYear);
    }
    return old;
}

and it occurs immediately on the first line, which (coincidentally) moves the date itself forward one day. The problem may be because I am changing the passed in date, but it may be because this value is being set to the birthday.

Samasaur1 commented 6 years ago

Even after 0f9d2e36e45a66f305f15aac0284bec36e1dbf3b and 595f3b9ba8902629d632a6603e84e35cd81c44a5 (and testing of them), this is not fixed. I believe that proceedOneDay is being called on the birthdays somewhere.

Samasaur1 commented 6 years ago

Fixed in c302268b2a8f607f718b836dbecf840bf6a0c11a. I was referencing the actual date... It now makes a copy.