MightyPork

Virtual Chicken [awesome]

Jul 12th, 2013
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.04 KB | None | 0 0
  1. import java.util.Random;
  2. import javax.swing.JOptionPane;
  3.  
  4. public class Chicken {
  5.     private static Random rand = new Random();
  6.    
  7.     public static void main(String[] args) {
  8.         Chicken poultry = new Chicken();
  9.         poultry.start();
  10.     }
  11.    
  12.     private void msg(String message) {
  13.         JOptionPane.showMessageDialog(null, message);
  14.     }
  15.    
  16.     private String ask(String message) {
  17.         return JOptionPane.showInputDialog(message);
  18.     }
  19.    
  20.     private boolean yesno(String message) {
  21.         int choice = JOptionPane.showConfirmDialog(null, message, "Chicken", JOptionPane.YES_NO_OPTION);
  22.         return choice == JOptionPane.YES_OPTION;
  23.     }
  24.    
  25.     private String name = "";
  26.     private int eggsC = 0;
  27.     private int songsC = 0;
  28.    
  29.     private void start() {
  30.        
  31.         msg("Hello, I'm a virtual chicken!");
  32.         name = ask("Give me a name, please.");
  33.         msg("Nice, "+name+" is a wonderful name!");
  34.        
  35.         while(true) {
  36.             String opt = ask("Hey there, I'm a chicken called " + name+ "!\n" +
  37.                     "\nI can do various things. Select number:\n\n" +
  38.                     "1) Sing\n" +
  39.                     "2) Fly\n" +
  40.                     "3) Lay egg\n" +
  41.                     "4) Get cooked\n");
  42.            
  43.             int userNumber;
  44.            
  45.             try {              
  46.                 userNumber = Integer.parseInt(opt);            
  47.             } catch (NumberFormatException e) {            
  48.                 msg(name + ":\nThis is not a number, try again.");
  49.                 continue; // ask again
  50.             }
  51.                        
  52.             switch(userNumber) {
  53.                 case 1:
  54.                     boolean again = true;
  55.                     while(again) {
  56.                         sing();                
  57.                         again = yesno(name + ":\nWant another lovely song?");
  58.                     }                  
  59.                     continue;
  60.                    
  61.                 case 2:
  62.                     msg("Chicken "+ name + " takes off ground.");
  63.                     msg("Chicken "+ name + " is flying around.");      
  64.                     msg("Chicken "+ name + " sits back on ground.");
  65.                     continue;
  66.                    
  67.                 case 3:
  68.                     msg("PLOP!");
  69.                     eggsC++;
  70.                     continue;
  71.                    
  72.                 case 4:
  73.                     for(int i=0; i< 1+rand.nextInt(5); i++) cook();
  74.                    
  75.                     msg("Chicken "+ name + " is now cooked.\n\n" +
  76.                             "Life facts:\n" +
  77.                             "Eggs = " + eggsC + "\n" +
  78.                             "Songs = " + songsC);
  79.  
  80.                     msg("Game Over!");
  81.                     System.exit(0);
  82.                    
  83.                     continue;
  84.                    
  85.             }
  86.         }
  87.     }
  88.    
  89.     private String[] songs = {
  90.             "Bock,bock,bock,bock,bock,begowwwwk!",
  91.             "BUCUCK!!",
  92.             "brrk, brroock, broock, brk-ooock",
  93.             "cockadoodle dooooooooooooooooooooooooooo",
  94.             "peep peep peep peep peep",
  95.             "Buk buk buk buk bukkaaaa",
  96.             "RO-UH-RO-UH-ROOOO",
  97.             "WRA, WRA, WROW, WROA, WRO!",
  98.             "Pio! Pio! Pio! Pi!",
  99.             "BTRAAAWKWKWWWKKKKK!!!",
  100.             "buuck buuck buuukcuck!!!!",
  101.             "kok-ro-koooo",
  102.             "kokokokokokdaaaawk!!!1!1!!!!!"
  103.     };
  104.    
  105.     private void sing() {
  106.         msg(name+":\n" + songs[rand.nextInt(songs.length)]);
  107.         songsC++;
  108.     }
  109.    
  110.     private static String[] cook = {
  111.             "Owowowow thats so hot!",
  112.             "I'm burning!",
  113.             "BTRAAAWKWKWWWKKKKK!!!",
  114.             "Oink! BUCUCK!!!!! RAWR!",
  115.             "This is not cool!",
  116.             "I'm on fire!!!",
  117.             "Help me out, pls?",
  118.             "I'm a coal brick already!",
  119.             "Wahaha I'm a phoenix!",
  120.             "Oh shit.",
  121.             "Was this needed??",
  122.             "cough cough BUUUKKKKKKWKWKWKWKW!",
  123.     };
  124.    
  125.     private void cook() {
  126.         msg(name+":\n" + cook[rand.nextInt(cook.length)]);
  127.     }
  128. }
Advertisement
Add Comment
Please, Sign In to add comment