-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.js
49 lines (38 loc) · 990 Bytes
/
config.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
"use strict";
class Config {
constructor(rows, cols, minesPercentage) {
if ((rows || 0) < 5) {
throw 'The number of rows must be greater than 5';
}
if ((cols || 0) < 5) {
throw 'The number of columns must be greater than 5';
}
if ((minesPercentage || 0) === 0) {
throw 'The percentage of mines must be greater than zero';
}
this._rows = rows;
this._cols = cols;
this._minesPercentage = minesPercentage;
this._totalNumber = this._rows * this._cols;
this._minesNumber = Math.round(this._totalNumber * (this._minesPercentage / 100));
this._emptyNumber = this._totalNumber - this._minesNumber;
}
get rows() {
return this._rows;
}
get cols() {
return this._cols;
}
get minesPercentage() {
return this._minesPercentage;
}
get totalNumber() {
return this._totalNumber;
}
get minesNumber() {
return this._minesNumber;
}
get emptyNumber() {
return this._emptyNumber;
}
}