Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
genie_logiciel_2015
the_dungeon_project
Commits
f16d0f12
Commit
f16d0f12
authored
Jan 06, 2016
by
Lucas Delcros
Browse files
Added javadoc
parent
cd34735b
Changes
1
Show whitespace changes
Inline
Side-by-side
src/map_generation/map/RoomGraph.java
View file @
f16d0f12
...
...
@@ -13,6 +13,11 @@ public class RoomGraph {
private
HashMap
<
RoomBuilder
,
RoomNode
>
rooms
;
private
boolean
isBuilded
=
false
;
/**
*
* @param start starting room
* @param rooms all the rooms
*/
public
RoomGraph
(
RoomBuilder
start
,
ArrayList
<
RoomBuilder
>
rooms
)
{
this
.
rooms
=
new
HashMap
<
RoomBuilder
,
RoomGraph
.
RoomNode
>();
for
(
RoomBuilder
room
:
rooms
)
{
...
...
@@ -22,14 +27,30 @@ public class RoomGraph {
if
(
this
.
start
==
null
)
throw
new
IllegalArgumentException
(
"Start is not is room list !"
);
}
/**
* Finds a room Node according to a RoomBuilder
* @param room
* @return
*/
private
RoomNode
findRoom
(
RoomBuilder
room
){
return
rooms
.
get
(
room
);
}
/**
* Add room a son of room father
* @param room
* @param fatherNode
*/
private
void
addRoomTo
(
RoomNode
room
,
RoomNode
fatherNode
){
if
(
fatherNode
.
voisins
==
null
)
fatherNode
.
voisins
=
new
ArrayList
<
RoomGraph
.
RoomNode
>();
if
(!
fatherNode
.
voisins
.
contains
(
room
))
fatherNode
.
voisins
.
add
(
room
);
}
/**
* Links room1 and room2 in graph
* @param room1
* @param room2
*/
public
void
linkRooms
(
RoomBuilder
room1
,
RoomBuilder
room2
){
RoomNode
fatherNode
=
findRoom
(
room1
);
RoomNode
roomNode
=
findRoom
(
room2
);
...
...
@@ -38,11 +59,23 @@ public class RoomGraph {
addRoomTo
(
roomNode
,
fatherNode
);
addRoomTo
(
fatherNode
,
roomNode
);
}
/**
* Checks if room1 and room2 are linked
* @param room1
* @param room2
* @return
*/
public
boolean
areLinked
(
RoomBuilder
room1
,
RoomBuilder
room2
){
RoomNode
n
=
findRoom
(
room1
),
n2
=
findRoom
(
room2
);
if
(
n
.
voisins
==
null
)
return
false
;
return
n
.
voisins
.
contains
(
n2
);
}
/**
*
* @return a list containing all the rooms that are not reachable from the starting room
*/
public
ArrayList
<
RoomBuilder
>
getNonReachableRooms
(){
ArrayList
<
RoomBuilder
>
res
=
new
ArrayList
<
RoomBuilder
>();
for
(
RoomBuilder
room
:
rooms
.
keySet
()){
...
...
@@ -50,9 +83,12 @@ public class RoomGraph {
}
return
res
;
}
public
void
removeRoom
(
RoomBuilder
room
){
rooms
.
remove
(
room
);
}
/**
* Inner function for buildLeft function
* @param top
* @param l
*/
private
void
buildLength_inner
(
RoomNode
top
,
int
l
){
if
(
top
.
ltostart
>
-
1
&&
top
.
ltostart
<
l
)
return
;
top
.
ltostart
=
l
;
...
...
@@ -61,10 +97,20 @@ public class RoomGraph {
if
(
voisin
.
ltostart
==
-
1
)
buildLength_inner
(
voisin
,
l
+
1
);
}
}
/**
* Builds the length of all the rooms in the graph
* The length of a room is it's distance (in rooms) from the starting room
*/
private
void
buildLength
(){
buildLength_inner
(
start
,
0
);
isBuilded
=
true
;
}
/**
*
* @return The farthest room in the graph for the starting room
*/
public
RoomBuilder
getMostFarNode
(){
if
(!
isBuilded
)
buildLength
();
RoomNode
max
=
start
;
...
...
@@ -74,21 +120,43 @@ public class RoomGraph {
}
return
max
.
room
;
}
/**
* Checks that a room is reachable
* @param room
* @return
*/
public
boolean
roomIsReachable
(
RoomBuilder
room
){
if
(!
isBuilded
)
buildLength
();
return
rooms
.
get
(
room
).
ltostart
!=
-
1
;
}
/**
* Checks that all the rooms are reachable
* @return
*/
public
boolean
everyRoomIsReachable
(){
for
(
RoomBuilder
room
:
rooms
.
keySet
()){
if
(!
roomIsReachable
(
room
))
return
false
;
}
return
true
;
}
/**
* Check whether a room is a dead-end in the graph
* @param room
* @return
*/
private
boolean
isDeadEnd
(
RoomBuilder
room
){
RoomNode
node
=
rooms
.
get
(
room
);
if
(
node
.
voisins
==
null
)
return
true
;
return
node
.
voisins
.
size
()
==
1
;
}
/**
*
* @return All list of all the dead-ends in the graph
*/
public
ArrayList
<
RoomBuilder
>
getDeadEnds
(){
ArrayList
<
RoomBuilder
>
deadEnds
=
new
ArrayList
<
RoomBuilder
>();
for
(
RoomBuilder
room
:
rooms
.
keySet
()){
...
...
@@ -96,7 +164,11 @@ public class RoomGraph {
}
return
deadEnds
;
}
class
RoomNode
{
/**
* Inner class of a Node in the Graph of Rooms
*/
private
ArrayList
<
RoomNode
>
voisins
;
private
RoomBuilder
room
;
private
int
ltostart
=
-
1
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment