| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- import java.util.Scanner;
- public class Main{
- public static void main (String[] args){
-
- // read user input
- Scanner input = new Scanner(System.in);
- char userinput = 'c';
-
- // load existing pet if there is one
- Pet mypet = Pet.loadFromDisk();
- if(mypet == null){
- mypet = new Pet();
- }
-
- // main game loop
- System.out.println("Welcome to \"The Pet Simulator.\"");
- while(userinput != 'q' && mypet.isAlive()){
- System.out.println("Here are your pet's stats:");
- mypet.printStatus();
- System.out.println("Enter \'f,\' \'w,\' or \'r\' to feed, water, or rest your pet.");
- System.out.println("Enter \'q\' to save and quit.");
- userinput = input.next().charAt(0);
- if(userinput == 'f'){
- mypet.feed();
- }
- if(userinput == 'w'){
- mypet.water();
- }
- if(userinput == 'r'){
- mypet.rest();
- }
- }
-
- // present the bad news
- if(!mypet.isAlive()){
- System.out.println("This pet has died.");
- }
-
- // clean up
- mypet.saveToDisk();
- input.close();
- }
- }
|