-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRoomRandomizer.java
More file actions
69 lines (58 loc) · 1.46 KB
/
RoomRandomizer.java
File metadata and controls
69 lines (58 loc) · 1.46 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import java.util.HashMap;
import java.util.ArrayList;
import java.util.Random;
/**
* classe permettant d'obtenir des Room aléatoires
* @author Clément Chomicki
*/
public class RoomRandomizer
{
private HashMap<String, Room> aRooms;
private String aNext;
private Random aRNG;
/**
* Constructeur
* @param pMap le HashMap des Rooms dont disposera le RoomRandomizer
*/
public RoomRandomizer(final HashMap<String, Room> pMap)
{
this.aRooms = pMap;
this.aRNG = new Random();
} //RoomRandomizer()
/**
* teste si le mot designe une Room de l'objet
* @param pWord le mot a teste
* @return un boolean
*/
public boolean doesExist(final String pWord)
{
return this.aRooms.containsKey(pWord);
} //doesExist()
/**
* utile pour la commande alea
* @param pString la String designant la prochaine Room tiree
*/
public void setNext(final String pString)
{
this.aNext = pString;
} //setNext()
/**
* Retourne la Room correspondante a aNext ou une Room aleatoire
* @return une Room parmis celles possibles
*/
public Room getRandomRoom()
{
if (this.aNext != null)
{
String vNext = this.aNext;
this.aNext = null;
return this.aRooms.get(vNext);
}
else
{
ArrayList<Room> vList = new ArrayList<Room>(this.aRooms.values());
int vI = this.aRNG.nextInt(vList.size());
return vList.get(vI);
}
} //getRandomRoom()
}