How to implement connected rooms?

后端 未结 7 1219
难免孤独
难免孤独 2021-02-04 22:27

This may be a duplicate question as I don\'t know to phrase the search query. I\'m creating a Zork-like text based game in Java where the character moves to different rooms whic

7条回答
  •  盖世英雄少女心
    2021-02-04 23:07

    You can store your Room objects in a List or a Set or (as Lars D suggested) an array.

    Within Room, I think a nice way to store exits (considering they could be other than just the 4 cardinal directions) would be in a Map, with an Enum for the direction and the adjoining Room as the value.

    That's pretty efficient in storage space and should also be quick enough to navigate through.

提交回复
热议问题