I am trying to create a MUD as fun project to practice JS (I am a total noob but have been inspired to learn more by codecademy!) and I was hoping that I could get some advice on how to go about representing my dungeon in JS.
The features I would like to have for my dungeon are:
- Dungeon should have a random number of rooms (within specified parameters)
- Rooms should be automatically populated with monsters
- (We can ignore how the rooms are connected for now)
Seeing as JS is OO language I thought that the best way to represent the dungeon would be as an object:
var dungeon = {
var room1:roomA,
var room2:roomB,
var room3:roomC
}
//RoomX is an object created with the following constructor
function Room(){
this.description: "Some text",
this.monsters:[monster1,monster2,monster3],
this.treasure:[treasure1,treasure2,treasure3]
}
The plan is to then create methods for the Room object allowing a player to interact with the stuff in the room.
Questions:
1) Is this a good idea/will it work?
2) How do I generate a random number of properties for an object?
Thanks!