diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..c995aa5c --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "java.debug.settings.onBuildFailureProceed": true +} \ No newline at end of file diff --git a/Castle.java b/Castle.java new file mode 100644 index 00000000..6b00a706 --- /dev/null +++ b/Castle.java @@ -0,0 +1,80 @@ +/** + * Castle class represents a special location (castle) in the Candy Land game. + * Players can enter or exit castles if they are accessible. + */ +public class Castle { + protected String name; + protected boolean isAccessible; + protected boolean isInTheCastle; + + /** + * Constructor for Castle. + * @param name The name of the castle. + */ + public Castle(String name) { + this.name = name; + this.isAccessible = true; + this.isInTheCastle = false; + } + + /** + * Gets the name of the castle. + * @return The name of the castle. + */ + public String getName() { + return name; + } + + /** + * Checks if the castle is accessible. + * @return True if accessible, false otherwise. + */ + public boolean isAccessible() { + return isAccessible; + } + + /** + * Sets whether the castle is accessible. + * @param accessible True to make accessible, false to block access. + */ + public void setAccessible(boolean accessible) { + this.isAccessible = accessible; + } + + /** + * Checks if the player is currently inside the castle. + * @return True if inside, false otherwise. + */ + public boolean isInTheCastle() { + return isInTheCastle; + } + + + /** + * Handles the logic for entering the castle. + * Player can only enter if the castle is accessible and they are not already inside. + */ + public void enter() { + if (isAccessible && !isInTheCastle) { + isInTheCastle = true; + System.out.println("You have entered the " + name + "."); + } else if (isInTheCastle) { + System.out.println("You are already in the " + name + "."); + } else { + System.out.println("The " + name + " is not accessible right now."); + } + } + + /** + * Handles the logic for exiting the castle. + * Player can only exit if they are currently inside. + */ + public void exit() { + if (isInTheCastle) { + isInTheCastle = false; + System.out.println("You have exited the " + name + "."); + } else { + System.out.println("You are not in the " + name + " to exit."); + } + } +} diff --git a/FullSpinner.java b/FullSpinner.java new file mode 100644 index 00000000..f3714366 --- /dev/null +++ b/FullSpinner.java @@ -0,0 +1,54 @@ +import java.util.ArrayList; +import java.util.Random; + +public class FullSpinner { + private ArrayList parts; + + public FullSpinner(){ + this.parts = new ArrayList<>(); + } + + +public void addParts(){ + parts.add(new SpinnerPart("Red")); + parts.add(new SpinnerPart("Purple")); + parts.add(new SpinnerPart("Yellow")); + parts.add(new SpinnerPart("Blue")); + parts.add(new SpinnerPart("Orange")); + parts.add(new SpinnerPart("Green")); + + //adding my candies + + parts.add(new SpinnerPart("Ice cream")); + parts.add(new SpinnerPart("Peanut")); + parts.add(new SpinnerPart("Lollipop")); + parts.add(new SpinnerPart("Licorice")); + + +} +//i'll need to add an override method to a to string + +// @Override +// public void toString(){ +// return "FullSpinner has a "; +// } + +public String spin(){ + int Index = random.nextInt(parts.size()); //is it not recognizing random? + String part = parts.get(Index).toString(); //can i not use somethig tat is part of a method in another class + return part ;//the thing that + //how could i do this without a getOutput variable + + + // just declare a variable that would pick a random number from the number of stuff in the arraylist + //and then just get it to spit out that index + + +} +public static void main(String[] args) { + FullSpinner spinner = new FullSpinner(); + spinner.addParts(); + System.out.println(spinner); +} + +} diff --git a/KingKandyCastle.java b/KingKandyCastle.java new file mode 100644 index 00000000..419853b5 --- /dev/null +++ b/KingKandyCastle.java @@ -0,0 +1,41 @@ +import java.util.Scanner; + +/** + * Represents King Kandy's Castle, the final destination in Candy Land. + * Players can only enter if they have the required key from Frosted Palace. + */ +public class KingKandyCastle extends Castle { + private boolean hasKeyToKingKandy; + + /** + * Constructor. + */ + public KingKandyCastle() { + super("King Kandy's Castle"); + this.hasKeyToKingKandy = false; + } + + /** + * Sets whether the player has the key to King Kandy's Castle. + * @param hasKey true if the player has the key, false otherwise. + */ + public void setHasKeyToKingKandy(boolean hasKey) { + this.hasKeyToKingKandy = hasKey; + } + + /** + * Attempts to enter King Kandy's Castle. + * Only allows entry if the player has the King Kandy key. + */ + public void attemptEntry() { + if (hasKeyToKingKandy) { // <<< use the local boolean here + Scanner scanner = new Scanner(System.in); + System.out.println("\n You have reached King Kandy's Castle!"); + System.out.print("Press Enter to step inside and claim your victory..."); + scanner.nextLine(); + System.out.println("\n Congratulations! You have WON the game!"); + } else { + System.out.println("\n You cannot enter King Kandy's Castle yet! You need the final key!"); + } + } +} diff --git a/LicoriceLagoon.java b/LicoriceLagoon.java new file mode 100644 index 00000000..1aa3b643 --- /dev/null +++ b/LicoriceLagoon.java @@ -0,0 +1,79 @@ +import java.util.ArrayList; +import java.util.Scanner; + + + } + + public int guessNumber(){ + return this.selectNumber; + /* + * When you land in the lagoon you will need to guess a number from 1 to 10. + * If you guess it incorectly, you will get a random trivia question. + * Array List of the trivia questions. + */ + } + + public Boolean proceedTrivia(){ + /* + * If number guessed is incorrect proceed to trivia questions. + */ + return this.trivia; + } + + public String triviaQuestions(){ + /* + * Random questions in an Array List + */ + questions = new ArrayList<>(); + + return this.triviaQuestions; + } + + public String proceedOrNot(){ + /* + * If trivia questions wrongly answered then player loses + and therefore proceeds through the long way and does not get directly + relocated to were the catsles are. + * If correctly answered then player gets relocated to the first castle. + */ + return this.acceptance; + +public class LicoriceLagoon extends PathPlaces{ + + public LicoriceLagoon(String name, int playerInput, ArrayList triviaQuestions) { + super (name, playerInput, triviaQuestions); + } + public void printPathName() { + /* + * When you land in the lagoon you will need to guess a number. + * If you guess it incorectly, you will get a random trivia question. + * ArrayList of the trivia questions. + */ + System.out.println("You have entered the Licorice Lagoon! You are ready to begin your next challenge. From 2000 - 5000, how many licorice make up the Lagoon?"); + + Scanner scanner = new Scanner(System.in); + int playerInput = scanner.nextInt(); + System.out.println(triviaQuestions.size()); + String question = triviaQuestions.get(this.random.nextInt (triviaQuestions.size())); + + if (playerInput >= 2000 && playerInput <= 5000) { + if (playerInput % 2 != 0) { + System.out.println("Aha! I see you have done your research! " + playerInput + " licorice make up the Lagoon. You can advance to the next tile."); + } else { + System.out.println("Oh no! " + playerInput + " is not the correct number of licorice that make up the Lagoon. You must complete the following trivia question to move to the next tile." + question); + + System.out.println("Well done! You have completed the challenge and may progress to the next tile."); + } + } else { + throw new IllegalArgumentException("Please enter a number between 2000 and 5000."); + } + + } + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + +} + LicoriceLagoon llTest = new LicoriceLagoon("Licorice Lagoon", 2003, PathPlaces.triviaQuestions); + llTest.printPathName(); + } + } \ No newline at end of file diff --git a/LollipopCastle.java b/LollipopCastle.java new file mode 100644 index 00000000..352241a3 --- /dev/null +++ b/LollipopCastle.java @@ -0,0 +1,71 @@ +import java.util.Scanner; + +/** + * Represents the Lollipop Castle in Candy Land. + * Players must complete a jumping challenge to proceed toward the Frosted Palace. + */ +public class LollipopCastle extends Castle { + private boolean hasKeyToFrostedPalace; + private double height; + + /** + * Constructs a new Lollipop Castle. + */ + public LollipopCastle() { + super("Lollipop Castle"); + this.hasKeyToFrostedPalace = false; + this.height = 0; + } + + /** + * Starts the jumping challenge at Lollipop Castle. + * If the player jumps between 200–400, they succeed and teleport closer to the Frosted Palace. + * Even if they fail the jump, they still receive the key but must take a longer route. + * + * @param hasKey A boolean indicating if the player has the required key to enter. + */ + public void startChallenge(boolean hasKey) { + if (!hasKey) { + System.out.println("You cannot enter Lollipop Castle without the key to the Frosted Palace."); + return; + } + + Scanner scanner = new Scanner(System.in); + System.out.println("Welcome to Lollipop Castle!"); + System.out.println("Jump too low = caramel abyss. Jump too high = sucked into space."); + + System.out.print("Enter your jump height (100–500): "); + if (scanner.hasNextDouble()) { + height = scanner.nextDouble(); + if (height < 100 || height > 500) { + System.out.println("Invalid jump height. Must be between 100 and 500."); + } else { + if (height >= 200 && height <= 400) { + System.out.println("Perfect jump! You land safely on the other side."); + player.setPositionIndex(45); + System.out.println("You are teleported to the Frosted Palace!"); + } else if (height < 200) { + System.out.println("Too low! You fall into the caramel abyss... Taking the long route to the Frosted Palace."); + } else { + System.out.println("Too high! You’re sucked into the void of space... Taking the long route to the Frosted Palace."); + } + } + } else { + System.out.println("Please enter a valid number."); + scanner.next(); // Clear invalid input + } + + // Regardless of success or failure, the player gets the key + this.hasKeyToFrostedPalace = true; + this.isAccessible = true; + } + + /** + * Checks if the player has earned the key to the Frosted Palace. + * + * @return true if the player has the key, false otherwise. + */ + public boolean hasKeyToFrostedPalace() { + return hasKeyToFrostedPalace; + } +} diff --git a/Map.java b/Map.java new file mode 100644 index 00000000..0caa67e3 --- /dev/null +++ b/Map.java @@ -0,0 +1,158 @@ +import java.util.ArrayList; + +public class Map { + private Boolean position ; + private String colorBlocks; + private String playerPosition; + + /* Constructor */ + public Map(Boolean position, String colorBlocks, String playerPosition){ + this.position = position; + this.colorBlocks = colorBlocks; + this.playerPosition = playerPosition; + } + + + /* + * Index of each block of the map. + */ + + public Boolean indexPosition(){ + return this.position; + } + + /* + * Tiles of the map. + */ + + public String gameBlocks(){ + return this.colorBlocks; + } + + /* + * Name of the tile (color and index) which the player is in. + */ + + public String playerPosition(){ + return this.playerPosition; + } + + + /* + * Establishing the player position, color blocks and index position of the tiles in the map. + */ + + public void setPlayerPosition(String playerPosition) { + this.playerPosition = playerPosition; + } + + public void setColorBlocks(String colorBlocks) { + this.colorBlocks = colorBlocks; + } + + + public void setIndexPosition(Boolean position) { + this.position = position; + } + + public static void main(String[] args){ + ArrayList map = new ArrayList<>(); + FullSpinner spinner = new FullSpinner(); + spinner.addParts(); + String[] colors = {"Red", "Purple", "Yellow", "Blue", "Orange", "Green"}; + + for (int i = 0; i < 60; i++){ + String color = colors[i % colors.length]; + Map tiles = new Map(false, color, "None"); + map.add(tiles); + } + + map.get(playerIndex).setIndexPosition(true); + map.get(playerIndex).setPlayerPosition("Player 1"); + + String spinColor = spinner.spin(); + System.out.println("Spinner result: " + spinColor); + + int newIndex = -1; + for (int i = playerIndex + 1; i < map.size(); i++){ + if (map.get(i).gameBlocks().equalsIgnoreCase(spinColor)){ + newIndex = i; + break; + } + } + + if (newIndex != -1){ + map.get(playerIndex).setIndexPosition(false); + map.get(playerIndex).setPlayerPosition("None"); + + + } + + } +} + + + public void setIndexPosition(Boolean position) { + this.position = position; + } + + public static void main(String[] args){ + /* + * Map array list. + */ + ArrayList map = new ArrayList<>(); + FullSpinner spinner = new FullSpinner(); + spinner.addParts(); + /* + * Setting the colors of the tiles. + */ + String[] colors = {"Red", "Purple", "Yellow", "Blue", "Orange", "Green"}; + + /* + * Loop for the map and tiles. + */ + for (int i = 0; i < 61; i++){ + String color = colors[i % colors.length]; + Map tiles = new Map(false, color, "None"); + map.add(tiles); + } + + /* + * Position and index gets set in the map. + */ + map.get(playerIndex).setIndexPosition(true); + map.get(playerIndex).setPlayerPosition(Player.getName); + + /* + * using the full spinner and spinner parts the color that was randomly selected gets printed. + */ + String spunColor = spinner.spunColor(); + System.out.println("Spinner result: " + spunColor); + + /* + * Array to make the player move to repsective tile(color) that was spun in the spinner. + */ + int currentPos = Player.getPosition(); + int newIndex = -1; + for (int i = playerIndex + 1; i < map.size(); i++){ + if (map.get(i).gameBlocks().equalsIgnoreCase(spunColor)){ + newIndex = i; + break; + } + else { + System.out.println("There are no tiles of that color ahead."); + } + /* + * + */ + if (newIndex != -1){ + map.get(playerIndex).setIndexPosition(false); + map.get(playerIndex).setPlayerPosition("None"); + map.get(newIndex).setIndexPosition(true); + map.get(newIndex).setPlayerPosition(Player.getName); + playerIndex = newIndex; + System.out.println("Player " + getName + " is now at " + playerIndex); + } + } +} + diff --git a/Nana_NutHouse.java b/Nana_NutHouse.java new file mode 100644 index 00000000..2a1be415 --- /dev/null +++ b/Nana_NutHouse.java @@ -0,0 +1,29 @@ +/** + * + */ +import java.util.Scanner; + +public class Nana_NutHouse extends PathPlaces{ + + public Nana_NutHouse(String name, int playerInput) { + super (name, playerInput); + } + + public int chocoBridgeNumber() { + if (playerInput % 2 != 0) { + System.out.println("Congratulations! Your magic number " + playerInput + " has unlocked the chocolate bridge. You advance to Licorice Lagoon!"); + } else { + System.out.println("Oh no! Your number " + playerInput + " has broken the chocolate bridge! You will have to take the long way after you answer this trivia question. Best of luck!"); + String question = triviaQuestions.get(this.random.nextInt (triviaQuestions.size())); + System.out.println("Well done! You have completed the challenge and may progress to the next tile."); + } + return this.playerInput; + } + + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + + Nana_NutHouse nanasTest = new Nana_NutHouse("Nana's House", 6); + nanasTest.chocoBridgeNumber(); + } +} diff --git a/PathPlaces.java b/PathPlaces.java new file mode 100644 index 00000000..e09b00d1 --- /dev/null +++ b/PathPlaces.java @@ -0,0 +1,57 @@ +/** + * PathPlaces is the base class that each Peppermint Forest, Licorice Lagoon, and Nana's Nut House inherit from in this game. + * Each location, or Path Place, has a name and a number guessing challenge. If correct the player proceeds and if incorrect, the player must answer a trivia question stored in triviaQuestions. The player will then proceed upon answering the question. + * The following imports, a scanner and an arraylist are necessary for PathPlaces. +*/ + +import java.util.ArrayList; +import java.util.Random; +import java.util.Scanner; +/** + * The following attributes are for Path Places and each subclass; Peppermint Forest, Nana's Nut House, and Licorice Lagoon. The trivia questions are stored in an Array List. +*/ + +public class PathPlaces { + protected String name; + protected int playerInput; + protected ArrayList triviaQuestions; + protected Random random; +/** + * The following constructor includes these paramenters: + * @param name + * @param playerInput + */ +public PathPlaces(String name, int playerInput) { + this.name = name; + this.playerInput = playerInput; + this.triviaQuestions = new ArrayList<>(); + this.random = new Random(); +} +/** + * printPathName will print the name of each subclass. + * getPathName obtains the name of the subclass. + * addString are the questions stored in the array list triviaQuestions. Initially a hashtable was going to be used, but for simplicity purposes an array list seemed to work better at this time. + */ +public void printPathName() { + System.out.println("Welcome to " + this.name + "!"); +} + +public String getPathName() { + return this.name; +} +/* +* Random questions in an Array List +*/ +public void addString(String str) { + this.triviaQuestions.add("What is the one secret to Nana's bizcocho recipe?"); + this.triviaQuestions.add("What is Queen Kandy's favorite color?"); + this.triviaQuestions.add("What animal does Queen Kandy dream of having in her Castle?"); +} +/** + * Main Method + * @param args + */ +public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); +} +} \ No newline at end of file diff --git a/PeppermintForest.java b/PeppermintForest.java new file mode 100644 index 00000000..ed1c1557 --- /dev/null +++ b/PeppermintForest.java @@ -0,0 +1,37 @@ +import java.util.ArrayList; +import java.util.Scanner; + +public class PeppermintForest extends PathPlaces{ + + public PeppermintForest(String name, int playerInput) { + super(name, playerInput); + } + + public void printPathName() { + System.out.println("You have entered the Peppermint Forest! With the aroma of peppermint candy canes, mint chocolate chip, and sugar, you are ready to begin your first challenge. From 1 - 10000, how many peppermint candy canes make up the Peppermint Forest?"); + + Scanner scanner = new Scanner(System.in); + int playerInput = scanner.nextInt(); +/* +* If trivia questions wrongly answered then player loses and therefore proceeds through the long way and does not get directly relocated to were the catsles are. +* If correctly answered then player gets relocated to the first castle. +*/ + if (playerInput >= 1 && playerInput <= 10000) { + if (playerInput % 2 != 0) { + System.out.println("Way to go! Exactly " + playerInput + " peppermint candy canes make up the Peppermint Forest! You can advance to the next tile. Remember to grab a candy cane on your way out."); + } else { + System.out.println("Unfortunately " + playerInput + " is not the correct amount of peppermint candy canes that make up the Peppermint Forest. You can continue on your path, but you may not take a peppermint candy cane. Good luck!"); + } + } else { + throw new IllegalArgumentException("Please enter a number between 1 and 10000."); + } + } + + } + + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + + PeppermintForest pfTest = new PeppermintForest("PF", 234); + pfTest.printPathName(); + } \ No newline at end of file diff --git a/Player.java b/Player.java new file mode 100644 index 00000000..c2cd8e5b --- /dev/null +++ b/Player.java @@ -0,0 +1,80 @@ +import java.util.ArrayList; +import java.util.Scanner; + + +public class Player { + private String name; + private String color; + private String shape; + private int positionIndex; + private String currPosition; + private int lives; + private Boolean isAlive; + private ArrayList tiles; //only added so i could test my move method , this arraylist should be declared within maybe a tile class or within the map class + + + + + public Player(String name,String color, String shape,int position){ + this.name = name ; + this.currPosition = "red";//if we have all the points on the map that the player can be at set up as an arraylist then im setting this to 0 as statring position + this.positionIndex = 0; + this.lives = 3; + this.isAlive = true; + this.tiles = new ArrayList<>(); + } + + public String enterName(){ + Scanner sc = new Scanner(System.in); + System.out.println("Enter your name:"); + String name = sc.nextLine(); + return name; + + } + + + public String getName(){ + return name; + } + + public int getPositionIndex(){ + return positionIndex; + } + + public void setPositionIndex(int positionIndex){ + this.positionIndex=positionIndex;//setter cause this is the only one we need to manipulate + } + //have a move method - while loop + + + + public String getCurrPosition() { + return currPosition; + } + + public void move(String SpinnerPart, ArrayList tiles){ + this.positionIndex+=1; / + if (this.positionIndex >= tiles.size()) { + this.positionIndex = tiles.size() - 1; + } + + while(this.positionIndex < tiles.size() && !tiles.get(this.positionIndex).equals(SpinnerPart)){//this just checks if the color of the tile tjat we are on is the same as the out put of our spinner and if it isn't, then the player keeps moving one tile forward + this.positionIndex+=1; + } + this.currPosition = SpinnerPart; + } + + + + + + + + + + + + + +} + diff --git a/QueenKandyCastle.java b/QueenKandyCastle.java new file mode 100644 index 00000000..a7d2b8ea --- /dev/null +++ b/QueenKandyCastle.java @@ -0,0 +1,14 @@ +public class QueenKandyCastle extends Castle { + + // Constructor + public QueenKandyCastle() { + super("Queen Kandy's Castle"); + } + + // Method to start final challenge (or ending) + public void startChallenge() { + // 1. Print final success message + System.out.println("🎉 Congratulations! You’ve reached Queen Kandy’s Castle."); + System.out.println("🏰 YOU WIN! YOU MADE IT TO THE END OF THE GAME! 🎉"); + } +} diff --git a/SpinnerPart.java b/SpinnerPart.java new file mode 100644 index 00000000..ed18635c --- /dev/null +++ b/SpinnerPart.java @@ -0,0 +1,45 @@ +import java.util.ArrayList; + + +public class SpinnerPart { + //text based version of the spinner + // private output; + //this could be a string or an int - and i need to remember the abstraction way to fix that + // private ArrayList Parts; + private String Item; + private String Color; + + + //initialize the constructor + // public Spinner(ArrayList Parts){ + // this.Parts = new ArrayList<>(); + // } +//overloading + public SpinnerPart(String Color) { + this.Color = Color; +} + public SpinnerPart(String Color, String Item) { + this.Color = Color; + this.Item = Item; + } + + public String getColor(){ + return Color; + } + + + + public String getItem(){ + return Item; + } + + + + + + +} + + + + diff --git a/architechture diagram.png b/architechture diagram.png new file mode 100644 index 00000000..0abb5e77 Binary files /dev/null and b/architechture diagram.png differ diff --git a/frostedPalace.java b/frostedPalace.java new file mode 100644 index 00000000..50af8a2e --- /dev/null +++ b/frostedPalace.java @@ -0,0 +1,126 @@ +import java.util.Random; +import java.util.Scanner; + +/** + * Represents the Frosted Palace in Candy Land. + * Players must guess a number to earn the key to King Kandy's Castle. + * Entry is only allowed if the player has the Frosted Palace key. + */ +public class FrostedPalace extends Castle { + + private int correctNumber; + private int temperature; + private boolean hasKeyToKingKandy; + private boolean teleportedToKingKandy; + + /** + * Constructs a new Frosted Palace. + * Initializes challenge values. + */ + public FrostedPalace() { + super("Frosted Palace"); + this.correctNumber = generateRandomNumber(); + this.temperature = 98; + this.hasKeyToKingKandy = false; + this.teleportedToKingKandy = false; + } + + /** + * Attempts to enter the Frosted Palace. + * Only allows entry if the player has the key from Lollipop Castle. + * + * @param hasKeyFromLollipopCastle true if player has the key, false otherwise + */ + public void enter(boolean hasKeyFromLollipopCastle) { + if (hasKeyFromLollipopCastle) { + System.out.println("\nYou used the key to enter the Frosted Palace!"); + startChallenge(); + } else { + System.out.println("\nYou cannot enter the Frosted Palace without the key from Lollipop Castle!"); + } + } + + /** + * Starts the freezing number-guessing challenge. + * If guessed correctly on the first try, player is teleported to King Kandy. + * Otherwise, the player either gets the key after more trials or freezes to death. + */ + private void startChallenge() { + Scanner scanner = new Scanner(System.in); + System.out.println("\nWelcome to the Frosted Palace."); + System.out.println("Guess the number between 1 and 10. It's freezing in here!"); + + boolean firstAttempt = true; + + while (temperature > 0 && !hasKeyToKingKandy) { + System.out.print("Enter your guess: "); + if (scanner.hasNextInt()) { + int guess = scanner.nextInt(); + + if (guess == correctNumber) { + System.out.println("Correct! You survived and earned the key to King Kandy’s Castle!"); + hasKeyToKingKandy = true; + this.isAccessible = true; + + if (firstAttempt) { + System.out.println("You guessed correctly on the first try! Teleporting you directly to King Kandy’s Castle..."); + teleportedToKingKandy = true; + player.setPositionIndex(60); + } else { + System.out.println("You guessed correctly, but you must take the long way to reach King Kandy’s Castle."); + teleportedToKingKandy = false; + } + break; + } else { + temperature -= 10; + System.out.println("Incorrect! Your body temperature is now: " + temperature + "°F"); + if (checkFrozen()) { + System.out.println("You froze to death in the Frosted Palace..."); + break; + } + } + firstAttempt = false; + } else { + System.out.println("Please enter a valid number."); + scanner.next(); // clear invalid input + } + } + } + + /** + * Checks if the player has earned the key to King Kandy's Castle. + * + * @return true if the player has the key, false otherwise + */ + public boolean hasKeyToKingKandy() { + return hasKeyToKingKandy; + } + + /** + * Checks if the player teleported directly to King Kandy's Castle. + * + * @return true if teleported, false otherwise + */ + public boolean wasTeleported() { + return teleportedToKingKandy; + } + + /** + * method to check if the player froze. + * + * @return true if frozen, false otherwise + */ + private boolean checkFrozen() { + return temperature <= 0; + } + + /** + * Generates a random number between 1 and 10. + * + * @return a random number between 1 and 10 + */ + private int generateRandomNumber() { + Random rand = new Random(); + return rand.nextInt(10) + 1; + } +} diff --git a/main.java b/main.java new file mode 100644 index 00000000..e73cbd01 --- /dev/null +++ b/main.java @@ -0,0 +1,77 @@ +import java.util.Scanner; + +/** + * Main class that runs the Candy Land game. + * Guides the player through spinning, moving, and entering special locations. + */ +public class Main { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + FullSpinner spinner = new FullSpinner(); + Player player = new Player(); + + System.out.println("Welcome to Candy Land!"); + System.out.println("You are currently on Tile " + player.currentposition()); + + // Main game loop + while (player.isAlive()) { + System.out.println("\n Spin the wheel to move forward!"); + System.out.print("Press Enter to spin..."); + scanner.nextLine(); + + + + // Handle special locations + if (tile == 5) { + System.out.println("You arrived at Peppermint Forest!"); + peppermintForest peppermint = new peppermintForest(); + peppermint.enter(player); + + } else if (tile == 10) { + System.out.println("Welcome to Nana’s Nuthouse!"); + Nana_NutHousehouse nana = new Nana_NutHouse()Nuthouse(); + nana.enter(player); + + } else if (tile == 15) { + System.out.println("Entering Licorice Lagoon..."); + licoriceLagoon lagoon = new licoriceLagoon(); + lagoon.enter(player); + } else if (tile == 20) { + System.out.println("You made it to Lollipop Castle!"); + LollipopCastle lollipop = new LollipopCastle(); + lollipop.startChallenge(); + if (lollipop.getIsAlive()) { + player.obtainKeyToFrostedPalace(); + } else { + player.setAlive(false); + } + } else if (tile == 25) { + System.out.println("You’ve reached the Frosted Palace."); + frostedPalace frosted = new frostedPalace(); + frosted.startChallenge(); + if (frosted.getIsAlive()) { + player.obtainKeyToKingKandy(); + } else { + player.setAlive(false); + } + } else if (tile == 60) { + if (player.hasKeyToKingKandy()) { + System.out.println("\n You’ve arrived at King Kandy’s Castle!"); + System.out.println(" YOU WIN! Sweet victory is yours!"); + player.setHasWon(true); + } else { + System.out.println("\n You reached the castle, but you don't have the final key! Find the Frosted Palace first."); + } + } else { + System.out.println("Nothing special here. Keep moving!"); + } + + // Check if the player has died + if (!player.isAlive()) { + System.out.println("\nOh no! You didn’t survive the journey. Game Over."); + } + } + + scanner.close(); + } +}