You are on page 1of 21

import java.util.

*;
import javax.swing.JFrame;
import javax.swing.ImageIcon;
import javax.swing.JLabel;

public class adventureGame extends JFrame {


private static boolean knight = false;
private static boolean sonic = false;
private static boolean thor = false;

public static void main (String args[]){


Scanner sc = new Scanner (System.in);
System.out.println("Welcome to the Adventure Game!");
System.out.println("What is your name?"+ " ");
String name = sc.nextLine();
System.out.println("Hello" + " "+ name + "!");
boolean exitloop=true;
while(exitloop) {
System.out.println("Choose one of the following paths to enter by typing in: ");
System.out.println("knight, sonic, or thor. ");
String choice = sc.nextLine();
choice.toLowerCase();
if(choice.equals("knight")) {
knight=adventureGame.knight(name);
if (knight) {
exitloop=false;
System.out.println("You have completed a level!");
System.out.println("Choose one of the remaining paths by typing in:");
System.out.println("sonic, or thor. ");
String a = sc.nextLine();
a.toLowerCase();
if (a.equals("sonic")) {
sonic=adventureGame.sonic(name);
if (sonic) {
System.out.println("You have completed a level!");
System.out.println("Complete the last path: thor");
thor=adventureGame.thor(name);
if (thor)
System.out.print("Congratulations! You completed all three paths!");
}
} else {
thor=adventureGame.thor(name);
if (thor) {
System.out.println("You have completed a level!");
System.out.println("Complete the last path: sonic");
sonic=adventureGame.sonic(name);
if (sonic)
System.out.print("Congratulations! You completed all three paths!");
}
}
}
}

if(choice.equals("sonic")) {
sonic=adventureGame.sonic(name);
if (sonic) {
exitloop=false;
System.out.println("You have completed a level!");
System.out.println("Choose one of the remaining paths by typing in:");
System.out.println("knight, or thor. ");
String b = sc.nextLine();
b.toLowerCase();
if (b.equals("knight")) {
knight=adventureGame.knight(name);
if (knight) {
System.out.println("You have completed a level!");
System.out.println("Complete the last path: thor");
thor=adventureGame.thor(name);
if (thor)
System.out.print("Congratulations! You completed all three paths!");
}
} else {
thor=adventureGame.thor(name);
if (thor) {
System.out.println("You have completed a level!");
System.out.println("Complete the last path: knight");
knight=adventureGame.knight(name);
if (knight)
System.out.print("Congratulations! You completed all three paths!");
}
}
}
}
if(choice.equals("thor")) {
thor=adventureGame.thor(name);
if (thor) {
exitloop=false;
System.out.println("You have completed a level!");
System.out.println("Choose one of the remaining paths by typing in:");
System.out.println("knight, or sonic. ");
String c = sc.nextLine();
c.toLowerCase();
if (c.equals("knight")) {
knight=adventureGame.knight(name);
if (knight) {
System.out.println("You have completed a level!");
System.out.println("Complete the last path: sonic");
sonic=adventureGame.sonic(name);
if (sonic)
System.out.print("Congratulations! You completed all three paths!");
}
} else {
sonic=adventureGame.sonic(name);
if (sonic) {
System.out.println("You have completed a level!");
System.out.println("Complete the last path: knight");
knight=adventureGame.knight(name);
if (knight)
System.out.print("Congratulations! You completed all three paths!");
}

}
}
}

}
public static boolean knight (String name) {
Scanner sc = new Scanner (System.in);
Scanner sc1 = new Scanner (System.in);
System.out.println("Today you are the gallant knight named Sir Anthony III.");
System.out.println("");
System.out.println("Please make sure to answer questions as directed; if the question in a yes or no question enter yes or no \nIf the question asks you to decide on
two actions, enter 1 or 2, with 1 being the first action and two being the second.");
System.out.println("");
System.out.println("");
System.out.println(" You wake up in the morning of the twelfth century to the rise of a beatiful sun. "
+ "\n You look down at your body and are suprised to find it fitted in silk linens."
+ "\n Quickly you take in your surroundings. The walls are beatifully crafted and seems to be made of limestone."
+ "\n You glance out of the window and see that you are almost a hundred feet up. You realize that you are in a castle."
+ "\n Do you want to exit the room? yes/no");
JFrame frame = new JFrame();
ImageIcon icon = new ImageIcon("Pics/room.png");
JLabel label = new JLabel(icon);
frame.add(label);
frame.setDefaultCloseOperation
(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);

String exit = sc.nextLine();


exit.toLowerCase();
if(exit.equals("yes")) {
System.out.println("You pry open the door carefully and now you are looking down a limestone corridor about 12 feet high."
+ "\n You turn left along the corridor and find yourself over looking a beautiful courtyard lined with flowers of all kinds and highly
maintained bushes."
+ "\n Suddenly realization dawns on you: you don't know your name!, you frantically scan the area and find a servant in the courtyard
trimming the bushes."
+ "\n Do you want to approach the servant? yes/no");
String servant = sc.nextLine();
servant.toLowerCase();
if(servant.equals("yes")) {
} else if(servant.equals("no")) {
System.out.println("You indecisevly linger in the corridor.");
System.out.println("The servant spots you and approaches you.");
System.out.println("You are cornered. ");

}
System.out.println("The servant looks up cheerfully: Hello sir Anthony, how may I help you?");
System.out.println("Do you tell him your secret that you are not Sir Anthony? yes/no");
String word1 = sc.nextLine();
word1.toLowerCase();
if (word1.equals("yes")) {
System.out.println("The servant appears confused, and ignores you.");
}
System.out.println("The servant says: Well the King has requested you in the banquet hall.");
System.out.println("You continue walking forward and find yourself in the doorway to a grand banquet.");

JFrame frame1 = new JFrame();


ImageIcon icon1 = new ImageIcon("Pics/table.jpg");
JLabel label1 = new JLabel(icon1);
frame1.add(label1);
frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame1.pack();
frame1.setVisible(true);

System.out.println("A long table fitted with bronze draperies occupies the middle of the room.");
System.out.println("A man fitted in a fine robe and crown bellows:"
+ " \n Welcome Sir Anthony! we have been missing your company.");
System.out.println("Do you try to 1- sit down somewhere or 2- stay standing?");
int sit = sc.nextInt();
System.out.println("You do so and try not to speak as your voice would almost certainly betray you.");
System.out.println("You end up only saying short phrases but the King has found you out!");
System.out.println("He says: you are not Sir Anthony, but rather an imposter!");
System.out.println("Do you 1-deny the accusation or 2-accept it?");
int acc = sc.nextInt();
if (acc==1) {
System.out.println("You deny the Kings accusation but it doesn't seem to phase him.");
}
if (acc==2) {
System.out.println("The king orders for you to be imprisoned"
+ "\non charges of impersonation.");
JFrame frame2 = new JFrame();
ImageIcon icon2 = new ImageIcon("Pics/jail.png");
JLabel label2 = new JLabel(icon2);
frame2.add(label2);
frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame2.pack();
frame2.setVisible(true);
System.out.println("The day ends with you in prison, you have failed. Try Again.\n \n \n");
return false;
}
System.out.println("");
}else if(exit.equals("no")) {
System.out.println("Scared witless, you remain in your room for several hours \n before you hear a knock on your door."
+ "A servant calls: Sir Anthony, are you ok?"
+ "do you answer with: Yes I am fine? yes or no.");
String voice = sc.nextLine();
voice.toLowerCase();
if(voice.equals("yes")) {
System.out.println("The servant says: Good, well it's 12oclock and dinner is ready,\n the King was worried because you missed breakfast.");
} else if(voice.equals("no")) {
System.out.println("The servant says: I am so sorry, well, it's 12oclock and dinner is ready, \nthe King was worried because you missed
breakfast.");
}
System.out.println("You ponder if you should go to dinner; do you go?");
String dinner = sc.nextLine();
dinner.toLowerCase();
if(dinner.equals("yes")) {

} else if (dinner.equals("no")) {
System.out.println("An hour has passed and you have not moved: do you want to remain in locked in your room for the rest of the day?");
String room = sc.nextLine();
room.toLowerCase();
if (room.equals("yes")) {
System.out.println("You remain locked in your room until the day ends and you are no longer Sir Anthony, you have failed.Try again \n \n
\n ");
return false;
}else if (room.equals("no")) {
System.out.println("An hour has passed, do you go to dinner now?");
String hour = sc.nextLine();
hour.toLowerCase();
}
System.out.print("\"You pry open the door carefully and now you are looking down a limestone corridor about 12 feet high.\"\r\n" +
"+ \"You turn left along the corridor and find yourself over looking a beautiful courtyard lined with flowers of all kinds and highly
maintained bushes.\"\r\n" +
"+ \"You glance around and see stairs on the other side of the corridor\"\r\n" +
"+ \"Do you want to take the stairs to enter the dining hall? yes/no\"");
String stairs = sc.nextLine();
stairs.toLowerCase();
if(stairs.equals("no")) {
System.out.println("The day is nearly over, do you want to do nothing?");
String end = sc.nextLine();
end.toLowerCase();
if (end.equals("yes")) {
System.out.println("You return to your room and remain locked \nin your room until the day ends and you are no longer Sir
Anthony, you have failed.Try again \n \n \n ");
return false;
}
}

}
System.out.println("You decide to enter the dining hall on the ground floor.");
System.out.println("A long table fitted with bronze draperies occupies the middle of the room.");

JFrame frame1 = new JFrame();


ImageIcon icon1 = new ImageIcon("Pics/table.jpg");
JLabel label1 = new JLabel(icon1);
frame1.add(label1);
frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame1.pack();
frame1.setVisible(true);

System.out.println("A man fitted in a fine robe and crown bellows:"


+ " \n Welcome Sir Anthony! we have been missing your company.");
System.out.println("Do you try to 1- sit down somewhere or 2- stay standing.");
int sit = sc.nextInt();
System.out.println("");
System.out.println("You do so and try not to speak as your voice would almost certainly betray you.");
System.out.println("You end up only saying short phrases but the King has found you out!");
System.out.println("He says: you are not Sir Anthony, but rather an imposter!");
System.out.println("");
System.out.println("Do you 1-deny the accusation or 2-accept it?");
int acc = sc.nextInt();
if (acc==1) {
System.out.println("You deny the Kings accusation but it doesn't seem to phase him.");
}
if (acc==2) {
System.out.println("The king orders for you to be imprisoned"
+ "\non charges of impersonation.");
JFrame frame2 = new JFrame();
ImageIcon icon2 = new ImageIcon("Pics/jail.png");
JLabel label2 = new JLabel(icon2);
frame2.add(label2);
frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame2.pack();
frame2.setVisible(true);
System.out.println("The day ends with you in prison, you have failed. Try Again.\n \n \n");
return false;
}
}
System.out.println("The king declares that you must defeat a dragon to prove\nyou are a worthy Knight!");
System.out.print("Do you 1-accept the challenge or 2-cower away from the challenge?");
int imp = sc.nextInt();
//fight or flight
if (imp==1) {
System.out.println("The King smiles and says: \nGood, now bring me back the head of a dragon and you will have proved yourself.");
System.out.println("You set off back to your room and summon the servant to get your armour and sword.");
System.out.println("");
System.out.println("After being fitted with your gear and weapons, \ndo you ask the servant where you can find a dragon? yes/no");
String askthe = sc1.nextLine();
askthe.toLowerCase();
if(askthe.equals("yes")) {
System.out.println("The servant says: legend has it that there is a human eating dragon 10 miles north of here.");
}
if(askthe.equals("no")) {
System.out.println("You must find where a dragon is, who do you ask? Enter a person.");
String someelse=sc1.nextLine();
System.out.println("");
System.out.println("You find and ask "+someelse+" where a dragon is.");
System.out.println("The "+someelse+" says: legend has it that there is a man eating dragon 10 miles north of here.");
System.out.println("");
}
System.out.println("you shiver but decide to follow through with your word");
System.out.println("You pack your bags, mount your horse, and set off to slay the dragon.");
System.out.println("");
JFrame frame2 = new JFrame();
ImageIcon icon2 = new ImageIcon("Pics/countryside.jpg");
JLabel label2 = new JLabel(icon2);
frame2.add(label2);
frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame2.pack();
frame2.setVisible(true);
System.out.println("You do quick calculations in your head: it will take about a hour to arrive at the dragon.");
System.out.println("After about an hour, you see a red dragon standing outside of his cave.");
System.out.println("Fear courses through you but you push on.");
JFrame frame3 = new JFrame();
ImageIcon icon3 = new ImageIcon("Pics/dragon.jpg");
JLabel label3 = new JLabel(icon3);
frame3.add(label3);
frame3.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame3.pack();
frame3.setVisible(true);
System.out.println("The Dragon doesn't seem to see you.");
System.out.println("You gallop closer to the dragon and now are around a 10 yards from its cave.");
System.out.println("");
System.out.println("You draw your sword and attempt to sneak up on the dragon!");
System.out.println("");
System.out.println("The dragon whips his head around, stopping you in your tracks.");
System.out.println("A jet of flame erupts from the dragon's mouth and you duck.");
System.out.println("Everything seems to be in slow motion.");
System.out.println("Choose to: 1- Chop at the dragon's neck or 2-stab at the dragon's neck.");
int attack= sc.nextInt();
if (attack==1) {
System.out.println("You grip your sword with two hands and slash the dragon's neck.");
System.out.println("Your sword tears the dragons scales off and cuts his flesh.");
}else {
System.out.println("You grip your sword with two hands and stab the dragon's neck.");
System.out.println("Your sword slips between his scales and drives into his neck.");
}
System.out.println("");
System.out.println("The dragon staggers back roaring. ");
System.out.println("The dragon is badly injured and he violently knocks you over with his paw.");
System.out.println("You collapse and break your nondominant hand.");
System.out.println("");
System.out.println("You scramble to your feet and attack again.");
System.out.println("Choose to: 1- Chop at the dragon's neck or 2-stab at the dragon's neck.");
int attack2= sc.nextInt();
if (attack2==1) {
System.out.println("You grip your sword with two hands and slash the dragon's weakened neck.");
System.out.println("Your");
}else {
System.out.println("You grip your sword with two hands and stab the dragon's neck.");
System.out.println("Your sword drives into the dragon's weakened neck.");
}
JFrame frame4 = new JFrame();
ImageIcon icon4 = new ImageIcon("Pics/fighting dragon.jpg");
JLabel label4 = new JLabel(icon4);
frame4.add(label4);
frame4.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame4.pack();
frame4.setVisible(true);
System.out.println("The dragon thrashes and lunges at you with its jaws.");
System.out.println("Do you stab at it's heart? yes/no");
String stab= sc1.nextLine();
stab.toLowerCase();
System.out.println("");
if (stab.equals("no")){
System.out.println("");
System.out.println("");
System.out.println("You stand frozen in fear and die. You have failed the knight path. Try again \\n\\n\\n\");");
return false;
}
System.out.println("You thrust your sword hilt deep into the dragon's heart.");
System.out.println("The dragon falls to the ground, you have killed it!");
JFrame frame5 = new JFrame();
ImageIcon icon5 = new ImageIcon("Pics/deaddragon.jpg");
JLabel label5 = new JLabel(icon5);
frame5.add(label5);
frame5.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame5.pack();
frame5.setVisible(true);
System.out.println("");
System.out.println("You journey back to the King with the dragon's head.");
System.out.println("You arrive at the castle and are welcomed by the King who proclaims you the Knight Sir Anthony!");
System.out.println("Congratulations! you have completed the knight level.");
System.out.println("");
System.out.println("");
System.out.println("");
}
if(imp==2) {
System.out.println("The King's mouth spreads into a broad smile");
System.out.println("So you aren't Sir Anthony...Take him to the dungeons");
JFrame frame2 = new JFrame();
ImageIcon icon2 = new ImageIcon("Pics/jail.png");
JLabel label2 = new JLabel(icon2);
frame2.add(label2);
frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame2.pack();
frame2.setVisible(true);
System.out.print("You are taken to the prison, the day ends, and you have failed. Try again \n\n\n");
return false;
}
return true;
}
public static boolean sonic (String name) {
Scanner sc = new Scanner (System.in);
System.out.println("Today you are speedy Sonic");
System.out.println("");
System.out.println("please make sure to answer questions as directed; if the question in a yes or no question enter yes or no \nIf the question asks you to decide on
two actions, enter 1 or 2, with 1 being the first action and two being the second.");
System.out.println("");
System.out.println("");
System.out.println("");

System.out.println("You wake up as Sonic the Hedgehog.");


System.out.println("You are amazed, you feel so light and fast. ");
System.out.println("A red fury animal approaches.");
JFrame frame = new JFrame();
ImageIcon icon = new ImageIcon("Pics/sonic.jpg");
JLabel label = new JLabel(icon);
frame.add(label);
frame.setDefaultCloseOperation
(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
System.out.print("enter 1 to proceed: ");
int x = sc.nextInt();
do {
if(x==1) {
System.out.println("\n\nYou meet knuckles, he tells you about a competition you are in.");
System.out.println("Knuckes is your bestfriend!");
System.out.println("You must defeat Dr eggman by collecting the most coins on three different islands");
System.out.print("enter 1 to meet Dr Eggman: ");
} else {
System.out.print("enter 1 to proceed: ");
}
x = sc.nextInt();
} while(x!=1);

JFrame frame1 = new JFrame();


ImageIcon icon1 = new ImageIcon("Pics/sonicEnemy.png");
JLabel label1 = new JLabel(icon1);
frame1.add(label1);
frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame1.pack();
frame1.setVisible(true);
System.out.println("\n\nThis is Dr eggman, he is evil and must be defeated!");
System.out.println("He laughs at you and insults you!");
System.out.print("enter 1 to go to the competition: ");
do {
x=sc.nextInt();
if(x!=1) {
System.out.print("enter one to proceed: ");
}
}while(x!=1);
System.out.println("\n\nThis is where the competition will take place");
JFrame frame2 = new JFrame();
ImageIcon icon2 = new ImageIcon("Pics/sonicbackground.jpg");
JLabel label2 = new JLabel(icon2);
frame2.add(label2);
frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame2.pack();
frame2.setVisible(true);
System.out.println("There are three islands, the Aztec land, the Mountains, and the Forest");
System.out.println("Each of the islands has coins that need to be collected, collect them before Dr Eggman to win the competition!");
System.out.print("which island do you want to go to first? \nenter 1 for the Aztec, 2 for the Mountains, 3 for the Forest: ");
do {
x=sc.nextInt();
if(!(x>=1&&x<=3)) {
System.out.print("enter 1, 2 or, 3: ");
}
} while(!(x>=1&&x<=3));
return islands(x);
}
public static boolean islands(int island) {
Scanner input = new Scanner(System.in);
int x;
ArrayList<String> islandNames = new ArrayList<String>();
islandNames.add("Aztec Land");
islandNames.add("Mountains");
islandNames.add("Forest");
System.out.println("\n\nyou are in the "+ islandNames.get(island-1));
System.out.println("you find 50 coins");
JFrame frame = new JFrame();
ImageIcon icon = new ImageIcon("Pics/ring.png");
JLabel label = new JLabel(icon);
frame.add(label);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
islandNames.remove(island-1);
System.out.print("which island do you want to go to next? \nenter 1 for "+islandNames.get(0)+" enter 2 for "+islandNames.get(1)+": ");
do {
x=input.nextInt();
if(x==1||x==2) {
System.out.println("\n\nyou arrive at the "+islandNames.get(x-1));
islandNames.remove(x-1);
} else {
System.out.print("enter 1 or 2: ");
}
} while(x!=1&&x!=2);
System.out.println("you find a message saying, \"Dr Eggman was here, I have 70 coins, hahahaha\"");
System.out.println("you see his ship not too far from the island \ndo you want to attack his ship and steal his coins, or try to make it to the other island before
him?");
System.out.print("enter 1 for attack, 2 for island: ");
do {
x=input.nextInt();
if(x==1||x==2) {
if(x==1) {
System.out.println("\n\nyou attack Dr Eggman's boat, but he came prepared to fight!");
boolean w=SonicFight();
return w;
}
} else {
System.out.print("enter 1 or 2: ");
}
} while(x!=1&&x!=2);
System.out.println("\n\nYou zoom over the water and arrive at the last island, the "+islandNames.get(0));
System.out.println("Dr Eggman isn't far behind, so you rush to collect 30 coins, this puts you at 80 coins, 10 more than EggMan!");
System.out.print("enter 1 to proceed: ");
do {
x=input.nextInt();
if(x==1) {
System.out.println("\n\nwhile exiting the island to claim victory, you are met by Dr Eggmans ship");
System.out.println("he says \"Did you think it would be that easy?\" while pointing his cannons at you");
System.out.println("Dr Eggman clearly wants to fight you for the coins you collected, you have no other option but to engage");
System.out.println("enter 1 to proceed: ");
} else {
System.out.print("enter 1 to proceed: ");
}
} while(x!=1);
do {
x=input.nextInt();
if(x==1) {
System.out.println("\n\nwhile exiting the island to claim victory, you are met by Dr Eggmans boat");
System.out.println("he says \"Did you think it would be that easy?\" while pointing his cannons at you");
System.out.println("Dr Eggman clearly wants to fight you for the coins you collected\nYou have no other option but to engage");
System.out.println("Enter 1 to proceed: ");
} else {
System.out.print("enter 1 or 2: ");
}
} while(x!=1);
return SonicFight();
}
public static boolean SonicFight() {
JFrame frame = new JFrame();
ImageIcon icon = new ImageIcon("Pics/ship.png");
JLabel label = new JLabel(icon);
frame.add(label);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
Scanner input = new Scanner(System.in);
int EggHealth = 500;
int SonicHealth = 100;
int eggDmgDealt;
int sonicDmgDealt;
int sonicHeal;
System.out.println("\n\n______________________________________________________________________________________________________");
System.out.println("You are fighting Dr Eggman, he deals 5-10 damage per turn");
do {
System.out.println("\n\nyou have " +SonicHealth+" health");
System.out.println("Dr Eggman has " +EggHealth+" health\n");
System.out.print("enter 1 to attack (you deal 50-120 damage)\nenter 2 to heal (you heal 5-15 health)\n");
int x= input.nextInt();
if(x==1) {
sonicDmgDealt =(int) (Math.random()*70)+50;
System.out.println("you dealt "+sonicDmgDealt+" damage to Dr Eggman");
EggHealth-=sonicDmgDealt;
} else if (x==2) {
sonicHeal=(int) (Math.random()*10)+5;
System.out.println("you healed back "+sonicHeal+" health");
SonicHealth+=sonicHeal;
}
eggDmgDealt =(int) (Math.random()*5)+5;
System.out.print("Dr Eggman fired his cannons at you, he dealt "+eggDmgDealt+"
damage\n_________________________________________________________");
SonicHealth-=eggDmgDealt;
} while (SonicHealth>0 && EggHealth>0);
if(SonicHealth<=0) {
System.out.print("\nDr Eggman killed you, you lost\n\n");
return false;
} else if (EggHealth<=0) {
System.out.print("\nYou beat Dr Eggman!\n\n");
return true;
}

return false;
}

public static boolean thor (String name) {


Scanner sc = new Scanner (System.in);
System.out.println("Today you are Thor");
System.out.println("");
System.out.println("please make sure to answer questions as directed; if the question in a yes or no question enter yes or no \nIf the question asks you to decide on
two actions, enter 1 or 2, with 1 being the first action and two being the second.");
System.out.println("");
System.out.println("");
System.out.println("You are thor and the day ends. You have won!");
System.out.println("");
System.out.println("");
System.out.println("");
return true;
}
}

You might also like