Starting to try and make modules out of the class Cards (WIP : will require a stateful «Game.Context» module and all kind of uglyness)
This commit is contained in:
parent
d5b846421c
commit
07cf48e857
3 changed files with 45 additions and 37 deletions
|
@ -2,20 +2,20 @@ import Hanafuda;
|
||||||
import * as Dom from UnitJS.Dom;
|
import * as Dom from UnitJS.Dom;
|
||||||
|
|
||||||
function Card(name) {
|
function Card(name) {
|
||||||
this.value = Hanafuda.Card[name];
|
var value = Hanafuda.Card[name];
|
||||||
this.name = name;
|
var dom = Dom.make('li', {
|
||||||
this.dom = Dom.make('li', {
|
class: [
|
||||||
class: [
|
"card",
|
||||||
"card",
|
"value" + Hanafuda.getValue(this.value),
|
||||||
"value" + Hanafuda.getValue(this.value),
|
"month" + this.value.flower
|
||||||
"month" + this.value.flower
|
]
|
||||||
],
|
});
|
||||||
onClick: this.onClick()
|
return {
|
||||||
});
|
value: value,
|
||||||
|
dom: dom
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
Card.prototype.onClick = function() {return function() {};};
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
Card: Card
|
make: Card
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,27 +1,34 @@
|
||||||
|
import * as Card from GUI.Card;
|
||||||
|
|
||||||
function RiverCard() {
|
function RiverCard(name) {
|
||||||
Card.apply(this, arguments);
|
var card = Card.make(name);
|
||||||
this.candidate = false;
|
var candidate = false;
|
||||||
|
card.onClick = onClick;
|
||||||
|
card.setCandidate = setCandidate;
|
||||||
|
return card;
|
||||||
|
|
||||||
|
function onClick() {
|
||||||
|
return function() {
|
||||||
|
if(candidate) {
|
||||||
|
var withCard = selected.name;
|
||||||
|
selected.setSelected(false);
|
||||||
|
play(
|
||||||
|
status.step == 'ToPlay' ? {capture: [withCard, card.name]} : {choose: card.name}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function setCandidate() {
|
||||||
|
candidate = yes;
|
||||||
|
card.dom.classList.toggle("candidate", yes);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RiverCard.prototype.onClick = function() {
|
RiverCard.prototype.onClick = function() {
|
||||||
var card = this;
|
var card = this;
|
||||||
return function() {
|
|
||||||
if(card.candidate) {
|
|
||||||
var withCard = selected.name;
|
|
||||||
selected.setSelected(false);
|
|
||||||
play(
|
|
||||||
status.step == 'ToPlay' ? {capture: [withCard, card.name]} : {choose: card.name}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
RiverCard.prototype.setCandidate = function(yes) {
|
|
||||||
this.candidate = yes;
|
|
||||||
this.dom.classList.toggle("candidate", yes);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
RiverCard: RiverCard
|
make: RiverCard
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
|
import * as Card from GUI.Card;
|
||||||
|
|
||||||
function TurnedCard() {
|
function TurnedCard(name) {
|
||||||
Card.apply(this, arguments);
|
var card = Card.make(name);
|
||||||
this.dom.id = "turned";
|
card.dom.id = "turned";
|
||||||
deck.appendChild(this.dom);
|
deck.appendChild(this.dom);
|
||||||
}
|
}
|
||||||
|
|
||||||
TurnedCard.prototype.onClick = Card.prototype.onClick;
|
TurnedCard.prototype.onClick = Card.prototype.onClick;
|
||||||
TurnedCard.prototype.setSelected = setSelected;
|
TurnedCard.prototype.setSelected = setSelected;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
TurnedCard: TurnedCard
|
make: TurnedCard
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue