/* * BAGSMain.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 */ import java.util.*; import java.io.*; TRUE="true"; FALSE="false"; isNotNull(obj) { if (obj != void && obj != null) { return true; } else { return false; } } isNull(obj) { if (obj == void || obj == null) { return true; } else { return false; } } isTrue(String toCompare) { if (toCompare.equalsIgnoreCase(TRUE)) { return true; } else { return false; } } isFalse(String toCompare) { if (toCompare.equalsIgnoreCase(FALSE)) { return true; } else { return false; } } toggleBoolean(toToggle) { if (isTrue(toToggle)) { return FALSE; } else { return TRUE; } } /* Display options */ if (showTurns==void) { showTurns = TRUE; } if (showStatus==void) { showStatus = TRUE; } if (showRoom==void) { showRoom = TRUE; } if (debugInGame==void) { debugInGame = FALSE; } if (displayGameInfo==void) { displayGameInfo = TRUE; } if (displayBAGSInfo==void) { displayBAGSInfo = TRUE; } if (loglevel==void) { loglevel = null; } logThreshold=10; historyLines = 1000; game; /** * Main object. */ BAGSMain() { HOME=System.getenv("HOME"); File bagsPrefsFile = new File(HOME + ".bagsrc"); selectGame() { JFileChooser chooser = new JFileChooser(HOME); BAGSGameFilter gameFilter = new BAGSGameFilter(); chooser.addChoosableFileFilter(gameFilter); int returnVal = chooser.showOpenDialog(null); if(returnVal == JFileChooser.APPROVE_OPTION) { return chooser.getSelectedFile().getAbsolutePath(); } else { result = JOptionPane.showConfirmDialog(null, "Are you sure you want to quit?", "Exit confirmation", JOptionPane.YES_NO_OPTION); if (result == JOptionPane.OK_OPTION) { exit(); } else { return ""; } } } gameId; pathToGame; cwd; File f = new File(jarFileName); if (jarFileName == null || jarFileName.equals("")) { while((jarFileName=selectGame()).equals("")) { } f = new File(jarFileName); } if (f.getName().endsWith(".jar")) { // Extract the jar file with the game JarExtractor extractor = new JarExtractor(jarFileName, BAGS_GAMES); extractor.extract(); // Get the game ID String jarFileNameOnly = f.getName(); gameId = jarFileNameOnly.split("\\.")[0]; } else if (f.getName().equals("bags.properties")) { if (File.separator.equals("\\")) { separator = "\\\\"; } else { separator = File.separator; } String[] paths = f.getAbsolutePath().split(separator); l = paths.length; gameId = paths[l-2]; i = f.getAbsolutePath().indexOf(gameId); BAGS_GAMES=f.getAbsolutePath().substring(0,i); } /** * Main method */ runGame() { try { //pwd(); // Load the BAGS code source("BAGSGame.bsh"); } catch(Exception ex) { ex.printStackTrace(); } /** The BAGS game */ game = Game(); try { source(preloadFile); } catch(ex) { ex.printStackTrace(); } game.displayIntro(); game.showLocation(); } return this; } bagsMain = BAGSMain();