This repository has been archived by the owner on Nov 28, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathroom.js
97 lines (84 loc) · 1.95 KB
/
room.js
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
* CLASS: Room
*
*/
//---------------------------
//
// Global variables
//
//----------------------
//
var rooms = [];
var roomCount = 0;
//---------------------------
//
// CONSTRUCTOR
//
//----------------------
//
function Room()
{
this.x = -1;
this.y = -1;
this.title;
this.descr = "";
this.item = null; // Item currently present in the room
this.discovered = false; // If the Room has been visited before or not
this.reqKey = null; // Item required for entry
}
//---------------------------
//
// MEMBER METHODS
//
//----------------------
//
Room.prototype.checkKey = function()
{// Returns TRUE if the Room is unlockable
//
if(this.reqKey == null) return false;
if(currentItem == this.reqKey) return false;
if(this.item == this.reqKey) return false;
//
return true;
}
//---------------------------
//
// STATIC METHODS
//
//----------------------
//
var addRoom = function(x_, y_, title_, descr_, reqKey_, item_)
{// Adds a Room instance to the 'rooms' global container
//
// int x_
// int y_
// string title_
// string descr_
// string reqKey_ (ignore or set to 'null' if not used)
// string item_ (ignore if not used)
//
reqKey_ = typeof reqKey_ == 'undefined' ? null : reqKey_;
item_ = typeof item_ == 'undefined' ? null : item_;
//
// Make sure the 2D container has enough columns
while(rooms.length-1 < x_) {
rooms.push([]);
}
//
// Clamp title (32 chars), description (256 chars) and item/key (16) strings
title_ = title_.substr(0,32);
descr_ = descr_.substr(0,256);
reqKey_ = reqKey_ != null ? reqKey_.substr(0,16) : null;
item_ = item_ != null ? item_.substr(0,16) : null;
//
// Create and store the new Room
rooms[x_][y_] = new Room();
rooms[x_][y_].x = x_;
rooms[x_][y_].y = y_;
rooms[x_][y_].title = title_;
rooms[x_][y_].descr = descr_;
rooms[x_][y_].reqKey = reqKey_;
rooms[x_][y_].item = item_;
//
roomCount++; // Needed to calculate what percentage of the total game has been explored
}