online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code   
Language
import java.util.*; import java.lang.annotation.Retention; // AI import java.lang.annotation.RetentionPolicy; // AI import java.util.regex.Pattern; // AI class Main { public static void main(String[] args) { new coreGame(); } } ///////////////////////// // Command Setup // Commands where researched starting at: // https://stackoverflow.com/questions/27606577/best-way-to-parse-commands-in-a-java-text-based-game // and then having AI help add aliases. @Retention(RetentionPolicy.RUNTIME) // AI @interface coreCommand { String[] value(); } interface coreAction // AI { void run(String invoked, Scanner scanner); } ///////////////////////// // Game Runner public class coreGame { private static coreRoom[][] roomMap; private static coreRoom currentRoom; private static ArrayList<coreAction> actions = new ArrayList<coreAction>(); private static int locationRow, locationCol; private static coreInventory playerInventory; public static coreContext context; private static double daysLeft; private static boolean gameWon = false; public static void main(String[] args) { new coreGame(); } public coreGame() { initGame(); Scanner inputScanner = new Scanner(System.in); coreGameHelper.clearBuffer(); coreGameHelper.addLine(coreGameHelper.centerText(Color.GREEN + "Welcome to Unpunished Thinking!" + Color.RESET)); coreGameHelper.addLine(coreGameHelper.centerText(Color.YELLOW + """ You are Лебедев Коля Николаевич, an 80-year-old inventor on his final day. You have 24 hours to build a device that can pause time, even if only for a fleeting moment. At 80 years old, your once-brilliant mind has grown foggy and many secrets you once held dear have slipped away, yet your burning desire to build a time-pausing device remains undiminished. You have just 24 hours to bring it to life, and only your actions will drain the clock — your thoughts remain free. Invoke Коля's thoughts with 'think <optional context>' — they cost no time, but their answers may not always be correct.""" + Color.RESET)); coreGameHelper.setStatusBarItems( currentRoom.getRoomName(), String.format("%.3f hours", daysLeft * 24.0), String.format("%.1f/%.1f lb", playerInventory.inventoryTotalWeight(), (double)playerInventory.getMaxWeight()) ); // AI helped with string formatting. coreGameHelper.flush(); while (daysLeft > 0 && !gameWon) { String command = inputScanner.nextLine(); context.addContext(command, "user"); coreGameHelper.addLine(coreGameHelper.rightText(Color.BLUE + command + Color.RESET, coreGameHelper.getConsoleWidth() - 5)); processCommand(command); coreGameHelper.setStatusBarItems( currentRoom.getRoomName(), String.format("%.3f hours", daysLeft * 24.0), String.format("%.1f/%.1f lb", playerInventory.inventoryTotalWeight(), (double)playerInventory.getMaxWeight()) ); // AI helped with string formatting. coreGameHelper.flush(); } coreGameHelper.addNewline(); if (daysLeft > 0) { coreGameHelper.addLine(coreGameHelper.centerText(Color.GREEN + "Congratulations, Николай! Your invention is complete!" + Color.RESET)); coreGameHelper.addLine(coreGameHelper.centerText(Color.GREEN + "Thank you for playing Unpunished Thinking!" + Color.RESET)); } else { coreGameHelper.addLine(coreGameHelper.centerText(Color.RED + "Time's up! Николай, your dream remains unfinished..." + Color.RESET)); coreGameHelper.addLine(coreGameHelper.centerText(Color.RED + "Game Over." + Color.RESET)); } coreGameHelper.flush(); } private void initGame() { createBaseActions(); createRooms(); context = new coreContext(); context.addContext( "Respond in short sentences. Use plain text and no emojis. Write Russian words in Cyrillic. " + "You are Лебедев Коля Николаевич’s inner voice, a wise Soviet inventor with broken English. Guide the player step-by-step with clear commands. Puzzles may be solved in any order. " + "Game map: Balcony (sundial, planter), Bed Room (nightstand, photo gallery), North Hallway (mirrors, locked door), Living Room (kitchen table fragment, grandfather clock, projector, mirror), South Hallway (mirror), Work Room (gear box, workbench, switchboard, capacitor box), Front Porch (porch, no objects), Shrine (glass case, tuning forks), Assembly Room (assembly table). " + "Room coordinates (row,col): Bed Room (0,1) (start here); Living Room (0,2); Balcony (1,0); North Hallway (1,1); South Hallway (1,2); Front Porch (1,3); Shrine (1,4); Assembly Room (2,1); Work Room (2,2). " + "Most north: row 0 (Balcony); most south: row 2 (Shrine); most west: col 0 (Assembly Room / Work Room); most east: col 4 (Bed Room / Living Room). " + "Remember that the Assembly Room door starts out being locked and can be unlocked after examining the plant on the Balcony. Additionally, do not mention the row and col of rooms to the player, they should never see this. In their perspective, they move directions such as north, south, east, and west. Give them this info in terms of such directions." + "First, collect four Schematic Parts scattered in apartment: use 'examine' and 'open' to find parts in nightstand drawers, on floor, and kitchen table. " + "Then, calibrate the clock: gears 14 and 21 yield 3 ticks per second (use 'calibrate clock 14 21'). " + "Next, weld a straight and a curved scrap on the workbench to create the 2 jaw coupler ('bench weld straight curved'). " + "Then achieve film-speed pause: recall 24 fps from photos, set the projector to 24 fps ('calibrate projector 24'), start and take the projector. " + "After that, orient mirrors to 30° and 60° angles to guide light for the beam puzzle ('turn mirror <deg>'). " + "Solve the wire-link puzzle: connect Alice->Jack 2, Bob->Jack 4, Charlie->Jack 1, GND->Ground, VCC->12V based on the call book ('switchboard connect ...'). " + "Pick the capacitor matching C=J/frame ÷ V² (~0.25 ÷ 144 = 0.00347F ≈ 3470uF) by choosing the 3300uF from the capacitor box. " + "At the shrine, strike the 128Hz and 500Hz tuning forks to produce a 372Hz resonance and shatter the glass ('hit forks 128 500'), then take the core. " + "Finally, in the Assembly Room, place Core at (1,2), Grandfather Clock at (2,1), 3300uF Capacitor at (2,2), 2 jaw coupler at (3,1), Projector at (3,2), and Switchboard at (3,3), then 'start assembly'. " + "Always offer a hint first; if the player requests, you may then reveal the full solutions.", "system" ); playerInventory = new coreInventory(35); // lb currentRoom = roomMap[0][1]; locationRow = 0; locationCol = 1; daysLeft = 1.0; } private void createBaseActions() { actions.add(new look()); actions.add(new move()); actions.add(new inventory()); actions.add(new drop()); actions.add(new pickup()); actions.add(new help()); actions.add(new examineFloor()); actions.add(new think()); } private void createObjectCommands() { for (coreObject obj : currentRoom.getObjects()) { for (coreAction act : obj.getActions()) { actions.add(act); } } } private void createItemCommands() { for (coreItem item : coreGame.getPlayerInventory().getInventory()) { for (coreAction act : item.getActions()) { actions.add(act); } } } private void createRooms() { roomMap = new coreRoom[3][5]; // N E S W roomMap[1][0] = new coreRoom( "Balcony", coreGameHelper.createExits(false, false, true, false), "A narrow rooftop terrace battered by wind, with a weathered sundial on a cracked stone pedestal. Faded city rooftops stretch below.", new coreObject[]{ new sundialObject(), new planterObject() } ); roomMap[0][1] = new coreRoom( "Bed Room", coreGameHelper.createExits(false, false, false, true), "A cramped bedroom lit by a flickering bulb. A rickety metal bed holds tattered blankets, and a three-drawer nightstand may conceal scattered schematic parts. Faded family photos line the walls, reminding you of what you once were.", new coreObject[]{ new bedroomNightstandObject(), new photoGalleryObject() } ); roomMap[1][1] = new coreRoom( "North Hallway", coreGameHelper.createExits(true, true, true, false), // Switch last option to True when Assembly Room door unlocked. "A dim, narrow corridor linking your apartment rooms. Faded wallpaper peels from the walls, and a locked door on the east bars access to the Assembly Room.", new coreObject[]{ new mirrorObject(), new doorObject() } ); roomMap[1][1].addItem(new schematicPartItem(2)); // adds item to floor roomMap[2][1] = new coreRoom( "Assembly Room", coreGameHelper.createExits(false, true, false, false), "A bare chamber dominated by a sturdy wooden table etched into a three-by-three grid. Empty slots glow faintly, awaiting the parts of your device.", new coreObject[]{ new assemblyObject() } ); roomMap[0][2] = new coreRoom( "Living Room", coreGameHelper.createExits(false, false, false, true), "A modest living room with a threadbare couch and a vintage film projector perched on a wobbly table. Stacks of dusty film reels gleam under dim light, and a ticking grandfather clock echoes in the corner.", new coreObject[]{ new kitchenTableObject(new coreItem[]{ new coreItem("Candles", 1.5), new schematicPartItem(4) }), new grandfatherClockObject(), new projectorObject(), new mirrorObject() } ); roomMap[1][2] = new coreRoom( "South Hallway", coreGameHelper.createExits(true, true, true, true), "A second corridor branching deeper into the apartment. Doors to unknown rooms line the hallway, with pale light from the living area reflecting off a tarnished mirror.", new coreObject[]{ new mirrorObject() } ); roomMap[2][2] = new coreRoom( "Work Room", coreGameHelper.createExits(false, true, false, false), "A cluttered workshop under harsh light, strewn with metal scraps and loose gears. A sturdy workbench holds coils of spring wire and bent brackets, while a switchboard panel looms on the wall.", new coreObject[]{ new gearBoxObject(), new workbenchObject(), new switchboardObject(), new capacitorBoxObject() } ); roomMap[1][3] = new coreRoom( "Front Porch", coreGameHelper.createExits(true, false, true, false), "A chipped wooden porch outside your apartment door, its railing worn smooth. Below, a quiet street leads eastward to a distant shrine under gray skies.", new coreObject[]{} ); roomMap[1][4] = new coreRoom( "Shrine", coreGameHelper.createExits(true, false, false, false), "An ancient roadside shrine shelters a delicate borosilicate glass case that encases the mysterious core. Four tuning forks of varying sizes hang from rusted hooks, awaiting the correct resonance to shatter the glass.", new coreObject[]{ new glassObject(), new chimeObject() } ); } private void processCommand(String command) // AI { // Advance code to check multi alias command names such as "look table" first before normal "look" commands. Lots of help from AI. actions = new ArrayList<coreAction>(); createBaseActions(); createObjectCommands(); createItemCommands(); String input = command.trim(); if (input.isEmpty()) { coreGameHelper.addLine("Please enter a valid command. Try the 'help' command."); return; } // build alias-action pairs class AliasAction { String alias; coreAction action; AliasAction(String a, coreAction ac){ alias = a; action = ac; } } List<AliasAction> pairs = new ArrayList<>(); for (coreAction action : actions) { coreCommand ann = action.getClass().getAnnotation(coreCommand.class); if (ann == null) continue; for (String alias : ann.value()) pairs.add(new AliasAction(alias, action)); } // sort by descending alias length so longest (multi-word) matches first Collections.sort(pairs, new Comparator<AliasAction>() { public int compare(AliasAction p1, AliasAction p2){ return Integer.compare(p2.alias.length(), p1.alias.length()); } }); // attempt to match each alias (only if it matches whole word or prefix + space) for (AliasAction pair : pairs) { String alias = pair.alias; int len = alias.length(); if (input.regionMatches(true, 0, alias, 0, len)) { // ensure exact or followed by whitespace, to avoid "ls" matching "l" if (input.length() == len || Character.isWhitespace(input.charAt(len))) { String rest = input.substring(len) .replaceAll("\\s+", " ") .trim(); // AI normalize whitespace and trim Scanner sc = new Scanner(rest); sc.useDelimiter("\\A"); // AI pair.action.run(alias, sc); return; } } } // no match: unknown command Scanner cmdScannerFallback = new Scanner(input); String cmdFallback = cmdScannerFallback.next(); coreGameHelper.handleUnknownCommand(cmdFallback); } ///////////////////////// public static coreRoom getCurrentRoom() { return currentRoom; } public static void setCurrentRoom(coreRoom cR) { currentRoom = cR; } public static coreRoom[][] getRoomMap() { return roomMap; } public static boolean moveDirection(int dir) { if (dir < 0 || dir > 3) { return false; } if (!currentRoom.getExits()[dir]) { return false; } int[] delta = coreGameHelper.getCoordDelta(dir); int newRow = locationRow + delta[0]; int newCol = locationCol + delta[1]; if (newRow < 0 || newRow >= roomMap.length || newCol < 0 || newCol >= roomMap[newRow].length || roomMap[newRow][newCol] == null) { return false; } locationRow = newRow; locationCol = newCol; currentRoom = roomMap[newRow][newCol]; return true; } public static coreInventory getPlayerInventory() { return playerInventory; } public static ArrayList<coreAction> getAvailableActions() { ArrayList<coreAction> list = new ArrayList<coreAction>(); list.add(new look()); list.add(new move()); list.add(new inventory()); list.add(new drop()); list.add(new pickup()); list.add(new help()); list.add(new examineFloor()); // AI list.add(new think()); // AI for (coreObject obj : currentRoom.getObjects()) list.addAll(obj.getActions()); for (coreItem item : playerInventory.getInventory()) list.addAll(item.getActions()); return list; } public static void addItemPlayerInventory(coreItem cI) { if(!playerInventory.addItem(cI)) { coreGameHelper.addCommand(Color.RED + "There is no space left in the inventory!" + Color.RESET); } } public static void removeDays(double days) { daysLeft -= days; if (daysLeft < 0) daysLeft = 0; } public static double getDaysLeft() { return daysLeft; } public static void winGame() { gameWon = true; } } ///////////////////////// // Game Helper class coreGameHelper { public static String stripAnsi(String s) // AI { return Pattern.compile("\\u001B\\[[;\\d]*[ -/]*[@-~]").matcher(s).replaceAll(""); } public static boolean[] createExits(boolean n, boolean e, boolean s, boolean w) { boolean[] exits = new boolean[4]; exits[0] = n; exits[1] = e; exits[2] = s; exits[3] = w; return exits; } public static int[] getCoordDelta(int direction) { int[][] dirOffsets = { { 0, -1 }, // north { -1, 0 }, // east { 0, 1 }, // south { 1, 0 } // west }; return new int[] { dirOffsets[direction][0], dirOffsets[direction][1] }; } ///////////////////////// private static ArrayList<String> buffer = new ArrayList<String>(); private static String[] statusSegments = new String[0]; public static void clearBuffer() { buffer = new ArrayList<String>(); } public static void addLine(String line) { buffer.add(line); coreGame.context.addContext(line, "user"); } public static void addCommand(String command) { buffer.add(leftText(Color.PURPLE + command + Color.RESET, coreGameHelper.getConsoleWidth() - 5)); coreGame.context.addContext(command, "assistant"); } public static void addNewline() { buffer.add(""); } public static void describeContainer(String description, ArrayList<coreItem> items, String containerName) { if (description != null && !(description.length() == 0)) { addCommand(description); } if (items != null && !(items.size() == 0)) { addCommand("On the " + containerName + " you see:"); for (coreItem it : items) { addCommand("- " + it.getItemName()); } } else { addCommand("There are no items on the " + containerName + "."); } } public static void clearScreen() // AI { System.out.print("\u001B[2J"); System.out.print("\u001B[H"); } public static void flush() // AI { int height = getConsoleHeight(); int contentHeight = height - 1; int totalLines = buffer.size(); int start = 0; if (totalLines > contentHeight) { start = totalLines - contentHeight; } int visibleLines = totalLines - start; int blanks = contentHeight - visibleLines; for (int i = 0; i < blanks; i++) { System.out.println(); } for (int i = start; i < totalLines; i++) { System.out.println(buffer.get(i)); } System.out.println(formatStatusBarItems(statusSegments)); } public static void setStatusBarItems(String... segments) // AI { statusSegments = segments != null ? segments : new String[0]; } public static String formatStatusBarItems(String... segments) // AI { int width = getConsoleWidth(); int n = segments.length; int totalLen = 0; for (String s : segments) { totalLen += (s != null ? s.length() : 0); } int gapCount = n + 1; int totalSpace = Math.max(0, width - totalLen); int baseSpace = totalSpace / gapCount; int extra = totalSpace % gapCount; StringBuilder sb = new StringBuilder(); sb.append(Color.INVERT); int slots = gapCount + n; for (int i = 0; i < slots; i++) { if (i % 2 == 0) { int gapIndex = i / 2; int spaces = baseSpace + (gapIndex < extra ? 1 : 0); for (int j = 0; j < spaces; j++) sb.append(" "); } else { int segIndex = i / 2; String seg = segments[segIndex] != null ? segments[segIndex] : ""; sb.append(seg); } } sb.append(Color.RESET); return sb.toString(); } public static String formatRow(String... segments) // AI { // Lots of help from AI, formats a row of segments equally spaced across the console width, without coloring or inversion int width = getConsoleWidth(); int totalLen = 0; for (String s : segments) totalLen += (s != null ? s.length() : 0); int gapCount = segments.length + 1; int totalSpace = Math.max(0, width - totalLen); int baseSpace = totalSpace / gapCount; int extra = totalSpace % gapCount; StringBuilder sb = new StringBuilder(); for (int i = 0; i < gapCount; i++) { int spaces = baseSpace + (i < extra ? 1 : 0); for (int j = 0; j < spaces; j++) sb.append(' '); if (i < segments.length) sb.append(segments[i] != null ? segments[i] : ""); } return sb.toString(); } public static int getConsoleWidth() // AI { String cols = System.getenv("COLUMNS"); if (cols != null) { try { return Integer.parseInt(cols); } catch (NumberFormatException e) { // ignore and try tput } } try { Process proc = new ProcessBuilder("bash", "-lc", "tput cols").redirectErrorStream(true).start(); java.io.BufferedReader reader = new java.io.BufferedReader( new java.io.InputStreamReader(proc.getInputStream())); String out = reader.readLine(); proc.waitFor(); if (out != null) { return Integer.parseInt(out.trim()); } } catch (Exception e) { // ignore and use default } return 80; } public static int getConsoleHeight() // AI { String lines = System.getenv("LINES"); if (lines != null) { try { return Integer.parseInt(lines); } catch (NumberFormatException e) { // ignore and use default } } return 64; } public static void handleUnknownCommand(String cmd) { addLine(Color.RED + "I don't understand that command: " + cmd + Color.RESET); addLine(Color.RED + "Try the 'help' command." + Color.RESET); } public static ArrayList<String> wrapText(String text, int maxWidth) // AI { // Lots of AI help, it skips colored text codes when splitting into parts while still keeping the colored text. ArrayList<String> lines = new ArrayList<>(); String[] parts = text.split("\\n"); for (String part : parts) { if (part.isEmpty()) { lines.add(""); continue; } int visibleCount = 0; StringBuilder current = new StringBuilder(); for (int i = 0; i < part.length(); ) { char c = part.charAt(i); if (c == '\u001B') // ANSI escape { int seqEnd = i + 1; // find 'm' while (seqEnd < part.length() && part.charAt(seqEnd) != 'm') seqEnd++; if (seqEnd < part.length()) { current.append(part, i, seqEnd + 1); i = seqEnd + 1; } else { current.append(c); i++; } } else { current.append(c); visibleCount++; i++; if (visibleCount >= maxWidth) { lines.add(current.toString()); current.setLength(0); visibleCount = 0; } } } if (current.length() > 0) lines.add(current.toString()); } return lines; } public static String centerText(String text, int maxWidth) // AI { int consoleWidth = getConsoleWidth(); ArrayList<String> lines = wrapText(text, maxWidth); String result = ""; for (int idx = 0; idx < lines.size(); idx++) { String line = lines.get(idx); int visibleLen = stripAnsi(line).length(); int padding = (consoleWidth - visibleLen) / 2; if (padding < 0) padding = 0; String spaces = ""; for (int i = 0; i < padding; i++) { spaces += " "; } result += spaces + line; if (idx < lines.size() - 1) { result += "\n"; } } return result; } public static String leftText(String text, int maxWidth) // AI { ArrayList<String> lines = wrapText(text, maxWidth); String result = ""; for (int idx = 0; idx < lines.size(); idx++) { result += lines.get(idx); if (idx < lines.size() - 1) { result += "\n"; } } return result; } public static String rightText(String text, int maxWidth) // AI { ArrayList<String> lines = wrapText(text, maxWidth); String result = ""; int consoleWidth = getConsoleWidth(); for (int idx = 0; idx < lines.size(); idx++) { String line = lines.get(idx); String stripped = stripAnsi(line); int visibleLen = stripped.length(); int padding = consoleWidth - visibleLen; if (padding < 0) padding = 0; String spaces = ""; for (int i = 0; i < padding; i++) { spaces += " "; } result += spaces + line; if (idx < lines.size() - 1) { result += "\n"; } } return result; } public static String centerText(String text) { return centerText(text, getConsoleWidth()); } public static String leftText(String text) { return leftText(text, getConsoleWidth()); } public static String rightText(String text) { return rightText(text, getConsoleWidth()); } }
public class Color { public static final String RESET = "\u001B[0m"; // AI public static final String INVERT = "\u001B[7m"; // AI public static final String BLACK = "\u001B[30m"; // AI public static final String RED = "\u001B[31m"; // AI public static final String GREEN = "\u001B[32m"; // AI public static final String YELLOW = "\u001B[33m"; // AI public static final String BLUE = "\u001B[34m"; // AI public static final String PURPLE = "\u001B[35m"; // AI public static final String CYAN = "\u001B[36m"; // AI public static final String WHITE = "\u001B[37m"; // AI }
import java.util.List; import java.util.Scanner; import java.util.ArrayList; import java.io.IOException; // AI // Commands where researched starting at: // https://stackoverflow.com/questions/27606577/best-way-to-parse-commands-in-a-java-text-based-game // and then having AI help add aliases. ///////////////////////// // Commands @coreCommand({"look", "l"}) class look implements coreAction { @Override public void run(String invoked, Scanner scanner) { coreGameHelper.addCommand(coreGame.getCurrentRoom().getRoomDescription()); coreGame.removeDays(15 / 86400.0); } } @coreCommand({"examine floor", "x floor"}) class examineFloor implements coreAction { @Override public void run(String invoked, Scanner scanner) { ArrayList<coreItem> floorItems = new ArrayList<coreItem>(coreGame.getCurrentRoom().getItems()); coreGameHelper.describeContainer("", floorItems, "floor"); coreGame.removeDays(45 / 86400.0); } } @coreCommand({"think"}) // AI class think implements coreAction { // Lots of help from AI, several commands that allow me to send JSON with context to external AI server and phrase the response. private static String unescapeJson(String text) // AI { if (text == null) { return ""; } StringBuilder sb = new StringBuilder(); for (int i = 0; i < text.length(); i++) { char ch = text.charAt(i); if (ch == '\\' && i + 1 < text.length()) { char next = text.charAt(i + 1); switch (next) { case 'n': sb.append('\n'); i++; break; case 'r': sb.append('\r'); i++; break; case 't': sb.append('\t'); i++; break; case '\\': sb.append('\\'); i++; break; case '"': sb.append('"'); i++; break; case 'u': if (i + 5 < text.length()) { String hex = text.substring(i + 2, i + 6); try { int code = Integer.parseInt(hex, 16); sb.append((char) code); i += 5; } catch (NumberFormatException e) { sb.append("\\u"); } } else { sb.append("\\u"); i++; } break; default: sb.append(next); i++; break; } } else { sb.append(ch); } } return sb.toString(); } // Lots of help from AI to format the JSON packet and response. @Override public void run(String invoked, Scanner scanner) // AI { String thought = scanner.hasNextLine() ? scanner.nextLine().trim() : ""; if (!thought.isEmpty()) { coreGame.context.addContext(thought, "user"); } try { String aiJson = coreGame.context.think(); String aiResponse; int idx = aiJson.indexOf("\"response\""); if (idx >= 0) { int colon = aiJson.indexOf(':', idx); int firstQuote = aiJson.indexOf('"', colon + 1); int secondQuote = aiJson.indexOf('"', firstQuote + 1); aiResponse = aiJson.substring(firstQuote + 1, secondQuote); } else { aiResponse = aiJson; } aiResponse = unescapeJson(aiResponse); coreGameHelper.addCommand(aiResponse); } catch (IOException e) { coreGameHelper.addCommand("Error: " + e.getMessage()); } } } @coreCommand({"inventory", "i"}) class inventory implements coreAction { @Override public void run(String invoked, Scanner scanner) { ArrayList<coreItem> inventory = coreGame.getPlayerInventory().getInventory(); if (inventory.size() == 0) { coreGameHelper.addCommand("Your inventory is empty."); } else { coreGameHelper.addCommand("You have:"); for (coreItem item : inventory) { coreGameHelper.addCommand("- " + item.getItemName()); } } coreGame.removeDays(5 / 86400.0); } } @coreCommand({"drop", "q"}) class drop implements coreAction { @Override public void run(String invoked, Scanner scanner) // AI { String itemName; if (scanner.hasNextLine()) itemName = scanner.nextLine().trim(); else { coreGameHelper.addCommand("Drop what?"); return; } if (itemName.length() == 0) { coreGameHelper.addCommand("Drop what?"); return; } ArrayList<coreItem> inv = coreGame.getPlayerInventory().getInventory(); coreItem found = null; for (coreItem item : inv) { if (item.getItemName().equalsIgnoreCase(itemName)) { found = item; break; } } if (found == null) { coreGameHelper.addCommand("You don't have " + itemName + "."); } else { coreGame.getPlayerInventory().removeItem(found); coreGame.getCurrentRoom().addItem(found); coreGameHelper.addCommand("You drop " + found.getItemName() + "."); coreGame.removeDays(15 / 86400.0); } } } @coreCommand({"n", "e", "s", "w", "north", "east", "south", "west"}) class move implements coreAction { @Override public void run(String invoked, Scanner scanner) { int dir; String dirStr = ""; if (invoked.equals("n") || invoked.equals("north")) { dir = 0; dirStr = "north"; } else if (invoked.equals("e") || invoked.equals("east")) { dir = 1; dirStr = "east"; } else if (invoked.equals("s") || invoked.equals("south")) { dir = 2; dirStr = "south"; } else if (invoked.equals("w") || invoked.equals("west")) { dir = 3; dirStr = "west"; } else { coreGameHelper.addCommand("I don't understand direction: " + invoked); return; } boolean moveSuccess = coreGame.moveDirection(dir); if (moveSuccess) { coreGameHelper.addCommand("Moved " + dirStr + "!"); coreGame.removeDays((60 + coreGame.getPlayerInventory().inventoryTotalWeight() * 5) / 86400.0); } else { coreGameHelper.addCommand("Can't move " + dirStr + "!"); } } } @coreCommand({"take", "get", "pickup"}) class pickup implements coreAction { @Override public void run(String invoked, Scanner scanner) { if (!scanner.hasNext()) { coreGameHelper.addCommand("Pick up what?"); return; } String name = scanner.nextLine().trim(); List<coreItem> floor = coreGame.getCurrentRoom().getItems(); coreItem found = null; for (coreItem it : floor) { if (it.getItemName().equalsIgnoreCase(name)) { found = it; break; } } if (found == null) { coreGameHelper.addCommand("There is no " + name + " here."); } else if (!coreGame.getPlayerInventory().addItem(found)) { coreGameHelper.addCommand("You can't carry that."); } else { coreGame.getCurrentRoom().removeItem(found); coreGameHelper.addCommand("You pick up " + found.getItemName() + "."); coreGame.removeDays(45 / 86400.0); } } } @coreCommand({"help", "h", "?"}) class help implements coreAction // AI { // Lots of help from AI, finds functions that are similar to the inputted value. @Override public void run(String invoked, Scanner scanner) { String filter = null; if (scanner.hasNextLine()) { filter = scanner.nextLine().trim().toLowerCase(); if (filter.isEmpty()) filter = null; } // gather available actions from coreGame ArrayList<coreAction> avail = coreGame.getAvailableActions(); // build unique alias lines ArrayList<String> lines = new ArrayList<>(); for (coreAction action : avail) { coreCommand ann = action.getClass().getAnnotation(coreCommand.class); if (ann == null) continue; String aliasLine = String.join(", ", ann.value()); if (filter != null && !aliasLine.toLowerCase().contains(filter)) continue; if (!lines.contains(aliasLine)) lines.add(aliasLine); } if (lines.isEmpty()) { coreGameHelper.addCommand("No commands match '" + filter + "'."); return; } if (filter == null) { coreGameHelper.addCommand("Available commands:"); } else { coreGameHelper.addCommand("Commands matching '" + filter + "':"); } for (String line : lines) { coreGameHelper.addCommand("- " + line); } } }
import java.util.ArrayList; import java.net.URL; // AI import java.net.HttpURLConnection; // AI import java.io.OutputStream; // AI import java.io.BufferedReader; // AI import java.io.InputStreamReader; // AI import java.io.IOException; // AI import java.nio.charset.StandardCharsets; // AI import java.io.InputStream; // AI public class coreContext { private class coreMessage { private String message; private String author; public coreMessage(String m, String a) { message = m; author = a; } public String getMessage() { return message; } public String getAuthor() { return author; } } private ArrayList<coreMessage> context; public coreContext() { context = new ArrayList<coreMessage>(); } public void addContext(String m, String a) { context.add(new coreMessage(m, a)); } private static String escapeJson(String text) // AI { // Lots of help from AI, converts every special case in a text to a 'safe' case that can be sent without errors. if (text == null) { return ""; } StringBuilder sb = new StringBuilder(); for (int i = 0; i < text.length(); i++) { char ch = text.charAt(i); switch (ch) { case '"': sb.append("\\\""); break; case '\\': sb.append("\\\\"); break; case '\b': sb.append("\\b"); break; case '\f': sb.append("\\f"); break; case '\n': sb.append("\\n"); break; case '\r': sb.append("\\r"); break; case '\t': sb.append("\\t"); break; default: if (ch <= 0x1F) { sb.append(String.format("\\u%04x", (int) ch)); } else { sb.append(ch); } } } return sb.toString(); } public String requestAI(String urlString) throws IOException // AI { // Lots of AI help to create a JSON POST request to my Cloudflare Worker. URL url = new URL(urlString); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("POST"); connection.setDoOutput(true); connection.setRequestProperty("Content-Type", "application/json; utf-8"); connection.setRequestProperty("Accept", "application/json"); StringBuilder payloadBuilder = new StringBuilder(); payloadBuilder.append("{\"context\":["); for (int i = 0; i < context.size(); i++) { coreMessage msg = context.get(i); String safeMessage = escapeJson(msg.getMessage()); String safeAuthor = escapeJson(msg.getAuthor()); payloadBuilder.append("{\"message\":\"") .append(safeMessage) .append("\",\"author\":\"") .append(safeAuthor) .append("\"}"); if (i < context.size() - 1) { payloadBuilder.append(","); } } payloadBuilder.append("]}"); String jsonInputString = payloadBuilder.toString(); try (OutputStream os = connection.getOutputStream()) { byte[] input = jsonInputString.getBytes(StandardCharsets.UTF_8); os.write(input, 0, input.length); } int responseCode = connection.getResponseCode(); InputStream stream; if (responseCode < HttpURLConnection.HTTP_BAD_REQUEST) { stream = connection.getInputStream(); } else { stream = connection.getErrorStream(); } try (BufferedReader br = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8))) { StringBuilder responseBuilder = new StringBuilder(); String responseLine; while ((responseLine = br.readLine()) != null) { responseBuilder.append(responseLine.trim()); } String responseBody = responseBuilder.toString(); if (responseCode >= HttpURLConnection.HTTP_BAD_REQUEST) { throw new IOException("HTTP " + responseCode + ": " + responseBody); } return responseBody; } } public String think() throws IOException // AI { return requestAI("https://unpunishedthoughts.dgcf.workers.dev/"); } }
import java.util.ArrayList; public class coreInventory { private ArrayList<coreItem> inventory; private final int maxWeight; public coreInventory(int mW) { inventory = new ArrayList<coreItem>(); maxWeight = mW; } public int getMaxWeight() { return maxWeight; } public boolean addItem(coreItem i) { if(inventoryBooleanWeight(i)) { inventory.add(i); return true; } return false; } public boolean removeItem(coreItem i) { for(int index = 0; index < inventory.size(); index++) { if(i.equals(inventory.get(index))) { inventory.remove(index); return true; } } return false; } public ArrayList<coreItem> getInventory() { return inventory; } public double inventoryTotalWeight() { double totalWeight = 0; for(coreItem i : inventory) { totalWeight += i.getItemWeight(); } return totalWeight; } public double inventoryWeight(coreItem nI) { return inventoryTotalWeight() + nI.getItemWeight(); } public boolean inventoryBooleanWeight(coreItem nI) { return inventoryTotalWeight() + nI.getItemWeight() <= maxWeight; } public int inventoryIndexOf(coreItem nI) { for(int i = 0; i < inventory.size(); i++) { if(nI.equals(inventory.get(i))) { return i; } } return -1; } }
import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class coreItem { private String itemName; private double itemWeight; private List<coreAction> itemActions; public coreItem(String iN, double iW) { itemName = iN; itemWeight = iW; itemActions = new ArrayList<coreAction>(); } public String getItemName() { return itemName; } public double getItemWeight() { return itemWeight; } public boolean equals(coreItem other) { return itemName.equals(other.getItemName()) && itemWeight == other.getItemWeight(); } public void registerAction(coreAction action) { itemActions.add(action); } public List<coreAction> getActions() { return new ArrayList<coreAction>(itemActions); } } ///////////////////////// // Projector Item class projectorItem extends coreItem { public projectorItem() { super("Projector", 10.0); registerAction(new inspectSpecAction()); } @coreCommand({"projector specs","spec projector","inspect projector"}) private class inspectSpecAction implements coreAction { @Override public void run(String invoked, Scanner scanner) { coreGameHelper.addCommand("Projector Model XR-24"); coreGameHelper.addCommand("Input: 12V DC @ 0.5A"); coreGameHelper.addCommand("Power Consumption: 6W"); coreGameHelper.addCommand("J per Frame: 0.25J"); coreGame.removeDays(15 / 86400.0); } } } ///////////////////////// // Schematic Part class schematicPartItem extends coreItem { private int itemNumber; public schematicPartItem(int iN) { super("Schematic Part " + iN, 0.2); itemNumber = iN; registerAction(new assembleAction()); } public int getItemNumber() { return itemNumber; } @coreCommand({"assemble schematic"}) private class assembleAction implements coreAction { public void run(String invoked, Scanner scanner) { ArrayList<coreItem> inv = coreGame.getPlayerInventory().getInventory(); for(int part = 1; part <= 4; part++) { if(coreGame.getPlayerInventory().inventoryIndexOf(new schematicPartItem(part)) < 0) { coreGameHelper.addCommand("You are missing some schematics! Can't assembly yet."); return; } } for (int part = 1; part <= 4; part++) { coreGame.getPlayerInventory().removeItem(new schematicPartItem(part)); } coreGameHelper.addCommand("You successfully created the schematic from 4 parts of schematic parts."); coreGame.removeDays((60 * 5) / 86400.0); coreGame.getPlayerInventory().addItem(new schematicItem()); } } } // Call Book item for wire-link puzzle class callBookItem extends coreItem { private String[] pages; public callBookItem() { super("Call Book", 0.5); pages = new String[] { "Page 1:\nDear Diary, today I found some interesting scraps around the workshop...", "Page 2:\nThe gears seem to hum in the night with a peculiar resonance...", "Page 3:\nI recall the pattern of light through the mirror maze... it's mesmerizing...", "Page 4:\nOdd scribbles about capacitors and voltages are barely legible...", "Page 5:\nWiring Instructions:\nAlice: Jack 2\nBob: Jack 4\nCharlie: Jack 1\nGND: Ground\nVCC: 12V" }; registerAction(new readAction()); } @coreCommand({"read call book", "read book", "read callbook"}) private class readAction implements coreAction { @Override public void run(String invoked, Scanner scanner) { if (!scanner.hasNextInt()) { coreGameHelper.addCommand("Which page? (1-5)"); return; } int page = scanner.nextInt(); if (scanner.hasNextLine()) scanner.nextLine(); if (page < 1 || page > pages.length) { coreGameHelper.addCommand("There are only " + pages.length + " pages."); } else { coreGameHelper.addCommand(pages[page-1]); coreGame.removeDays(60 / 86400.0); } } } } ///////////////////////// // Schematic Full class schematicItem extends coreItem { public schematicItem() { super("Schematic", 0.8); registerAction(new examineSchematicAction()); } @coreCommand({"examine schematic", "x schematic"}) private class examineSchematicAction implements coreAction { @Override public void run(String invoked, Scanner scanner) { String text = "Схема сборки устройства:\n" + coreGameHelper.formatRow(" ", "Ядро", " ") + "\n" + coreGameHelper.formatRow("Часы", "Конденсатор", " ") + "\n" + coreGameHelper.formatRow("Связь", "Проектор", "Панель"); coreGameHelper.addCommand(text); coreGame.removeDays(60 / 86400.0); } } }
import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.*; import java.util.Scanner; public class coreObject { private String objectName; private String objectDescription; private String objectType; private List<coreAction> objectActions; public coreObject(String oN, String oD, String oT) { objectName = oN; objectDescription = oD; objectType = oT; objectActions = new ArrayList<coreAction>(); } public String getObjectName() { return objectName; } public String getObjectDescription() { return objectDescription; } public String getObjectType() { return objectType; } public boolean equals(coreObject other) { return objectName.equals(other.getObjectName()) && objectDescription.equals(other.getObjectDescription()) && objectType.equals(other.getObjectType()); } public void registerAction(coreAction action) { objectActions.add(action); } public List<coreAction> getActions() { return new ArrayList<coreAction>(objectActions); } } ///////////////////////// // Planter class planterObject extends coreObject { private boolean keyRevealed = false; public planterObject() { super("Planter", "A battered metal planter holds dry soil and withered leaves, its surface cracked—perhaps something vital lies buried within.", "scenery"); registerAction(new examinePlanterAction()); } @coreCommand({"examine planter", "x planter", "inspect planter", "examine plant", "x plant", "inspect plant"}) private class examinePlanterAction implements coreAction { @Override public void run(String invoked, Scanner scanner) { if (!keyRevealed) { coreGameHelper.addCommand("As you sift through the soil, you uncover an old key!"); coreItem key = new coreItem("Key", 0.1); if (coreGame.getPlayerInventory().addItem(key)) { coreGameHelper.addCommand("You pick up the key."); } else { coreGameHelper.addCommand(Color.RED + "You have no space in your inventory! The key remains in the soil." + Color.RESET); coreGame.getCurrentRoom().addItem(key); } keyRevealed = true; } else { coreGameHelper.addCommand("The potted plant sits quietly. The soil is disturbed from where you found the key."); } coreGame.removeDays(30 / 86400.0); } } } ///////////////////////// // Assembly Room Door class doorObject extends coreObject // AI { private boolean locked = true; public doorObject() { super("Door", "A heavy oak door with iron hinges and a hardened lock, barring entry to the Assembly Room until you find the key.", "scenery"); registerAction(new unlockDoorAction()); } @coreCommand({"unlock door", "unlock assembly room", "unlock assembly room door"}) private class unlockDoorAction implements coreAction { @Override public void run(String invoked, Scanner scanner) // AI { if (!locked) { coreGameHelper.addCommand("The door is already unlocked."); return; } ArrayList<coreItem> inv = coreGame.getPlayerInventory().getInventory(); coreItem key = null; for (coreItem item : inv) { if (item.getItemName().equalsIgnoreCase("Key")) { key = item; break; } } if (key == null) { coreGameHelper.addCommand("You don't have the key."); return; } coreGame.getPlayerInventory().removeItem(key); coreRoom current = coreGame.getCurrentRoom(); current.getExits()[3] = true; locked = false; coreGameHelper.addCommand("You unlock the door with the key. The key breaks and is lost."); coreGame.removeDays(60 / 86400.0); } } } ///////////////////////// // Assembly Table class assemblyObject extends coreObject { private coreItem[][] slots; private static final String[][] expected = { {null, "Core", null}, {"Grandfather Clock", "3300uF Capacitor", null}, {"2 jaw coupler", "Projector", "Switchboard"} }; // AI public assemblyObject() { super("Assembly Table", "A sturdy wooden table etched into a three-by-three grid, each empty slot glowing faintly as it awaits a critical component.", "furniture"); slots = new coreItem[3][3]; registerAction(new examineAssemblyAction()); registerAction(new placeAction()); registerAction(new takeFromSlotAction()); registerAction(new startAssemblyAction()); } @coreCommand({"examine assembly", "x assembly"}) private class examineAssemblyAction implements coreAction { @Override public void run(String invoked, Scanner scanner) { String text = ""; for (int r = 0; r < 3; r++) { String[] labels = new String[3]; for (int c = 0; c < 3; c++) { labels[c] = (slots[r][c] == null) ? "Empty" : slots[r][c].getItemName(); } text += coreGameHelper.formatRow(labels); if (r < 2) text += "\n"; } coreGameHelper.addCommand(text); coreGame.removeDays(45 / 86400.0); } } @coreCommand({"place", "assembly place"}) private class placeAction implements coreAction { @Override public void run(String invoked, Scanner scanner) { String rest = scanner.hasNextLine() ? scanner.nextLine().trim() : ""; Scanner sc = new Scanner(rest); if (!sc.hasNextInt()) { coreGameHelper.addCommand("Specify row and column first (e.g., 'place 1 2 Item')."); return; } int row = sc.nextInt(); if (!sc.hasNextInt()) { coreGameHelper.addCommand("Specify column next (e.g., 'place 1 2 Item')."); return; } int col = sc.nextInt(); String itemName = sc.hasNextLine() ? sc.nextLine().trim() : ""; if (itemName.isEmpty()) { coreGameHelper.addCommand("Specify item name last (e.g., 'place 1 2 Core')."); return; } if (row < 1 || row > 3 || col < 1 || col > 3) { coreGameHelper.addCommand("Invalid slot coordinates."); return; } int r = row - 1, c = col - 1; if (slots[r][c] != null) { coreGameHelper.addCommand("Slot is already occupied."); return; } coreItem toPlace = null; for (coreItem it : coreGame.getPlayerInventory().getInventory()) { if (it.getItemName().equalsIgnoreCase(itemName)) { toPlace = it; break; } } if (toPlace == null) { coreGameHelper.addCommand("You don't have " + itemName + "."); return; } coreGame.getPlayerInventory().removeItem(toPlace); slots[r][c] = toPlace; coreGameHelper.addCommand("You place " + toPlace.getItemName() + " at (" + row + "," + col + ")."); coreGame.removeDays(30 / 86400.0); } } @coreCommand({"assembly take", "take assembly"}) private class takeFromSlotAction implements coreAction { @Override public void run(String invoked, Scanner scanner) { if (!scanner.hasNextInt()) { coreGameHelper.addCommand("Specify row."); return; } int row = scanner.nextInt(); if (!scanner.hasNextInt()) { coreGameHelper.addCommand("Specify column."); return; } int col = scanner.nextInt(); if (row < 1 || row > 3 || col < 1 || col > 3) { coreGameHelper.addCommand("Invalid slot coordinates."); return; } int r = row - 1, c = col - 1; coreItem item = slots[r][c]; if (item == null) { coreGameHelper.addCommand("Slot is empty."); return; } if (coreGame.getPlayerInventory().addItem(item)) { slots[r][c] = null; coreGameHelper.addCommand("You take " + item.getItemName() + " from (" + row + "," + col + ")."); coreGame.removeDays(30 / 86400.0); } else { coreGameHelper.addCommand("You can't carry that."); } } } @coreCommand({"start assembly", "begin assembly"}) private class startAssemblyAction implements coreAction { @Override public void run(String invoked, Scanner scanner) // AI { boolean ok = true; for (int r = 0; r < 3; r++) { for (int c = 0; c < 3; c++) { String exp = expected[r][c]; coreItem cur = slots[r][c]; if (exp == null) { if (cur != null) ok = false; } else { if (cur == null || !cur.getItemName().equalsIgnoreCase(exp)) ok = false; } } } if (ok) { coreGameHelper.addCommand("With a triumphant click, the assembled device springs to life! Николай, you have succeeded!"); coreGame.winGame(); coreGame.removeDays(60 / 86400.0); } else { coreGameHelper.addCommand("The machine hums briefly but fails to activate. The components are not in the correct configuration."); coreGame.removeDays(60 / 86400.0); } } } } ///////////////////////// // Shrine-Chime Resonance Puzzle class glassObject extends coreObject { private boolean broken = false; private boolean coreTaken = false; public glassObject() { super("Glass Case", "A thick borosilicate glass case perched on a stone plinth, protecting a mysterious core that pulses with hidden energy.", "container"); registerAction(new examineGlassAction()); registerAction(new takeCoreAction()); } @coreCommand({"examine glass case", "x glass case", "examine glass", "x glass", "examine case", "x case"}) private class examineGlassAction implements coreAction { public void run(String invoked, Scanner scanner) { if (!broken) { coreGameHelper.addCommand(getObjectDescription()); } else { coreGameHelper.addCommand("The borosilicate glass has shattered; shards lie scattered and the core rests exposed on the floor."); } coreGame.removeDays(15 / 86400.0); } } public void breakGlass() { broken = true; } public boolean isCoreTaken() { return coreTaken; } @coreCommand({"take core", "get core" ,"pickup core" ,"t core"}) private class takeCoreAction implements coreAction { @Override public void run(String invoked, Scanner scanner) { if (!broken) { coreGameHelper.addCommand("The glass is intact; the core is unreachable."); } else if (coreTaken) { coreGameHelper.addCommand("You have already taken the core."); } else { coreItem core = new coreItem("Core", 1.0); if (coreGame.getPlayerInventory().addItem(core)) { coreTaken = true; coreGameHelper.addCommand("You take the core from the shattered glass."); coreGame.removeDays(60 / 86400.0); } else { coreGameHelper.addCommand("You can't carry the core."); } } } } } class chimeObject extends coreObject { private final ArrayList<Integer> forks; public chimeObject() { super("Tuning Forks", "Four metal tuning forks of 128Hz, 256Hz, 500Hz, and 640Hz hang on a tarnished wooden rack, awaiting a strike.", "device"); forks = new ArrayList<Integer>(Arrays.asList(128, 256, 500, 640)); // AI registerAction(new examineChimesAction()); registerAction(new hitForksAction()); } @coreCommand({"examine tuning forks", "x tuning forks", "examine forks", "x forks"}) private class examineChimesAction implements coreAction { public void run(String invoked, Scanner scanner) { coreGameHelper.addCommand(getObjectDescription()); coreGameHelper.addCommand("Available frequencies: 128Hz, 256Hz, 500Hz, 640Hz."); } } @coreCommand({"hit forks"}) private class hitForksAction implements coreAction // AI { public void run(String invoked, Scanner scanner) { for (coreObject obj : coreGame.getCurrentRoom().getObjects()) { if (obj instanceof glassObject) // AI { glassObject glass = (glassObject) obj; if (glass.isCoreTaken()) { coreGameHelper.addCommand("You feel the lingering resonance of the forks echo in your mind; nothing more happens."); return; } } } String rest = scanner.hasNextLine() ? scanner.nextLine().trim() : ""; if (rest.isEmpty()) { coreGameHelper.addCommand("Hit which forks? Specify frequencies."); return; } String[] parts = rest.split("\\s+"); // AI ArrayList<Integer> inputs = new ArrayList<Integer>(); for (String p : parts) { try { inputs.add(Integer.parseInt(p)); } catch (NumberFormatException e) { coreGameHelper.addCommand("Invalid frequency: " + p); return; } } for (int f : inputs) { if (!forks.contains(f)) { coreGameHelper.addCommand("There's no " + f + "Hz fork here."); return; } } if (inputs.size() == 2 && inputs.contains(128) && inputs.contains(500)) { coreGameHelper.addCommand("As you strike the 128Hz and 500Hz forks, a 372Hz resonance shatters the glass!"); for (coreObject obj : coreGame.getCurrentRoom().getObjects()) { if (obj instanceof glassObject) // AI ((glassObject)obj).breakGlass(); } coreGame.getCurrentRoom().addItem(new coreItem("Core", 1.0)); } else { coreGameHelper.addCommand("The forks vibrate discordantly. Nothing happens."); } } } } // Mirror puzzle class mirrorObject extends coreObject { private int orientation = 0; public mirrorObject() { super("Mirror", "An adjustable mirror on a swivel arm, its surface dulled by age yet capable of redirecting light with precision.", "device"); registerAction(new examineMirrorAction()); registerAction(new turnMirrorAction()); } @coreCommand({"examine mirror", "x mirror"}) private class examineMirrorAction implements coreAction { @Override public void run(String invoked, Scanner scanner) { coreGameHelper.addCommand(getObjectDescription()); coreGameHelper.addCommand("The mirror is currently oriented at " + orientation + "°."); coreGame.removeDays(15 / 86400.0); } } @coreCommand({"turn mirror"}) private class turnMirrorAction implements coreAction // AI { @Override public void run(String invoked, Scanner scanner) { if (!scanner.hasNextInt()) { coreGameHelper.addCommand("Turn mirror to what degree?"); return; } orientation = scanner.nextInt(); if (scanner.hasNextLine()) scanner.nextLine(); coreGameHelper.addCommand("You turn the mirror to " + orientation + "°."); coreGame.removeDays(30 / 86400.0); } } } // Switchboard Wire-link Puzzle class switchboardObject extends coreObject // AI { private final String[] wires = {"Alice", "Bob", "Charlie", "GND", "VCC"}; private ArrayList<String> connections; public switchboardObject() { super("Switchboard", "A metal control panel studded with numbered jacks and loose, color-coded wires, their ends frayed from disuse.", "device"); connections = new ArrayList<String>(Collections.nCopies(wires.length, null)); // AI registerAction(new examineSwitchboardAction()); registerAction(new connectWireAction()); registerAction(new takeSwitchboardAction()); } @coreCommand({"examine switchboard", "x switchboard", "examine sb", "x sb"}) private class examineSwitchboardAction implements coreAction { @Override public void run(String invoked, Scanner scanner) { coreGameHelper.addCommand(getObjectDescription()); coreGameHelper.addCommand("Available wires: Alice, Bob, Charlie, GND, VCC.\nUse: switchboard connect <wire> <jack number|Ground|12V>"); for (int i = 0; i < wires.length; i++) { String wire = wires[i]; String map = connections.get(i); String status = (map != null) ? map : "unconnected"; coreGameHelper.addCommand(wire + " -> " + status); } } } @coreCommand({"switchboard connect", "sb connect"}) private class connectWireAction implements coreAction { @Override public void run(String invoked, Scanner scanner) // AI { // Function mostly written by AI. String rest = scanner.hasNextLine() ? scanner.nextLine().trim() : ""; if (rest.isEmpty()) { coreGameHelper.addCommand("Usage: switchboard connect <wire> <jack number|Ground|12V>"); return; } String[] parts = rest.split("\\s+"); if (parts.length < 2) { coreGameHelper.addCommand("Usage: switchboard connect <wire> <jack number|Ground|12V>"); return; } String wire = parts[0]; // wire name String target = parts[1]; // jack or label // find wire index int idx = -1; for (int i = 0; i < wires.length; i++) { if (wires[i].equalsIgnoreCase(wire)) { idx = i; break; } } if (idx < 0) { coreGameHelper.addCommand("Unknown wire: " + wire + ". Use Alice, Bob, Charlie, GND, or VCC."); return; } String mapping; if (target.matches("\\d+")) { int jackNum = Integer.parseInt(target); if (jackNum < 1 || jackNum > 5) { coreGameHelper.addCommand("Invalid jack number. Choose 1 through 5."); return; } mapping = "Jack " + jackNum; } else { String t = target.toLowerCase(); if (t.equals("ground")) mapping = "Ground"; else if (t.equals("12v")) mapping = "12V"; else { coreGameHelper.addCommand("Invalid jack label. Use 1-5, Ground, or 12V."); return; } } connections.set(idx, mapping); coreGameHelper.addCommand("Connected " + wire + " to " + mapping + "."); coreGame.removeDays(20 / 86400.0); } } @coreCommand({"take switchboard", "take sb", "t switchboard", "t sb"}) private class takeSwitchboardAction implements coreAction { @Override public void run(String invoked, Scanner scanner) { if (!isComplete()) { coreGameHelper.addCommand("Connect all wires correctly before taking the switchboard."); return; } coreItem sb = new coreItem("Switchboard", 5.0); if (coreGame.getPlayerInventory().addItem(sb)) { coreGame.getCurrentRoom().removeObject(switchboardObject.this); // AI coreGameHelper.addCommand("You take the switchboard."); coreGame.removeDays(180 / 86400.0); } else { coreGameHelper.addCommand("You can't carry that."); } } } private boolean isComplete() { String[] expected = { "Jack 2", "Jack 4", "Jack 1", "Ground", "12V" }; for (int i = 0; i < wires.length; i++) { String got = connections.get(i); if (got == null || !got.equalsIgnoreCase(expected[i])) return false; } return true; } } // Capacitor Box for Capacitor-Weight Matching puzzle class capacitorBoxObject extends coreObject { private ArrayList<coreItem> caps; public capacitorBoxObject() // AI { super("Capacitor Box", "A steel box brimming with capacitors of varying microfarad ratings, each coated in dust and faint oil stains.", "container"); caps = new ArrayList<coreItem>(); caps.add(new coreItem("1000uF Capacitor", 0.1)); caps.add(new coreItem("2200uF Capacitor", 0.1)); caps.add(new coreItem("3300uF Capacitor", 0.1)); caps.add(new coreItem("4700uF Capacitor", 0.1)); caps.add(new coreItem("5600uF Capacitor", 0.1)); registerAction(new examineBoxAction()); registerAction(new takeCapacitorAction()); } @coreCommand({"examine capacitor box", "x caps", "examine caps"}) private class examineBoxAction implements coreAction { @Override public void run(String invoked, Scanner scanner) { coreGameHelper.addCommand(getObjectDescription()); coreGameHelper.addCommand("Inside the box you see:"); for (coreItem c : caps) coreGameHelper.addCommand("- " + c.getItemName()); coreGame.removeDays(15 / 86400.0); } } @coreCommand({"take capacitor", "take caps", "box take", "box t"}) private class takeCapacitorAction implements coreAction { @Override public void run(String invoked, Scanner scanner) { if (!scanner.hasNextLine()) { coreGameHelper.addCommand("Take which capacitor?"); return; } String want = scanner.nextLine().trim(); for (int i = 0; i < caps.size(); i++) { coreItem c = caps.get(i); if (c.getItemName().equalsIgnoreCase(want)) { caps.remove(i); if (coreGame.getPlayerInventory().addItem(c)) { coreGameHelper.addCommand("You take " + c.getItemName() + "."); coreGame.removeDays(30 / 86400.0); } else { coreGameHelper.addCommand("You can't carry that."); caps.add(i, c); } return; } } coreGameHelper.addCommand("There's no " + want + " here."); } } } // Night Stand class bedroomNightstandObject extends coreObject { private coreItem[] drawers; private boolean[] drawersOpen; public bedroomNightstandObject() { super("Nightstand", "A worn wooden nightstand with three cramped drawers—its surface scratched and dust-covered, hinting at secrets within.", "furniture"); registerAction(new openDrawerAction()); drawers = new coreItem[]{ new schematicPartItem(1), new callBookItem(), new schematicPartItem(3) }; drawersOpen = new boolean[]{ false, false, false }; } public void openDrawer(int number) { if (number < 1 || number > 3) { coreGameHelper.addCommand("There is no such drawer! There are only 3 drawers, 1, 2, and 3."); } else { if(drawersOpen[number - 1]) { coreGameHelper.addCommand("This drawer has already been opened!"); if(drawers[number - 1] != null) { coreGameHelper.addCommand("However there is still a " + drawers[number - 1].getItemName() + "."); } } else { coreGameHelper.addCommand("You open drawer number " + number + "."); coreGameHelper.addCommand("You find " + (drawers[number - 1] == null ? "nothing" : drawers[number - 1].getItemName()) + "."); coreGame.removeDays(15 / 86400.0); drawersOpen[number - 1] = true; coreGame.addItemPlayerInventory(drawers[number - 1]); drawers[number - 1] = null; } } } @coreCommand({"nightstand open", "nightstand o"}) private class openDrawerAction implements coreAction // AI { public void run(String invoked, Scanner scanner) { if (invoked.equalsIgnoreCase("drawer")) { coreGameHelper.addCommand(Color.RED + "Open what?" + Color.RESET); return; } if (!scanner.hasNextInt()) { coreGameHelper.addCommand(Color.RED + "Which drawer number?" + Color.RESET); } else { openDrawer(scanner.nextInt()); } } } } // Kitchen Table class kitchenTableObject extends coreObject { private ArrayList<coreItem> tableItems; public kitchenTableObject(coreItem[] cIS) { super("Round Kitchen Table", "A worn round kitchen table scarred by candle wax and chipped plates. A loose schematic fragment lies among placemats and unlit candles.", "table"); tableItems = new ArrayList<coreItem>(); for (coreItem cI : cIS) tableItems.add(cI); registerAction(new examineTableAction()); registerAction(new takeTableAction()); } @coreCommand({"examine kitchen table", "x kitchen table", "examine table", "x table"}) private class examineTableAction implements coreAction { @Override public void run(String invoked, Scanner scanner) { coreGameHelper.describeContainer(getObjectDescription(), tableItems, "table"); coreGameHelper.addCommand("On the table is an engraving of a 30°-60°-90° triangle. The 30° angle faces east toward the living room window, and the 60° angle is on the north side."); coreGame.removeDays(60 / 86400.0); } } @coreCommand({"kitchen table take", "kitchen table t"}) private class takeTableAction implements coreAction { @Override public void run(String invoked, Scanner scanner) { if (!scanner.hasNext()) { coreGameHelper.addCommand("Take what from the table?"); return; } String want = scanner.nextLine().trim(); for (int i = 0; i < tableItems.size(); i++) { coreItem it = tableItems.get(i); if (it.getItemName().equalsIgnoreCase(want)) { if (coreGame.getPlayerInventory().addItem(it)) { tableItems.remove(i); coreGameHelper.addCommand("You take " + it.getItemName() + " from the table."); coreGame.removeDays(30 / 86400.0); } else coreGameHelper.addCommand("You can't carry that."); return; } } coreGameHelper.addCommand("There's no " + want + " on the table."); } } } // Grandfather Clock class grandfatherClockObject extends coreObject { private boolean calibrated = false; private double tickRate = 2.0; public grandfatherClockObject() { super("Grandfather Clock", "A towering wooden clock with elaborate carvings and a brass pendulum. Its face stubbornly reads 12:00 as it ticks steadily.", "furniture"); registerAction(new examineClockAction()); registerAction(new calibrateClockAction()); registerAction(new takeClockAction()); } @coreCommand({"examine clock", "x clock"}) private class examineClockAction implements coreAction { @Override public void run(String invoked, Scanner scanner) { coreGameHelper.addCommand(getObjectDescription()); if (calibrated) { coreGameHelper.addCommand("The clock is calibrated and ticks at " + tickRate + " times per second."); coreGame.removeDays(15 / 86400.0); } else { coreGameHelper.addCommand("The clock seems uncalibrated. It ticks at 2 times per second."); coreGameHelper.addCommand("A faint inscription reads 'III:II'."); coreGame.removeDays(15 / 86400.0); } } } @coreCommand({"calibrate clock"}) private class calibrateClockAction implements coreAction { @Override public void run(String invoked, Scanner scanner) // AI { List<coreItem> inv = coreGame.getPlayerInventory().getInventory(); String input = scanner.hasNext() ? scanner.nextLine().trim() : ""; if (input.isEmpty()) { coreGameHelper.addCommand("Which two gears will you use? Specify sizes, e.g. '5 12'."); return; } String[] parts = input.split("\\s+"); if (parts.length != 2) { coreGameHelper.addCommand("Please specify exactly two gear sizes, e.g. '5 12'."); return; } String size1 = parts[0]; String size2 = parts[1]; coreItem gear1 = null, gear2 = null; for (coreItem it : inv) { if (gear1 == null && it.getItemName().equalsIgnoreCase("Gear " + size1)) gear1 = it; else if (gear2 == null && it.getItemName().equalsIgnoreCase("Gear " + size2)) gear2 = it; } if (gear1 == null) { coreGameHelper.addCommand("You don't have gear " + size1 + "."); return; } if (gear2 == null) { coreGameHelper.addCommand("You don't have gear " + size2 + "."); return; } if (!(size1.equals("14") && size2.equals("21")) || (size1.equals("21") && size2.equals("14"))) { coreGameHelper.addCommand("Those gears won't calibrate the clock. Try some other gears."); coreGame.removeDays(120 / 86400.0); return; } coreGame.getPlayerInventory().removeItem(gear1); coreGame.getPlayerInventory().removeItem(gear2); calibrated = true; tickRate = 3.0; coreGameHelper.addCommand("You attach gears 14 and 21 and calibrate the clock. It now ticks at 3 times per second."); coreGame.removeDays(120 / 86400.0); } } @coreCommand({"take clock", "get clock", "pickup clock", "clock take", "clock pickup"}) private class takeClockAction implements coreAction { @Override public void run(String invoked, Scanner scanner) { if (!calibrated) { coreGameHelper.addCommand("The clock is uncalibrated. Pick it up later when it is calibrated."); return; } coreItem clockItem = new coreItem("Grandfather Clock", 30.0); if (coreGame.getPlayerInventory().addItem(clockItem)) { coreGame.getCurrentRoom().removeObject(grandfatherClockObject.this); coreGameHelper.addCommand("You take the Grandfather Clock."); coreGame.removeDays((5 * 60) / 86400.0); } else { coreGameHelper.addCommand("You can't carry that."); } } } } // Gear Box class gearBoxObject extends coreObject { private ArrayList<coreItem> gears; public gearBoxObject() { super("Gear Box", "A battered wooden box full of gleaming gears in sizes from tiny cogs to large wheels.", "container"); gears = new ArrayList<coreItem>(); gears.add(new coreItem("Gear 14", 0.1)); gears.add(new coreItem("Gear 18", 0.1)); gears.add(new coreItem("Gear 21", 0.1)); gears.add(new coreItem("Gear 24", 0.1)); registerAction(new examineBoxAction()); registerAction(new takeGearAction()); } @coreCommand({"examine box", "x box", "examine gears", "x gears"}) private class examineBoxAction implements coreAction { @Override public void run(String invoked, Scanner scanner) { coreGameHelper.addCommand(getObjectDescription()); if (gears.isEmpty()) coreGameHelper.addCommand("The box is empty."); else { coreGameHelper.addCommand("Inside you see:"); for (coreItem g : gears) coreGameHelper.addCommand("- " + g.getItemName()); coreGame.removeDays(20 / 86400.0); } } } @coreCommand({"box take", "box t"}) private class takeGearAction implements coreAction // AI { @Override public void run(String invoked, Scanner scanner) { if (!scanner.hasNext()) { coreGameHelper.addCommand("Take which gear?"); return; } String want = scanner.next(); for (int i = 0; i < gears.size(); i++) { coreItem g = gears.get(i); String name = g.getItemName().toLowerCase(); if (name.equalsIgnoreCase("gear " + want) || name.equalsIgnoreCase(want)) { if (coreGame.getPlayerInventory().addItem(g)) { gears.remove(i); coreGameHelper.addCommand("You take " + g.getItemName() + "."); } else coreGameHelper.addCommand("You can't carry that."); return; } } coreGameHelper.addCommand("There's no " + want + " gear here."); } } } ///////////////////////// // Workbench Object class workbenchObject extends coreObject { private ArrayList<coreItem> scraps; public workbenchObject() { super("Workbench", "A solid steel workbench cluttered with metal scraps—straight rods, curved brackets, coils of spring wire, and a lone lock pin.", "furniture"); scraps = new ArrayList<coreItem>(); scraps.add(new coreItem("Straight piece", 0.1)); scraps.add(new coreItem("Curved piece", 0.1)); scraps.add(new coreItem("Hook piece", 0.1)); scraps.add(new coreItem("Bent bracket", 0.1)); scraps.add(new coreItem("Lock pin", 0.05)); scraps.add(new coreItem("Spring coil", 0.05)); registerAction(new examineWorkbenchAction()); registerAction(new takeScrapAction()); registerAction(new weldAction()); } @coreCommand({"examine bench", "x bench", "examine workbench", "x workbench"}) private class examineWorkbenchAction implements coreAction { @Override public void run(String invoked, Scanner scanner) { coreGameHelper.addCommand(getObjectDescription()); if (scraps.isEmpty()) { coreGameHelper.addCommand("The workbench is empty."); coreGame.removeDays(15 / 86400.0); } else { coreGameHelper.addCommand("On the workbench you see:"); for (coreItem s : scraps) coreGameHelper.addCommand("- " + s.getItemName()); coreGame.removeDays(15 / 86400.0); } } } @coreCommand({"bench take", "bench t", "workbench take", "workbench t"}) private class takeScrapAction implements coreAction // AI { @Override public void run(String invoked, Scanner scanner) // AI { if (scraps.isEmpty()) { coreGameHelper.addCommand("There are no metal scraps left."); return; } if (!scanner.hasNextLine()) { coreGameHelper.addCommand("Take which scrap?"); return; } String want = scanner.nextLine().trim(); for (int i = 0; i < scraps.size(); i++) { coreItem s = scraps.get(i); if (s.getItemName().equalsIgnoreCase(want)) { scraps.remove(i); if (coreGame.getPlayerInventory().addItem(s)) { coreGameHelper.addCommand("You take " + s.getItemName() + "."); coreGame.removeDays(25 / 86400.0); } else { coreGameHelper.addCommand("You can't carry that."); scraps.add(i, s); } return; } } coreGameHelper.addCommand("There's no " + want + " on the workbench."); } } @coreCommand({"bench weld", "workbench weld"}) private class weldAction implements coreAction { @Override public void run(String invoked, Scanner scanner) // AI { String rest = scanner.hasNextLine() ? scanner.nextLine().trim() : ""; if (rest.isEmpty()) { coreGameHelper.addCommand( "Which two pieces will you weld? (e.g. bench weld straight curved)" ); return; } Scanner parts = new Scanner(rest); String p1 = parts.hasNext() ? parts.next().toLowerCase() : ""; String p2 = parts.hasNext() ? parts.next().toLowerCase() : ""; if (p1.isEmpty() || p2.isEmpty()) { coreGameHelper.addCommand("Please specify two pieces."); return; } String name1 = p1.equals("straight") ? "Straight piece" : p1.equals("curved") ? "Curved piece" : null; String name2 = p2.equals("straight") ? "Straight piece" : p2.equals("curved") ? "Curved piece" : null; if (name1 == null) { coreGameHelper.addCommand("Invalid piece."); coreGame.removeDays(5 / 86400.0); return; } if (name2 == null) { coreGameHelper.addCommand("Invalid piece."); coreGame.removeDays(5 / 86400.0); return; } ArrayList<coreItem> inv = coreGame.getPlayerInventory().getInventory(); coreItem item1 = null, item2 = null; for (coreItem it : inv) { if (item1 == null && it.getItemName().equalsIgnoreCase(name1)) item1 = it; else if (item2 == null && it.getItemName().equalsIgnoreCase(name2)) item2 = it; } if (item1 == null) { coreGameHelper.addCommand("You don't have " + name1 + "."); return; } if (item2 == null) { coreGameHelper.addCommand("You don't have " + name2 + "."); return; } boolean valid = (p1.equals("straight") && p2.equals("curved")) || (p1.equals("curved") && p2.equals("straight")); if (!valid) { coreGameHelper.addCommand("Those pieces won't weld together. Try some other pieces."); coreGame.removeDays(120 / 86400.0); return; } coreGame.getPlayerInventory().removeItem(item1); coreGame.getPlayerInventory().removeItem(item2); coreItem coupler = new coreItem("2 jaw coupler", 0.5); coreGame.getPlayerInventory().addItem(coupler); coreGameHelper.addCommand("You weld the straight and curved pieces into a 2 jaw coupler."); coreGame.removeDays((6 * 60) / 86400.0); } } } // Sundial Object class sundialObject extends coreObject { public sundialObject() { super("Sundial", "An aged bronze sundial with etched markers at 0°, 120°, and 240°, standing on the rooftop terrace under open sky.", "scenery"); registerAction(new examineSundialAction()); } @coreCommand({"examine sundial", "x sundial"}) private class examineSundialAction implements coreAction { @Override public void run(String invoked, Scanner scanner) { coreGameHelper.addCommand(getObjectDescription()); coreGameHelper.addCommand("You notice markings at 0°, 120°, and 240°."); coreGameHelper.addCommand("Three main parts of the day: morning, afternoon, evening."); coreGame.removeDays(30 / 86400.0); } } } // Photos class photoGalleryObject extends coreObject { private static class photoData { String title, desc, hint; photoData(String t, String d, String h){ title=t; desc=d; hint=h;} } // AI private ArrayList<photoData> photos; public photoGalleryObject() { super("Photo Collection", "Three faded photographs in wooden frames: you and your wife at the cinema, on a picnic, and on your wedding day—each a fragment of memory.", "scenery"); photos = new ArrayList<photoData>(); photos.add(new photoData("Movie Photo", "A photo of you and your wife at the old cinema.", "You recall films are shot at 24 frames per second.")); photos.add(new photoData("Picnic Photo", "A photo of you and your wife having a picnic in the park.", "You remember the warm sun and a gentle breeze.")); photos.add(new photoData("Wedding Photo", "A wedding photo of you and your wife on the day you married.", "You recall the joy of new beginnings.")); registerAction(new examineGalleryAction()); } @coreCommand({"examine gallery", "examine photos", "x photos", "examine photo", "x photo"}) private class examineGalleryAction implements coreAction { @Override public void run(String invoked, Scanner scanner) // AI { String rest = scanner.hasNextLine() ? scanner.nextLine().trim() : ""; if (!rest.isEmpty()) { int idx; try { idx = Integer.parseInt(rest) - 1; } catch (Exception e) { idx = -1; } if (idx < 0 || idx >= photos.size()) { coreGameHelper.addCommand("Please enter a number 1 through " + photos.size() + "."); return; } photoData sel = photos.get(idx); coreGameHelper.addCommand(sel.desc); coreGameHelper.addCommand(sel.hint); return; } coreGameHelper.addCommand(getObjectDescription()); coreGameHelper.addCommand("Which photo will you examine? (1-" + photos.size() + ")"); for (int i = 0; i < photos.size(); i++) { photoData p = photos.get(i); coreGameHelper.addCommand((i+1) + ". " + p.title); } String choice = scanner.hasNextLine() ? scanner.nextLine().trim() : ""; int idx; try { idx = Integer.parseInt(choice) - 1; } catch (Exception e) { idx = -1; } if (idx < 0 || idx >= photos.size()) { coreGameHelper.addCommand("Please enter a number 1 through " + photos.size() + "."); return; } photoData sel2 = photos.get(idx); coreGameHelper.addCommand(sel2.desc); coreGameHelper.addCommand(sel2.hint); coreGame.removeDays(25 / 86400.0); } } } // Projector Object in Living Room class projectorObject extends coreObject { private int fps = 0; public projectorObject() { super("Projector", "A vintage brass-lined film projector patched with tape and oil, its reels whispering of 24fps glory.", "device"); registerAction(new calibrateProjectorAction()); registerAction(new startProjectorAction()); registerAction(new projectorSpecsAction()); registerAction(new takeProjectorAction()); } @coreCommand({"calibrate projector", "projector set", "set projector"}) private class calibrateProjectorAction implements coreAction { @Override public void run(String invoked, Scanner scanner) { if (!scanner.hasNextInt()) { coreGameHelper.addCommand("Specify frame rate to set (e.g. 34)."); return; } fps = scanner.nextInt(); if (scanner.hasNextLine()) scanner.nextLine(); coreGameHelper.addCommand("Projector set to " + fps + " fps."); coreGame.removeDays(10 / 86400.0); } } @coreCommand({"start projector", "projector start", "launch projector"}) private class startProjectorAction implements coreAction { @Override public void run(String invoked, Scanner scanner) { if (fps != 24) { coreGameHelper.addCommand("The film jitters at " + fps + " fps. Nothing useful happens."); coreGame.removeDays(25 / 86400.0); } else { coreGameHelper.addCommand("You start the projector. A stabilized 3-frame loop appears, letting frames linger longer."); coreGame.removeDays(25 / 86400.0); } } } @coreCommand({"projector specs", "spec projector", "inspect projector"}) private class projectorSpecsAction implements coreAction { @Override public void run(String invoked, Scanner scanner) { coreGameHelper.addCommand(""" Projector Model XR-24 Input: 12V DC @ 0.5A Power Consumption: 6W J per Frame: 0.25J 2E / V^2 = C (F) 1F = 1000000uF """); coreGame.removeDays(15 / 86400.0); } } @coreCommand({"take projector", "pickup projector", "get projector", "projector take", "projector pickup", "projector get"}) private class takeProjectorAction implements coreAction { @Override public void run(String invoked, Scanner scanner) { if (fps != 24) { coreGameHelper.addCommand("Try calibrating the projector before taking it as a component."); return; } coreItem proj = new projectorItem(); if (coreGame.getPlayerInventory().addItem(proj)) { coreGame.getCurrentRoom().removeObject(projectorObject.this); coreGameHelper.addCommand("You take " + getObjectName() + "."); coreGame.removeDays(60 / 86400.0); } else { coreGameHelper.addCommand("You can't carry that."); } } } }
import java.util.*; public class coreRoom { private final String roomName; private boolean[] exits; //N, E, S, W (N is left) private String roomDescription; private ArrayList<coreObject> objects; private ArrayList<coreItem> items; public coreRoom(String rN, boolean[] e, String rD, coreObject[] cO) { roomName = rN; exits = e; roomDescription = rD; objects = new ArrayList<coreObject>(); for(coreObject cOi : cO) { objects.add(cOi); } items = new ArrayList<coreItem>(); } public void addObject(coreObject cO) { objects.add(cO); } public boolean removeObject(coreObject cO) { return objects.remove(cO); } public void addItem(coreItem item) { items.add(item); } public boolean[] getExits() { return exits; } public String getRoomDescription() { return roomDescription; } public String getRoomName() { return roomName; } public List<coreObject> getObjects() { return new ArrayList<coreObject>(objects); // inmutable } public boolean removeItem(coreItem item) { return items.remove(item); } public List<coreItem> getItems() { return new ArrayList<coreItem>(items); } }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue