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:
Tissevert 2020-01-14 22:14:55 +01:00
parent d5b846421c
commit 07cf48e857
3 changed files with 45 additions and 37 deletions

View file

@ -2,20 +2,20 @@ import Hanafuda;
import * as Dom from UnitJS.Dom;
function Card(name) {
this.value = Hanafuda.Card[name];
this.name = name;
this.dom = Dom.make('li', {
class: [
"card",
"value" + Hanafuda.getValue(this.value),
"month" + this.value.flower
],
onClick: this.onClick()
});
var value = Hanafuda.Card[name];
var dom = Dom.make('li', {
class: [
"card",
"value" + Hanafuda.getValue(this.value),
"month" + this.value.flower
]
});
return {
value: value,
dom: dom
};
}
Card.prototype.onClick = function() {return function() {};};
return {
Card: Card
make: Card
};

View file

@ -1,27 +1,34 @@
import * as Card from GUI.Card;
function RiverCard() {
Card.apply(this, arguments);
this.candidate = false;
function RiverCard(name) {
var card = Card.make(name);
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() {
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}
);
}
};
var card = this;
};
RiverCard.prototype.setCandidate = function(yes) {
this.candidate = yes;
this.dom.classList.toggle("candidate", yes);
}
return {
RiverCard: RiverCard
make: RiverCard
};

View file

@ -1,13 +1,14 @@
import * as Card from GUI.Card;
function TurnedCard() {
Card.apply(this, arguments);
this.dom.id = "turned";
deck.appendChild(this.dom);
function TurnedCard(name) {
var card = Card.make(name);
card.dom.id = "turned";
deck.appendChild(this.dom);
}
TurnedCard.prototype.onClick = Card.prototype.onClick;
TurnedCard.prototype.setSelected = setSelected;
return {
TurnedCard: TurnedCard
make: TurnedCard
};