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,13 +1,15 @@
|
||||||
|
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;
|
||||||
|
|
||||||
RiverCard.prototype.onClick = function() {
|
function onClick() {
|
||||||
var card = this;
|
|
||||||
return function() {
|
return function() {
|
||||||
if(card.candidate) {
|
if(candidate) {
|
||||||
var withCard = selected.name;
|
var withCard = selected.name;
|
||||||
selected.setSelected(false);
|
selected.setSelected(false);
|
||||||
play(
|
play(
|
||||||
|
@ -15,13 +17,18 @@ RiverCard.prototype.onClick = function() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
|
|
||||||
RiverCard.prototype.setCandidate = function(yes) {
|
function setCandidate() {
|
||||||
this.candidate = yes;
|
candidate = yes;
|
||||||
this.dom.classList.toggle("candidate", yes);
|
card.dom.classList.toggle("candidate", yes);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
RiverCard.prototype.onClick = function() {
|
||||||
RiverCard: RiverCard
|
var card = this;
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
make: RiverCard
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,5 +10,5 @@ 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