-
-
- {cards.split(" ").map(card=>{
- return this.translateCardData(card);
- })}
-
+
+
+ {cards.map(card=>{
+ return this.translateCardData(card);
+ })}
+
+
+ )
+ }
+
+ computeSideHand(cards) {
+ let upCards = [];
+ let downCards = [];
+ if(cards.length > 10){
+ upCards = cards.slice(0, 10);
+ downCards = cards.slice(10, );
+ }else{
+ upCards = cards;
+ }
+ return (
+
+
+
+
+ {upCards.map(element => {return this.translateCardData(element)})}
+
+
+
+
+
+
+ {downCards.map(element => {return this.translateCardData(element)})}
+
+
)
@@ -88,794 +119,35 @@ class DoudizhuGameBoard extends React.Component {
- {`Player Id ${leftId}`}
-
-
-
-
+
{`Player Id ${leftId}\n${this.props.playerInfo.length > 0 ? this.props.playerInfo[leftIdx].role : ""}`}
+ {leftIdx >= 0 ? this.computeSideHand(this.props.hand[leftIdx]) :
Waiting...
}
-
+ {leftIdx >= 0 ? this.computeSingleLineHand(this.props.latestAction[leftIdx]) : ""}
- {`Player Id ${rightId}`}
-
-
-
-
+
{`Player Id ${rightId}\n${this.props.playerInfo.length > 0 ? this.props.playerInfo[rightIdx].role : ""}`}
+ {rightIdx >= 0 ? this.computeSideHand(this.props.hand[rightIdx]) :
Waiting...
}
-
+ {rightIdx >= 0 ? this.computeSingleLineHand(this.props.latestAction[rightIdx]) : ""}
-
+ {bottomIdx >= 0 ? this.computeSingleLineHand(this.props.latestAction[bottomIdx]) : ""}
- {`Player Id ${bottomId}`}
-
-
-
+
{`Player Id ${bottomId}\n${this.props.playerInfo.length > 0 ? this.props.playerInfo[bottomIdx].role : ""}`}
+ {bottomIdx >= 0 ?
{this.computeSingleLineHand(this.props.hand[bottomIdx])}
:
Waiting...
}
-
);
diff --git a/src/components/GameBoard/index.scss b/src/components/GameBoard/index.scss
index 4c1c20a..1484e52 100644
--- a/src/components/GameBoard/index.scss
+++ b/src/components/GameBoard/index.scss
@@ -4,19 +4,30 @@
font-size: 12px;
}
+.player-hand-placeholder {
+ font-size: 16px;
+ display: table;
+
+ span {
+ display: table-cell;
+ vertical-align: middle;
+ text-align: center;
+ }
+}
+
.player-info {
- text-align: center;
- line-height: 130px;
+
+ //line-height: 130px;
font-size: 16px;
width: 130px;
height: 130px;
background-color: green;
+ display: table;
span {
+ display: table-cell;
vertical-align: middle;
- white-space: nowrap;
- overflow: hidden;
- text-overflow: ellipsis;
+ text-align: center;
}
}
@@ -36,7 +47,7 @@
.player-hand-up {
position: absolute;
- top: 0px;
+ top: 0;
margin-left: 130px;
width: 150px;
}
@@ -47,6 +58,14 @@
margin-left: 130px;
width: 150px;
}
+
+ .player-hand-placeholder {
+ width: 150px;
+ height: 130px;
+ position: absolute;
+ top: 0;
+ margin-left: 130px;
+ }
}
.played-card-area {
@@ -72,7 +91,7 @@
.player-hand-up {
position: absolute;
- top: 0px;
+ top: 0;
margin-right: 130px;
width: 150px;
}
@@ -83,6 +102,14 @@
margin-right: 130px;
width: 150px;
}
+
+ .player-hand-placeholder {
+ width: 150px;
+ height: 130px;
+ position: absolute;
+ top: 0;
+ margin-right: 130px;
+ }
}
.played-card-area {
@@ -105,15 +132,29 @@
.player-hand {
position: absolute;
- top: 0px;
+ top: 0;
+ padding-left: 20px;
margin-left: 130px;
width: 450px;
}
+
+ .player-hand-placeholder {
+ width: 150px;
+ height: 130px;
+ position: absolute;
+ top: 0;
+ padding-left: 20px;
+ margin-left: 130px;
+ }
}
.played-card-area {
position: relative;
transform: translateY(30px);
+ width: 280px;
+ margin-left: auto;
+ margin-right: auto;
+ text-align: center;
}
}
diff --git a/src/view/DoudizhuGameView.js b/src/view/DoudizhuGameView.js
index ad73e09..09760e4 100644
--- a/src/view/DoudizhuGameView.js
+++ b/src/view/DoudizhuGameView.js
@@ -13,7 +13,7 @@ class DoudizhuGameView extends React.Component {
gameInfo: {
playerInfo: [],
hand: [],
- latestAction: [],
+ latestAction: [[], [], []],
mainViewerId: mainViewerId
}
};
@@ -31,14 +31,16 @@ class DoudizhuGameView extends React.Component {
connectWebSocket() {
let ws = webSocket("http://localhost:10080");
ws.on("getMessage", message => {
- console.log(message);
+ // console.log(message);
if(message){
switch(message.type){
case 0:
// init replay info
let gameInfo = JSON.parse(JSON.stringify(this.state.gameInfo));
gameInfo.playerInfo = message.message.playerInfo;
- gameInfo.hand = message.message.initHand;
+ gameInfo.hand = message.message.initHand.map(element => {
+ return element.split(" ");
+ });
this.setState({gameInfo: gameInfo});
break;
}