public void run() { init(); while (true) { System.out.print( String.format( "%-20s %-40s", tamagotchi.getLifeState(), tamagotchi.getPhysicalState().getDescription())); System.out.print( String.format( " %30s", "(" + tamagotchi.getHungerIndex() + " , " + tamagotchi.getAge() + " , " + currentDay + ":" + currentHour + ") ? ")); userInput(); } }
// Step through simulation. // It simulates passage of time. Changes internal state. private void step(Integer stepHours) { LifeState lifeState = tamagotchi.getLifeState(); PhysicalState physicalState = tamagotchi.getPhysicalState(); Integer age = tamagotchi.getAge(); Integer hungerIndex = tamagotchi.getHungerIndex(); currentHour += stepHours; if (currentHour > 24) { currentDay = +1; currentHour = currentHour % 24; age = +1; } // Losses energy and get aged as time passes. tamagotchi.loseHealth(stepHours); tamagotchi.setAge(age); lifeState.action(tamagotchi); physicalState.action(tamagotchi, currentHour); }