Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Random;
- import javax.swing.JOptionPane;
- public class Chicken {
- private static Random rand = new Random();
- public static void main(String[] args) {
- Chicken poultry = new Chicken();
- poultry.start();
- }
- private void msg(String message) {
- JOptionPane.showMessageDialog(null, message);
- }
- private String ask(String message) {
- return JOptionPane.showInputDialog(message);
- }
- private boolean yesno(String message) {
- int choice = JOptionPane.showConfirmDialog(null, message, "Chicken", JOptionPane.YES_NO_OPTION);
- return choice == JOptionPane.YES_OPTION;
- }
- private String name = "";
- private int eggsC = 0;
- private int songsC = 0;
- private void start() {
- msg("Hello, I'm a virtual chicken!");
- name = ask("Give me a name, please.");
- msg("Nice, "+name+" is a wonderful name!");
- while(true) {
- String opt = ask("Hey there, I'm a chicken called " + name+ "!\n" +
- "\nI can do various things. Select number:\n\n" +
- "1) Sing\n" +
- "2) Fly\n" +
- "3) Lay egg\n" +
- "4) Get cooked\n");
- int userNumber;
- try {
- userNumber = Integer.parseInt(opt);
- } catch (NumberFormatException e) {
- msg(name + ":\nThis is not a number, try again.");
- continue; // ask again
- }
- switch(userNumber) {
- case 1:
- boolean again = true;
- while(again) {
- sing();
- again = yesno(name + ":\nWant another lovely song?");
- }
- continue;
- case 2:
- msg("Chicken "+ name + " takes off ground.");
- msg("Chicken "+ name + " is flying around.");
- msg("Chicken "+ name + " sits back on ground.");
- continue;
- case 3:
- msg("PLOP!");
- eggsC++;
- continue;
- case 4:
- for(int i=0; i< 1+rand.nextInt(5); i++) cook();
- msg("Chicken "+ name + " is now cooked.\n\n" +
- "Life facts:\n" +
- "Eggs = " + eggsC + "\n" +
- "Songs = " + songsC);
- msg("Game Over!");
- System.exit(0);
- continue;
- }
- }
- }
- private String[] songs = {
- "Bock,bock,bock,bock,bock,begowwwwk!",
- "BUCUCK!!",
- "brrk, brroock, broock, brk-ooock",
- "cockadoodle dooooooooooooooooooooooooooo",
- "peep peep peep peep peep",
- "Buk buk buk buk bukkaaaa",
- "RO-UH-RO-UH-ROOOO",
- "WRA, WRA, WROW, WROA, WRO!",
- "Pio! Pio! Pio! Pi!",
- "BTRAAAWKWKWWWKKKKK!!!",
- "buuck buuck buuukcuck!!!!",
- "kok-ro-koooo",
- "kokokokokokdaaaawk!!!1!1!!!!!"
- };
- private void sing() {
- msg(name+":\n" + songs[rand.nextInt(songs.length)]);
- songsC++;
- }
- private static String[] cook = {
- "Owowowow thats so hot!",
- "I'm burning!",
- "BTRAAAWKWKWWWKKKKK!!!",
- "Oink! BUCUCK!!!!! RAWR!",
- "This is not cool!",
- "I'm on fire!!!",
- "Help me out, pls?",
- "I'm a coal brick already!",
- "Wahaha I'm a phoenix!",
- "Oh shit.",
- "Was this needed??",
- "cough cough BUUUKKKKKKWKWKWKWKW!",
- };
- private void cook() {
- msg(name+":\n" + cook[rand.nextInt(cook.length)]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment