compute bottom player's hand

This commit is contained in:
Songyi Huang 2020-01-13 19:05:47 -08:00
parent 3d3647ecb2
commit 4fd21acc48
1 changed files with 117 additions and 65 deletions

View File

@ -3,9 +3,61 @@ import React from 'react';
import './index.scss'; import './index.scss';
class DoudizhuGameBoard extends React.Component { class DoudizhuGameBoard extends React.Component {
constructor(props) {
super(props);
computeMainViewerHand() { this.suitMap = new Map(
[["H", "hearts"], ["D", "diams"], ["S", "spades"], ["C", "clubs"]]
);
}
translateCardData(card) {
let rankClass = "";
let suitClass = "";
let rankText = "";
let suitText = "";
// translate rank
if(card === "RJ"){
rankClass = "big";
rankText = "+";
suitClass = "joker";
suitText = "Joker";
}else if(card === "BJ"){
rankClass = "little";
rankText = "-";
suitClass = "joker";
suitText = "Joker";
}else{
rankClass = card.charAt(0) === "T" ? `10` : card.charAt(0).toLowerCase();
rankText = card.charAt(0) === "T" ? `10` : card.charAt(0);
}
// translate suitClass
if(card !== "RJ" && card !== "BJ"){
suitClass = this.suitMap.get(card.charAt(1));
suitText = `&${this.suitMap.get(card.charAt(1))};`;
}
return (
<li>
<a className={`card rank-${rankClass} ${suitClass}`} href="/#">
<span className="rank">{rankText}</span>
<span className="suit">{suitText}</span>
</a>
</li>
)
}
computeBottomHand(cards) {
return (
<div className="played-card-area">
<div className="playingCards">
<ul className="hand">
{cards.split(" ").map(card=>{
return this.translateCardData(card);
})}
</ul>
</div>
</div>
)
} }
render() { render() {