2018-11-18 18:04:50 +00:00
|
|
|
import Rectangle from "./rectangle.js";
|
2018-11-19 07:59:20 +00:00
|
|
|
import Circle from "./circle.js";
|
2018-11-20 13:55:17 +00:00
|
|
|
import Triangle from "./triangle.js";
|
2018-11-18 18:04:50 +00:00
|
|
|
|
2018-11-20 13:55:17 +00:00
|
|
|
const options = {
|
|
|
|
rectangle: Rectangle,
|
|
|
|
circle : Circle,
|
|
|
|
triangle : Triangle
|
|
|
|
};
|
|
|
|
|
|
|
|
let collection = [
|
|
|
|
Circle, Rectangle, Triangle
|
2018-11-19 07:59:20 +00:00
|
|
|
];
|
2018-11-18 18:04:50 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
createRandomShape: function() {
|
2018-11-20 13:55:17 +00:00
|
|
|
let Shape = collection[Math.floor(Math.random() * collection.length)];
|
2018-11-19 07:59:20 +00:00
|
|
|
|
|
|
|
return Shape.fromOptions(Shape.randomOptions());
|
2018-11-20 13:55:17 +00:00
|
|
|
},
|
|
|
|
setCollection(obj) {
|
|
|
|
collection = [];
|
|
|
|
let keys = Object.keys(obj);
|
|
|
|
for (let i = 0; i < keys.length; ++i) {
|
|
|
|
let key = keys[i];
|
|
|
|
if (obj[key]) {
|
|
|
|
collection.push(options[key]);
|
|
|
|
}
|
|
|
|
}
|
2018-11-18 18:04:50 +00:00
|
|
|
}
|
|
|
|
};
|