simple java program

4
import javax.swing.JOptionPane; public class Game { public static void main(String[] args) { JOptionPane.showMessageDialog(null, "You find yourself in a dark room, " +"enveloped by cold stone.\n\n" +"At the edge of the room are two doors, one of thick " +"steel, and another of bright maple."); int option = 0; int potion = 0; while (option ==0) { String x = JOptionPane.showInputDialog("Do you choose the Door One, the steel door, or Door Two, the maple door?"); if(x.equalsIgnoreCase("door one") || x.equalsIgnoreCase("one")) { option = 1; } else if(x.equalsIgnoreCase("door two") || x.equalsIgnoreCase("two")) { option = 2; } else { JOptionPane.showMessageDialog(null, "The walls begin to move. The room is shrinking.\n\n" + "Time is running out. It's time to pick a door."); } } if(option == 2) {

Upload: vartan-batmazyan

Post on 23-Jan-2016

212 views

Category:

Documents


0 download

DESCRIPTION

Simple Java Program

TRANSCRIPT

Page 1: Simple Java Program

import javax.swing.JOptionPane;

public class Game

{

public static void main(String[] args)

{

JOptionPane.showMessageDialog(null, "You find yourself in a dark room, "

+"enveloped by cold stone.\n\n"

+"At the edge of the room are two doors, one of thick "

+"steel, and another of bright maple.");

int option = 0;

int potion = 0;

while (option ==0)

{

String x = JOptionPane.showInputDialog("Do you choose the Door One, the steel door, or Door Two, the maple door?");

if(x.equalsIgnoreCase("door one") || x.equalsIgnoreCase("one"))

{

option = 1;

}

else if(x.equalsIgnoreCase("door two") || x.equalsIgnoreCase("two"))

{

option = 2;

}

else

{

JOptionPane.showMessageDialog(null, "The walls begin to move. The room is shrinking.\n\n" +

"Time is running out. It's time to pick a door.");

}

}

if(option == 2)

{

JOptionPane.showMessageDialog(null, "The small door slides open; you kneel your head to enter\n"+

"Inside, stout creatures wielding clubs: trolls. They batter you in the face");

return;

}

Page 2: Simple Java Program

else if(option == 1)

{

JOptionPane.showMessageDialog(null, "With a great excertion of energy you push the steel door open, and are greeted by a narrow dead-end hallway.\n"+

"At the center of the room is a small table with two small flasks on top.\n"+

"There is a paper that says that drinking either of the potions will open two doors.\n"+

"With nothing left to lose, you decide to drink a potion.\n");

}

while (potion == 0)

{

String x = JOptionPane.showInputDialog("Which color flask do you choose: yellow or green?");

if(x.equalsIgnoreCase("green"))

{

potion = 1;

}

if(x.equalsIgnoreCase("yellow"))

{

potion = 2;

}

}

while(option == 1 || option == 2)

{

String x = JOptionPane.showInputDialog("Do you choose door one or door two?");

if(x.equalsIgnoreCase("door one")&& potion == 1 || x.equalsIgnoreCase("one")&&potion == 1)

{

JOptionPane.showMessageDialog(null, "You win. Congratulations.\n"+

"You are awarded a participation prize.");

return;

}

else if(x.equalsIgnoreCase("door two")&& potion == 1 || x.equalsIgnoreCase("two")&& potion == 1)

{

JOptionPane.showMessageDialog(null, "You just die. I'm running out of witty things to say.\n");

return;

}

Page 3: Simple Java Program

else if(x.equalsIgnoreCase("door one")&& potion == 2 || x.equalsIgnoreCase("one")&& potion == 2)

{

JOptionPane.showMessageDialog(null, "You walk outside! You are free\n"+

"However, you feel a sharp pain in your stomach.\n"+

"You keel over, succumbing to the potions effects.");

return;

}

else if(x.equalsIgnoreCase("door two")&& potion == 2 || x.equalsIgnoreCase("two")&& potion == 2)

{

JOptionPane.showMessageDialog(null, "A ghost appears and consumes your soul.");

return;

}

else

{

JOptionPane.showMessageDialog(null, "You're wasting my time. I have another adventure to oversee in thirty minutes.\n"+

"Hurry up!");

}

System.out.println(option);

}

}

}