Post by Admin on Jan 8, 2016 1:03:58 GMT
Game Code! 2
Doors...
Copy Paste the Code Below into BlueJ
Below is the next game code
Go back to the previous page for music or other games!
Doors...
Copy Paste the Code Below into BlueJ
Below is the next game code
Go back to the previous page for music or other games!
/**
* Emma Donahue
* F Period
*/
import javax.swing.JOptionPane;
public class Project2 {
/**
*The following are static variable, which can be found almost >Anywhere< in codes.
*/
static boolean quit = false;
static String place = "start";
/**
*This method is used so you don’t have to write JOptionpane over and over again.
*/
public static String q(String m) {
String s = JOptionPane.showInputDialog(m);
return s;
}
/**
* showMessageDialog is made shorter by using this method.
*/
public static void m(String s) {
JOptionPane.showMessageDialog(null, s);
}
public static void main(String [] args) {
while(!quit) {
if (place.equals("start")) {
start();
} else if (place.equals("Bluedoor")) {
Bluedoor();
} else if (place.equals("Reddoor")) {
Reddoor();
} else if (place.equals("ghost")) {
m("You poor soul...");
quit = true;
} else if (place.equals("win")) {
m("Bai. G00d j0b :3");
quit = true;
}
}
}
/**
*Here is where the game begins. Choose wisely between your options and try to get the the end.
*Will you make it?
*Using a String for more than one line of code is seen here.
*/
public static void start() {
String choice = q("Welcome.\n"+
"Which door do you choose? The (B)lue or (R)ed?");
if (choice.equals("B")) {
place = "Bluedoor";
} else if (choice.equals("R")) {
place = "Reddoor";
}
}
/**
* This is where you'd end up if you chose the Blue door.
*You can choose what you want to do and the code will bring you some where different.
*If you choose incorrectly you'll have quite a surprise.
*/
public static void Bluedoor() {
String choice = q("You look around the gloomy room and there's a chair.\n"+
"Next to the chair is a table with a neatly folded note card resting upon it's gl?? surface.\nIt Says:\n"+
"Don't look behind you. What do you do? Ignore the note and [look] behind you anyways, or do you [listen] and sit down in the chair?");
if (choice.equals("listen")) {
m("Well... this is it. You just. Sit in a chair. Exciting right? idon'tknowaboutyou BuT iwouldhavechosentolook.\n"+
"You’re now able to explore the empty room safely.\n"+
"Good Job. You’ve chosen wisely.");
place = "win";
} else {
m("As you look behind you an eerie growl-like noise rumbles.\n"+
"You can feel a cold and evil gaze piercing the back of your head as you slowly turn around to see what it is that awaits you.\nYou're terrified yet curious at the same time\n"+
"You finally turn around, but your eyes are sealed shut with fright. When you slowly open them you come face to face with to blowing white eyes. They are small and intimidating. You're frozen.\nToo terrified to move away from the now approaching monster you grab the nearest object to you, which is nothing but a flash card which tells you not to look behind you...\n"+
"Then everything goes black... In the blink of an eye everything just goes completely black and you wake up.\nIt was only a dream.");
place = "ghost";
}
}
/*
* Here is were you'll see a door. Open it or not, either choice will effect the outcome.
* >>If you choose to fight (o) you will have 30% chance of falling out the door..
* >>If you loose the code will end and you'll have to restart...
* >>If you win the code will end...
* >>If you choose not to open it, the code will send you back to .
*/
public static void Reddoor() {
String choice = q("You enter the Reddoor and search the room for a few moments. It looks a lot like your room except everything is clean and there's a random door next to the window.\n"+
"You become curious and walk over to the door a part of you tells to enter the other tells you to leave it closed?\nDo you [l]eave it close or [o]pen it?");
if (choice.equals("o")) {
double fight = Math.random();
if (fight > 0.4) {
m("The door shut behind you and pushed you out as a sacrifice to the Lubxubub Lord and Seeing Eye.");
place = "ghost";
} else {
m("You opened the door to find Snoop Dog.\n Get Rekt\n"+
"gr8\n"+
"u 3nt3r3d MLG l4NDD\n"+
"get out\n");
if (choice.equals("l")) {
place = "win";
}
}
}
}
}
/**
* This is the end of the code! Congrats! You either made it or lost either way this is the end. :3
*/
DO NOT COPY PASTE THIS PART.
There is small type down here that keeps making it's way into the code and messes it up.