-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCommandWords.java
54 lines (51 loc) · 1.78 KB
/
CommandWords.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
* This class is part of the "World of Zuul" application.
* "World of Zuul" is a very simple, text based adventure game.
*
* This class holds an enumeration table of all command words known to the game.
* It is used to recognise commands as they are typed in.
*
* @author Michael Kolling and David J. Barnes + D.Bureau + A.Aubert
* @version 2008.03.30 + 2019.09.25 + 08/05/21
*/
public class CommandWords
{
// a constant array that will hold all valid command words
private final String[] aValidCommands;
/**
* Constructor - initialise the command words.
* cree un tableau de string avec "go", "help", "quit","look","eat","back" et pour les autres commande word
*/
public CommandWords()
{
this.aValidCommands = new String[] {"go","back","help","look","eat","take","drop","items","use","test","quit", "alea"};
}//CommandWords()
/**
* return toutes les cmd valides
* est aussi apl dans Parser avec showCommands()
* @return vStr return toutes les cmd valides
*/
public String getCommandList()
{
String vStr="";
for( String vCommand : this.aValidCommands){
vStr += vCommand + " ";
}// for
return vStr;
}//getCommandList()
/**
* Check whether a given String is a valid command word.
* @param pString est une string
* @return true if a given string is a valid command,
* false if it isn't.
*/
public boolean isCommand( final String pString )
{
for ( int i=0; i<this.aValidCommands.length; i++ ) {
if ( this.aValidCommands[i].equals( pString ) )
return true;
} // for
// if we get here, the string was not found in the commands
return false;
} // isCommand(.)
}//CommandWords