| 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131 |
1×
1×
4×
1×
1×
1×
257×
1×
1×
1×
1×
257×
257×
257×
257×
257×
255×
255×
255×
255×
255×
255×
255×
255×
1×
7×
2×
2×
2×
1×
1×
6×
42×
42×
804×
1×
| 'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Card = exports.Color = exports.Icon = undefined;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { Eif (protoProps) defineProperties(Constructor.prototype, protoProps); Iif (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _enum = require('enum');
var _enum2 = _interopRequireDefault(_enum);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { Iif (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Icon = exports.Icon = new _enum2.default(['WHEAT', 'COW', 'GEAR', 'CUP']);
var Color = exports.Color = new _enum2.default(['RED', 'PURPLE', 'GREEN', 'BLUE']);
var Card = exports.Card = function () {
/**
* Create a new card
* @param {number} cost
* @param {string|EnumItem} icon
* @param {string|EnumItem} color
* @param {number[]|number} activation
* @param {string} description
* @param {Player} owner
*/
function Card(_ref) {
var _ref$cost = _ref.cost,
cost = _ref$cost === undefined ? 0 : _ref$cost,
_ref$icon = _ref.icon,
icon = _ref$icon === undefined ? Icon.WHEAT : _ref$icon,
_ref$color = _ref.color,
color = _ref$color === undefined ? Color.BLUE : _ref$color,
_ref$activation = _ref.activation,
activation = _ref$activation === undefined ? [] : _ref$activation,
_ref$description = _ref.description,
description = _ref$description === undefined ? '' : _ref$description,
owner = _ref.owner;
_classCallCheck(this, Card);
if (typeof activation === 'number') activation = [activation];
if (typeof color === 'string') color = Color.get(color.toUpperCase());
if (!color) throw TypeError('Color is not valid');
if (typeof icon === 'string') icon = Icon.get(icon.toUpperCase());
Iif (!icon) throw TypeError('Icon is not valid');
this.cost = cost;
this.activation = activation;
this.description = description;
this.color = color;
this.icon = icon;
if (owner) this.setOwner(owner);
}
/**
* When dice are rolled activate me for owner
* @param {number} number
* @param {Player=} player
*/
_createClass(Card, [{
key: 'rolled',
value: function rolled(number, player) {
if (this.activation.indexOf(number) > -1) {
// BLUE card has owner
Iif (this.color === Color.BLUE && this.owner) {
this.activate();
return true;
}
// RED card owned by someone else
Iif (this.color === Color.RED && this.owner !== player) {
this.activate(player);
return true;
}
// GREEN or PURPLE card owned by roller
if (this.color & (Color.GREEN | Color.PURPLE) && this.owner === player) {
this.activate();
return true;
}
}
return false;
}
/**
* card belongs to a player
* @param {Player} player
*/
}, {
key: 'setOwner',
value: function setOwner(player) {
this.owner = player;
player.cards.push(this);
}
/**
* Name of card
* @return {string}
*/
}, {
key: 'activate',
/**
* @abstract
*/
value: function activate() {}
}, {
key: 'name',
get: function get() {
return this.constructor.name.replace(/([a-z])([A-Z])/g, '$1 $2').trim();
}
}]);
return Card;
}();
//# sourceMappingURL=Card.js.map |