home *** CD-ROM | disk | FTP | other *** search
/ MACD 4 / MACD4.iso / Internet / Java / networking / sockets / example / KKState.class (.txt) < prev    next >
Encoding:
Java Class File  |  1978-03-06  |  1.8 KB  |  51 lines

  1. class KKState {
  2.    private static final int WAITING = 0;
  3.    private static final int SENTKNOCKKNOCK = 1;
  4.    private static final int SENTCLUE = 2;
  5.    private static final int ANOTHER = 3;
  6.    private static final int NUMJOKES = 5;
  7.    private int state;
  8.    private int currentJoke;
  9.    private String[] clues = new String[]{"Turnip", "Little Old Lady", "Atch", "Who", "Who"};
  10.    private String[] answers = new String[]{"Turnip the heat, it's cold in here!", "I didn't know you could yodel!", "Bless you!", "Is there an owl in here?", "Is there an echo in here?"};
  11.  
  12.    String processInput(String var1) {
  13.       String var2 = null;
  14.       if (this.state == 0) {
  15.          var2 = "Knock! Knock!";
  16.          this.state = 1;
  17.       } else if (this.state == 1) {
  18.          if (var1.equalsIgnoreCase("Who's there?")) {
  19.             var2 = this.clues[this.currentJoke];
  20.             this.state = 2;
  21.          } else {
  22.             var2 = "You're supposed to say \"Who's there?\"! Try again. Knock! Knock!";
  23.          }
  24.       } else if (this.state == 2) {
  25.          if (var1.equalsIgnoreCase(this.clues[this.currentJoke] + " who?")) {
  26.             var2 = this.answers[this.currentJoke] + " Want another? (y/n)";
  27.             this.state = 3;
  28.          } else {
  29.             var2 = "You're supposed to say \"" + this.clues[this.currentJoke] + " who?\"" + "! Try again. Knock! Knock!";
  30.             this.state = 1;
  31.          }
  32.       } else if (this.state == 3) {
  33.          if (var1.equalsIgnoreCase("y")) {
  34.             var2 = "Knock! Knock!";
  35.             if (this.currentJoke == 4) {
  36.                this.currentJoke = 0;
  37.             } else {
  38.                ++this.currentJoke;
  39.             }
  40.  
  41.             this.state = 1;
  42.          } else {
  43.             var2 = "Bye.";
  44.             this.state = 0;
  45.          }
  46.       }
  47.  
  48.       return var2;
  49.    }
  50. }
  51.