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;
|
||||
|
||||
function Card(name) {
|
||||
this.value = Hanafuda.Card[name];
|
||||
this.name = name;
|
||||
this.dom = Dom.make('li', {
|
||||
var value = Hanafuda.Card[name];
|
||||
var dom = Dom.make('li', {
|
||||
class: [
|
||||
"card",
|
||||
"value" + Hanafuda.getValue(this.value),
|
||||
"month" + this.value.flower
|
||||
],
|
||||
onClick: this.onClick()
|
||||
]
|
||||
});
|
||||
return {
|
||||
value: value,
|
||||
dom: dom
|
||||
};
|
||||
}
|
||||
|
||||
Card.prototype.onClick = function() {return function() {};};
|
||||
|
||||
return {
|
||||
Card: Card
|
||||
make: Card
|
||||
};
|
||||
|
|
|
@ -1,13 +1,15 @@
|
|||
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;
|
||||
|
||||
RiverCard.prototype.onClick = function() {
|
||||
var card = this;
|
||||
function onClick() {
|
||||
return function() {
|
||||
if(card.candidate) {
|
||||
if(candidate) {
|
||||
var withCard = selected.name;
|
||||
selected.setSelected(false);
|
||||
play(
|
||||
|
@ -15,13 +17,18 @@ RiverCard.prototype.onClick = function() {
|
|||
);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
RiverCard.prototype.setCandidate = function(yes) {
|
||||
this.candidate = yes;
|
||||
this.dom.classList.toggle("candidate", yes);
|
||||
}
|
||||
|
||||
return {
|
||||
RiverCard: RiverCard
|
||||
function setCandidate() {
|
||||
candidate = yes;
|
||||
card.dom.classList.toggle("candidate", yes);
|
||||
}
|
||||
}
|
||||
|
||||
RiverCard.prototype.onClick = function() {
|
||||
var card = this;
|
||||
};
|
||||
|
||||
return {
|
||||
make: RiverCard
|
||||
};
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
import * as Card from GUI.Card;
|
||||
|
||||
function TurnedCard() {
|
||||
Card.apply(this, arguments);
|
||||
this.dom.id = "turned";
|
||||
function TurnedCard(name) {
|
||||
var card = Card.make(name);
|
||||
card.dom.id = "turned";
|
||||
deck.appendChild(this.dom);
|
||||
}
|
||||
|
||||
|
@ -9,5 +10,5 @@ TurnedCard.prototype.onClick = Card.prototype.onClick;
|
|||
TurnedCard.prototype.setSelected = setSelected;
|
||||
|
||||
return {
|
||||
TurnedCard: TurnedCard
|
||||
make: TurnedCard
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue