| Directions.java |
1 /*
2 * CVS: $Id: Directions.java,v 1.4 2004/07/16 16:22:33 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;
25
26/**
27 * Diese Klasse definiert Konstanten für Type Variablen in der {@link org.jzuul.engine.GameMap}
28 *
29 *
30 * @version $Revision: 1.4 $
31 */
32public class Directions {
33 /**
34 * Die Anzahl der unterschiedlichen Richtungen
35 */
36 public static final int NUMBER_OF_DIRECTIONS = 6;
37
38 /**
39 * Room befindet sich im Norden von Room
40 */
41 public static final int NORTH_OF = 0;
42
43 /**
44 * Room befindet sich im Osten von Room
45 */
46 public static final int EAST_OF = 1;
47
48 /**
49 * Room befindes sich im Süden von Room
50 */
51 public static final int SOUTH_OF = 2;
52
53 /**
54 * Room befindes sich im Westen von Room
55 */
56 public static final int WEST_OF = 3;
57
58 /**
59 * Room befindet sich über Room (es existiert eine Treppe)
60 */
61 public static final int TOP_OF = 4;
62
63 /**
64 * Room befindet sich unter Room (es existiert eine Treppe)
65 */
66 public static final int BELOW_OF = 5;
67
68 /**
69 * Semantischer Alias für NORTH_OF
70 */
71 public static final int NORTH = NORTH_OF;
72
73 /**
74 * Semantischer Alias für EAST_OF
75 */
76 public static final int EAST = EAST_OF;
77
78 /**
79 * Semantischer Alias für SOUTH_OF
80 */
81
82 public static final int SOUTH = SOUTH_OF;
83
84 /**
85 * Semantischer Alias für WEST_OF
86 */
87 public static final int WEST = WEST_OF;
88
89 /**
90 * Semantischer Alias für TOP_OF
91 */
92 public static final int TOP = TOP_OF;
93
94 /**
95 * Semantischer Alias für BELOW_OF
96 */
97 public static final int BELOW = BELOW_OF;
98
99 /**
00 * Ein Richtungsfehler
01 */
02 public static final int DIRECTION_ERROR = -1;
03
04 /**
05 * Wandelt eine Direction Konstante in die text Representation um
06 *
07 * @param direction Eine direction Konstante
08 * @return Die Stringrepresentation der Konstant, null bei fehler
09 */
10 public static String getDirectionName(int direction) {
11 switch (direction) {
12 case NORTH :
13 return "north";
14 case EAST :
15 return "east";
16 case SOUTH :
17 return "south";
18 case WEST :
19 return "west";
20 case BELOW :
21 return "below";
22 case TOP :
23 return "above";
24
25 case DIRECTION_ERROR :
26 return "DIRECTION ERROR";
27 }
28 return null;
29 }
30
31 /**
32 * Wandelt einen Richtungsnamen in seine Zahl um
33 *
34 * @param direction der Name einer Himmelrichtung
35 * @return die zugehörige Direction Nummer, DIRECTION_ERROR bei unbekanntem Namen
36 */
37 public static int directionToInt(String direction){
38 if(direction.equalsIgnoreCase("north")){
39 return NORTH;
40 }
41 else if(direction.equalsIgnoreCase("east")){
42 return EAST;
43 }
44 else if(direction.equalsIgnoreCase("south")){
45 return SOUTH;
46 }
47 else if(direction.equalsIgnoreCase("west")){
48 return WEST;
49 }
50 else if(direction.equalsIgnoreCase("above")){
51 return TOP;
52 }
53 else if(direction.equalsIgnoreCase("below")){
54 return BELOW;
55 }
56 else if(direction.equalsIgnoreCase("up")){
57 return TOP;
58 }
59 else if(direction.equalsIgnoreCase("down")){
60 return BELOW;
61 }
62 else{
63 return Directions.DIRECTION_ERROR;
64 }
65 }
66
67
68}
69