1 /*
2  *  CVS: $Id: Go.java,v 1.6 2004/07/25 21:40:55 marcus Exp $
3  * 
4  *  This file is part of JZuul.
5  *
6  *  JZuul is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10 *
11 *  JZuul is distributed in the hope that it will be useful,
12 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 *  GNU General Public License for more details.
15 *
16 *  You should have received a copy of the GNU General Public License
17 *  along with Zuul; if not, write to the Free Software
18 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 * 
20 *  Copyrigth 2004 by marcus, leh
21 * 
22 */
23
24package org.jzuul.engine.commands;
25import java.text.MessageFormat;
26
27import org.jzuul.engine.*;
28import org.jzuul.engine.rooms.*;
29
30/**
31 * 
32 */
33public class Go extends Command {
34
35    public Go() {
36        super();
37        this.name = "go"; //$NON-NLS-1$
38        this.arguments = 1;
39        this.desc =
40            Messages.getString("GO_HELP"); //$NON-NLS-1$
41    }
42
43    protected boolean action() {
44        Room myCurrentRoom = player.getCurrentRoom();
45        String direction = args[0];
46        Object[] formatArgs = { args[0] };
47        if (!(direction.equals("north") //$NON-NLS-1$
48            || direction.equals("south") //$NON-NLS-1$
49            || direction.equals("west") //$NON-NLS-1$
50            || direction.equals("east") //$NON-NLS-1$
51            || direction.equals("down") //$NON-NLS-1$
52            || direction.equals("up") //$NON-NLS-1$
53            || direction.equals("back"))) { //$NON-NLS-1$
54            player.say(MessageFormat.format(Messages.getString("GO_DIRECTION_ERROR"), formatArgs)); //$NON-NLS-1$
55            return false;
56        }
57            if (args[0].equals("back")) { //$NON-NLS-1$
58            Room nextRoom = player.getLastRoom();
59            if (nextRoom == null) {
60                player.say(Messages.getString("GO_BACK_ERROR")); //$NON-NLS-1$
61                return false;
62            }
63            player.setCurrentRoom(nextRoom);
64            return true;
65        }
66
67        if (myCurrentRoom.getRoomByOrientation(args[0]) != null) {
68            Room nextRoom = myCurrentRoom.getRoomByOrientation(args[0]);
69            player.setCurrentRoom(nextRoom);
70            return true;
71        } else {
72            player.say(MessageFormat.format(Messages.getString("GO_WAY_ERROR"),formatArgs)); //$NON-NLS-1$
73            return false;
74        }
75    }
76
77    public void help() {
78        super.help();
79        Engine.gui.println(Messages.getString("GO_HELP_USAGE")); //$NON-NLS-1$
80    }
81}
82