/* * BAGSConnection.bsh * * Copyright 2005 M. Aaron Wadley * * This file is part of BAGS (Beany Adventure Game System). * BAGS (Beany Adventure Game System) is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * BAGS (Beany Adventure Game System) is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with BAGS (Beany Adventure Game System); if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /* Directions */ EXIT_UNDEFINED = 0; EXIT_NORTH = 1; EXIT_SOUTH = 2; EXIT_EAST = 3; EXIT_WEST = 4; EXIT_UP = 5; EXIT_DOWN = 6; EXIT_NORTHEAST = 7; EXIT_NORTHWEST = 8; EXIT_SOUTHEAST = 9; EXIT_SOUTHWEST = 10; EXIT_IN = 11; EXIT_OUT = 12; /** Direction names */ String[] dirNames = { "UNDEFINED", "NORTH", "SOUTH", "EAST", "WEST", "UP", "DOWN", "NORTHEAST", "NORTHWEST", "SOUTHEAST", "SOUTHWEST", "IN", "OUT" }; /** Short direction names */ String[] shortDirNames = { "NULL", "N", "S", "E", "W", "U", "D", "NE", "NW", "SE", "SW", "I", "O" }; /** * Get the direction from the name. * @param name * @return direction */ getDirFromName(name) { for (int i=0; i pointB=" + pointB + ", pointBDir=" + pointBDir; } return this; } /** * Overloaded constructor. */ Connection(paLoc, paDir, pbLoc, pbDir, theDoor) { c = Connection(paLoc, paDir,pbLoc, pbDir); c.door = theDoor; return c; } /** * Door between rooms * TODO implement keyring stuff */ Door(closed, locked, lockDir, keyId) { isClosed = closed; isLocked = locked; lockSide = lockDir; theKey = keyId; /** * Generic unlock routine * @return success */ unlock() { if (isLocked) { if (game.currentLocation.roomId.equals(lockSide)) { // echo success message isLocked = false; return true; } else { // search inventory for correct key // for each key in inventory // if (unlock(game, key)) { // return true; // } // return false; } } else { // echo message about uneccesary return true; } } /** * Generic locking routine * @return success */ lock() { if (!isLocked) { if (game.currentLocation.roomId.equals(lockSide)) { // echo success message isLocked = true; return true; } else { // search inventory for correct key // for each key in inventory // if (lock(game, key)) { // return true; // } // return false; } } else { // echo message about uneccesary return true; } } /** * Unlock a door with a given key. * @param key * @return success */ unlock(key) { if (isLocked) { if (room.roomId.equals(lockSide)) { // echo success message isLocked = false; return true; } else { if (key.equals(theKey)) { isLocked = false; // echo success message return true; } else { // echo failure message return false; } } } else { // echo message about uneccesary return true; } } /** * Lock a door with a given key. * @param key * @return success */ lock(key) { return true; } return this; }