'F' → Fullscreen
false. If the use survives one of the scenarios, the variable is
changed to true, which will be used to select an ending. import java.util.Scanner;
public class Program { public static void main(String[] args) { // If the player beats one of the levels, set its boolean variable to true boolean wolfpackEnding = false; boolean dragonEnding = false; int gold = 0; int twinkies = 0; Scanner input = new Scanner(System.in); }}import java.util.Scanner;
public class Program { public static void main(String[] args) {6 collapsed lines
// If the player beats one of the levels, set its boolean variable to true boolean wolfpackEnding = false; boolean dragonEnding = false; int gold = 0; int twinkies = 0; Scanner input = new Scanner(System.in);
// Prologue ----------------------------------------------------------------------------- System.out.println("Your car crashes into a tree during a thunderstorm in the woods."); System.out.println("Darkness surrounds you as thunder crashes and rain pours."); System.out.println("You spot a cave nearby, dimly lit by flashes of lightning, and run towards it for shelter."); System.out.println("Inside, you see two shadowy paths diverging deeper into the unknown...\n");
// Convert a string to lowercase using String.toLowerCase() System.out.print("Which path do you take? (left or right) -> "); String path = input.nextLine().toLowerCase();
if (path.equals("left") || path.equals("right")) { System.out.println("\nAs you move forward, you see something glimmering on the ground — a Hostess Twinkie."); System.out.println("Do you eat the Twinkie for sustenance, or will you save it for later?");
System.out.print("(take or eat) -> "); String twinkieChoice = input.nextLine().toLowerCase();
if (twinkieChoice.equals("take")) { System.out.println("You slip the Twinkie into your pocket, unsure what awaits in the darkness...\n"); twinkies += 1; } else if (twinkieChoice.equals("eat")) { System.out.println("Feeling uneasy, you eat the Twinkie to keep up your strength.\n"); } else { System.out.println("You leave the Twinkie untouched, feeling an ominous presence watching.\n"); } } }}//import java.util.Scanner;
public class Program { public static void main(String[] args) {35 collapsed lines
// If the player beats one of the levels, set its boolean variable to true boolean wolfpackEnding = false; boolean dragonEnding = false; int gold = 0; int twinkies = 0; Scanner input = new Scanner(System.in);
// Prologue ----------------------------------------------------------------------------- System.out.println("Your car crashes into a tree during a thunderstorm in the woods."); System.out.println("Darkness surrounds you as thunder crashes and rain pours."); System.out.println("You spot a cave nearby, dimly lit by flashes of lightning, and run towards it for shelter."); System.out.println("Inside, you see two shadowy paths diverging deeper into the unknown...\n");
// Convert a string to lowercase using String.toLowerCase() System.out.print("Which path do you take? (left or right) -> "); String path = input.nextLine().toLowerCase();
if (path.equals("left") || path.equals("right")) { System.out.println("\nAs you move forward, you see something glimmering on the ground — a Hostess Twinkie."); System.out.println("Do you eat the Twinkie for sustenance, or will you save it for later?");
System.out.print("(take or eat) -> "); String twinkieChoice = input.nextLine().toLowerCase();
if (twinkieChoice.equals("take")) { System.out.println("You slip the Twinkie into your pocket, unsure what awaits in the darkness...\n"); twinkies += 1; } else if (twinkieChoice.equals("eat")) { System.out.println("Feeling uneasy, you eat the Twinkie to keep up your strength.\n"); } else { System.out.println("You leave the Twinkie untouched, feeling an ominous presence watching.\n"); } }
// Caves ----------------------------------------------------------------------------- // Left -> Wolfpack // Right -> Dragon // Else -> No path chosen if (path.equals("left")) {
} else if (path.equals("right")) {
} else {
} }}//import java.util.Scanner;
public class Program { public static void main(String[] args) {35 collapsed lines
// If the player beats one of the levels, set its boolean variable to true boolean wolfpackEnding = false; boolean dragonEnding = false; int gold = 0; int twinkies = 0; Scanner input = new Scanner(System.in);
// Prologue ----------------------------------------------------------------------------- System.out.println("Your car crashes into a tree during a thunderstorm in the woods."); System.out.println("Darkness surrounds you as thunder crashes and rain pours."); System.out.println("You spot a cave nearby, dimly lit by flashes of lightning, and run towards it for shelter."); System.out.println("Inside, you see two shadowy paths diverging deeper into the unknown...\n");
// Convert a string to lowercase using String.toLowerCase() System.out.print("Which path do you take? (left or right) -> "); String path = input.nextLine().toLowerCase();
if (path.equals("left") || path.equals("right")) { System.out.println("\nAs you move forward, you see something glimmering on the ground — a Hostess Twinkie."); System.out.println("Do you eat the Twinkie for sustenance, or will you save it for later?");
System.out.print("(take or eat) -> "); String twinkieChoice = input.nextLine().toLowerCase();
if (twinkieChoice.equals("take")) { System.out.println("You slip the Twinkie into your pocket, unsure what awaits in the darkness...\n"); twinkies += 1; } else if (twinkieChoice.equals("eat")) { System.out.println("Feeling uneasy, you eat the Twinkie to keep up your strength.\n"); } else { System.out.println("You leave the Twinkie untouched, feeling an ominous presence watching.\n"); } }
// Caves ----------------------------------------------------------------------------- // Left -> Wolfpack // Right -> Dragon // Else -> No path chosen if (path.equals("left")) { System.out.println("You cautiously take the left path."); System.out.println("A few steps in, you freeze as the piercing eyes of a pack of wolves emerge from the shadows."); System.out.println("The pack leader, larger and fiercer than the others, steps forward, growling softly...\n");
System.out.print("Do you offer the pack leader your hand in peace? (yes or no) -> "); String wolfChoice = input.nextLine().toLowerCase();
if (wolfChoice.equals("yes") && twinkies >= 1) { System.out.println("As you reach out, the wolves smell the Twinkie..."); System.out.println("In a frenzy of hunger, they turn on you, and you're surrounded with no escape!\n"); } else if (wolfChoice.equals("yes")) { System.out.println("The pack leader sniffs your hand and accepts you into the fold."); System.out.println("You're given a small satchel of gold as a token of their trust."); System.out.println("You settle in with the wolves, awaiting dawn as the storm howls outside...\n"); gold += 5; wolfpackEnding = true; } else { System.out.println("Sensing your hesitation, the wolves close in, their teeth bared."); System.out.println("You feel their claws sink in, and everything goes black...\n"); } } else if (path.equals("right")) {
} else {
} }}//import java.util.Scanner;
public class Program { public static void main(String[] args) {35 collapsed lines
// If the player beats one of the levels, set its boolean variable to true boolean wolfpackEnding = false; boolean dragonEnding = false; int gold = 0; int twinkies = 0; Scanner input = new Scanner(System.in);
// Prologue ----------------------------------------------------------------------------- System.out.println("Your car crashes into a tree during a thunderstorm in the woods."); System.out.println("Darkness surrounds you as thunder crashes and rain pours."); System.out.println("You spot a cave nearby, dimly lit by flashes of lightning, and run towards it for shelter."); System.out.println("Inside, you see two shadowy paths diverging deeper into the unknown...\n");
// Convert a string to lowercase using String.toLowerCase() System.out.print("Which path do you take? (left or right) -> "); String path = input.nextLine().toLowerCase();
if (path.equals("left") || path.equals("right")) { System.out.println("\nAs you move forward, you see something glimmering on the ground — a Hostess Twinkie."); System.out.println("Do you eat the Twinkie for sustenance, or will you save it for later?");
System.out.print("(take or eat) -> "); String twinkieChoice = input.nextLine().toLowerCase();
if (twinkieChoice.equals("take")) { System.out.println("You slip the Twinkie into your pocket, unsure what awaits in the darkness...\n"); twinkies += 1; } else if (twinkieChoice.equals("eat")) { System.out.println("Feeling uneasy, you eat the Twinkie to keep up your strength.\n"); } else { System.out.println("You leave the Twinkie untouched, feeling an ominous presence watching.\n"); } }
// Caves ----------------------------------------------------------------------------- // Left -> Wolfpack // Right -> Dragon // Else -> No path chosen if (path.equals("left")) {22 collapsed lines
System.out.println("You cautiously take the left path."); System.out.println("A few steps in, you freeze as the piercing eyes of a pack of wolves emerge from the shadows."); System.out.println("The pack leader, larger and fiercer than the others, steps forward, growling softly...\n");
System.out.print("Do you offer the pack leader your hand in peace? (yes or no) -> "); String wolfChoice = input.nextLine().toLowerCase();
if (wolfChoice.equals("yes") && twinkies >= 1) { System.out.println("As you reach out, the wolves smell the Twinkie..."); System.out.println("In a frenzy of hunger, they turn on you, and you're surrounded with no escape!\n"); } else if (wolfChoice.equals("yes")) { System.out.println("The pack leader sniffs your hand and accepts you into the fold."); System.out.println("You're given a small satchel of gold as a token of their trust."); System.out.println("You settle in with the wolves, awaiting dawn as the storm howls outside...\n"); gold += 5; wolfpackEnding = true; } else { System.out.println("Sensing your hesitation, the wolves close in, their teeth bared."); System.out.println("You feel their claws sink in, and everything goes black...\n"); } } else if (path.equals("right")) { System.out.println("You take the right path, deeper into the damp, dark cave."); System.out.println("Suddenly, a rotten, smoky smell fills the air. A massive dragon with dull, greedy eyes looms in the shadows."); System.out.println("The dragon sniffs the air and sneers, 'Did you bring me something sweet?'");
System.out.print("Do you offer him a treat? (yes or no) -> "); String dragonChoice = input.nextLine().toLowerCase();
if (dragonChoice.equals("yes") && twinkies >= 1) { System.out.println("The dragon's eyes widen as he devours the Twinkie. 'Delicious!' he roars."); System.out.println("In gratitude, he hands you a pile of gold coins.\n");
System.out.print("How much gold do you take? -> "); int goldAmount = input.nextInt();
if (goldAmount > 0 && goldAmount <= 100) { System.out.println("The dragon grunts approval, allowing you to take the gold...\n"); gold += goldAmount; } else if (goldAmount > 100) { System.out.println("The dragon's eyes narrow, and he hisses, 'Greed will get you nothing.'\n"); } else { System.out.println("The dragon, impressed by your modesty, lets you take all the gold!\n"); gold += 100000; }
dragonEnding = true; } else { System.out.println("The dragon's face darkens, and he lunges towards you!"); System.out.println("His jaws close around you as everything fades to black...\n"); } } else {
} }}//import java.util.Scanner;
public class Program { public static void main(String[] args) {35 collapsed lines
// If the player beats one of the levels, set its boolean variable to true boolean wolfpackEnding = false; boolean dragonEnding = false; int gold = 0; int twinkies = 0; Scanner input = new Scanner(System.in);
// Prologue ----------------------------------------------------------------------------- System.out.println("Your car crashes into a tree during a thunderstorm in the woods."); System.out.println("Darkness surrounds you as thunder crashes and rain pours."); System.out.println("You spot a cave nearby, dimly lit by flashes of lightning, and run towards it for shelter."); System.out.println("Inside, you see two shadowy paths diverging deeper into the unknown...\n");
// Convert a string to lowercase using String.toLowerCase() System.out.print("Which path do you take? (left or right) -> "); String path = input.nextLine().toLowerCase();
if (path.equals("left") || path.equals("right")) { System.out.println("\nAs you move forward, you see something glimmering on the ground — a Hostess Twinkie."); System.out.println("Do you eat the Twinkie for sustenance, or will you save it for later?");
System.out.print("(take or eat) -> "); String twinkieChoice = input.nextLine().toLowerCase();
if (twinkieChoice.equals("take")) { System.out.println("You slip the Twinkie into your pocket, unsure what awaits in the darkness...\n"); twinkies += 1; } else if (twinkieChoice.equals("eat")) { System.out.println("Feeling uneasy, you eat the Twinkie to keep up your strength.\n"); } else { System.out.println("You leave the Twinkie untouched, feeling an ominous presence watching.\n"); } }
// Caves ----------------------------------------------------------------------------- // Left -> Wolfpack // Right -> Dragon // Else -> No path chosen if (path.equals("left")) {22 collapsed lines
System.out.println("You cautiously take the left path."); System.out.println("A few steps in, you freeze as the piercing eyes of a pack of wolves emerge from the shadows."); System.out.println("The pack leader, larger and fiercer than the others, steps forward, growling softly...\n");
System.out.print("Do you offer the pack leader your hand in peace? (yes or no) -> "); String wolfChoice = input.nextLine().toLowerCase();
if (wolfChoice.equals("yes") && twinkies >= 1) { System.out.println("As you reach out, the wolves smell the Twinkie..."); System.out.println("In a frenzy of hunger, they turn on you, and you're surrounded with no escape!\n"); } else if (wolfChoice.equals("yes")) { System.out.println("The pack leader sniffs your hand and accepts you into the fold."); System.out.println("You're given a small satchel of gold as a token of their trust."); System.out.println("You settle in with the wolves, awaiting dawn as the storm howls outside...\n"); gold += 5; wolfpackEnding = true; } else { System.out.println("Sensing your hesitation, the wolves close in, their teeth bared."); System.out.println("You feel their claws sink in, and everything goes black...\n"); } } else if (path.equals("right")) {32 collapsed lines
System.out.println("You take the right path, deeper into the damp, dark cave."); System.out.println("Suddenly, a rotten, smoky smell fills the air. A massive dragon with dull, greedy eyes looms in the shadows."); System.out.println("The dragon sniffs the air and sneers, 'Did you bring me something sweet?'");
System.out.print("Do you offer him a treat? (yes or no) -> "); String dragonChoice = input.nextLine().toLowerCase();
if (dragonChoice.equals("yes") && twinkies >= 1) { System.out.println("The dragon's eyes widen as he devours the Twinkie. 'Delicious!' he roars."); System.out.println("In gratitude, he hands you a pile of gold coins.\n");
System.out.print("How much gold do you take? -> "); int goldAmount = input.nextInt();
if (goldAmount > 0 && goldAmount <= 100) { System.out.println("The dragon grunts approval, allowing you to take the gold...\n"); gold += goldAmount; } else if (goldAmount > 100) { System.out.println("The dragon's eyes narrow, and he hisses, 'Greed will get you nothing.'\n"); } else { System.out.println("The dragon, impressed by your modesty, lets you take all the gold!\n"); gold += 100000; }
dragonEnding = true; } else { System.out.println("The dragon's face darkens, and he lunges towards you!"); System.out.println("His jaws close around you as everything fades to black...\n"); } } else { System.out.println("You hesitate, feeling the storm grow stronger as lightning flashes around you."); System.out.println("Suddenly, a bolt strikes nearby, and you fall to the ground, darkness closing in.\n"); } }}//import java.util.Scanner;
public class Program { public static void main(String[] args) {102 collapsed lines
// If the player beats one of the levels, set its boolean variable to true boolean wolfpackEnding = false; boolean dragonEnding = false; int gold = 0; int twinkies = 0; Scanner input = new Scanner(System.in);
// Prologue ----------------------------------------------------------------------------- System.out.println("Your car crashes into a tree during a thunderstorm in the woods."); System.out.println("Darkness surrounds you as thunder crashes and rain pours."); System.out.println("You spot a cave nearby, dimly lit by flashes of lightning, and run towards it for shelter."); System.out.println("Inside, you see two shadowy paths diverging deeper into the unknown...\n");
// Convert a string to lowercase using String.toLowerCase() System.out.print("Which path do you take? (left or right) -> "); String path = input.nextLine().toLowerCase();
if (path.equals("left") || path.equals("right")) { System.out.println("\nAs you move forward, you see something glimmering on the ground — a Hostess Twinkie."); System.out.println("Do you eat the Twinkie for sustenance, or will you save it for later?");
System.out.print("(take or eat) -> "); String twinkieChoice = input.nextLine().toLowerCase();
if (twinkieChoice.equals("take")) { System.out.println("You slip the Twinkie into your pocket, unsure what awaits in the darkness...\n"); twinkies += 1; } else if (twinkieChoice.equals("eat")) { System.out.println("Feeling uneasy, you eat the Twinkie to keep up your strength.\n"); } else { System.out.println("You leave the Twinkie untouched, feeling an ominous presence watching.\n"); } }
// Caves ----------------------------------------------------------------------------- // Left -> Wolfpack // Right -> Dragon // Else -> No path chosen if (path.equals("left")) { System.out.println("You cautiously take the left path."); System.out.println("A few steps in, you freeze as the piercing eyes of a pack of wolves emerge from the shadows."); System.out.println("The pack leader, larger and fiercer than the others, steps forward, growling softly...\n");
System.out.print("Do you offer the pack leader your hand in peace? (yes or no) -> "); String wolfChoice = input.nextLine().toLowerCase();
if (wolfChoice.equals("yes") && twinkies >= 1) { System.out.println("As you reach out, the wolves smell the Twinkie..."); System.out.println("In a frenzy of hunger, they turn on you, and you're surrounded with no escape!\n"); } else if (wolfChoice.equals("yes")) { System.out.println("The pack leader sniffs your hand and accepts you into the fold."); System.out.println("You're given a small satchel of gold as a token of their trust."); System.out.println("You settle in with the wolves, awaiting dawn as the storm howls outside...\n"); gold += 5; wolfpackEnding = true; } else { System.out.println("Sensing your hesitation, the wolves close in, their teeth bared."); System.out.println("You feel their claws sink in, and everything goes black...\n"); } } else if (path.equals("right")) { System.out.println("You take the right path, deeper into the damp, dark cave."); System.out.println("Suddenly, a rotten, smoky smell fills the air. A massive dragon with dull, greedy eyes looms in the shadows."); System.out.println("The dragon sniffs the air and sneers, 'Did you bring me something sweet?'");
System.out.print("Do you offer him a treat? (yes or no) -> "); String dragonChoice = input.nextLine().toLowerCase();
if (dragonChoice.equals("yes") && twinkies >= 1) { System.out.println("The dragon's eyes widen as he devours the Twinkie. 'Delicious!' he roars."); System.out.println("In gratitude, he hands you a pile of gold coins.\n");
System.out.print("How much gold do you take? -> "); int goldAmount = input.nextInt();
if (goldAmount > 0 && goldAmount <= 100) { System.out.println("The dragon grunts approval, allowing you to take the gold...\n"); gold += goldAmount; } else if (goldAmount > 100) { System.out.println("The dragon's eyes narrow, and he hisses, 'Greed will get you nothing.'\n"); } else { System.out.println("The dragon, impressed by your modesty, lets you take all the gold!\n"); gold += 100000; }
dragonEnding = true; } else { System.out.println("The dragon's face darkens, and he lunges towards you!"); System.out.println("His jaws close around you as everything fades to black...\n"); } } else { System.out.println("You hesitate, feeling the storm grow stronger as lightning flashes around you."); System.out.println("Suddenly, a bolt strikes nearby, and you fall to the ground, darkness closing in.\n"); }
// Epilogue ----------------------------------------------------------------------------- System.out.println("-- Ending --");
if (wolfpackEnding) { System.out.println("By cuddling with the wolfpack, you weather out the storm."); System.out.println("Upon leaving the cave, they follow you, seeing you as the new pack leader."); System.out.println("You survived!!!"); } else if (dragonEnding) { System.out.println("By tempting the dragon with a delicious Hostess snack cake, you avoid his wrath."); System.out.println("He flies you back home after the storm, but not after raiding the nearest Hostess factory."); System.out.println("You survived!!!"); } else { System.out.println("Game Over!"); }
if (gold > 0) { System.out.println("You not only survived, but you found " + gold + "gold!"); } }}//Your program output should something similar to the sample output below.
Your car crashes into a tree during a thunderstorm in the woods.Darkness surrounds you as thunder crashes and rain pours.You spot a cave nearby, dimly lit by flashes of lightning, and run towards it for shelter.Inside, you see two shadowy paths diverging deeper into the unknown...
Which path do you take? (left or right) -> left
As you move forward, you see something glimmering on the ground - a Hostess Twinkie.Do you eat the Twinkie for sustenance, or will you save it for later?(take or eat) -> takeYou slip the Twinkie into your pocket, unsure what awaits in the darkness...
You cautiously take the left path.A few steps in, you freeze as the piercing eyes of a pack of wolves emerge from the shadows.The pack leader, larger and fiercer than the others, steps forward, growling softly...
Do you offer the pack leader your hand in peace? (yes or no) -> yesAs you reach out, the wolves smell the Twinkie...In a frenzy of hunger, they turn on you, and you're surrounded with no escape!
-- Ending --Game Over!You may write your reflection answers as comments at the bottom of your code.
Submit your activity and reflection answers to the appropriate dropbox.