|
|
|
@ -1,8 +1,11 @@ |
|
|
|
import React, { Component, useState } from 'react' |
|
|
|
import React, { Component, useState } from 'react' |
|
|
|
import { View, Text, Image, Input, Button } from '@tarojs/components' |
|
|
|
import { View, Text, Image, Input, Button } from '@tarojs/components' |
|
|
|
import { useSelector } from 'react-redux' |
|
|
|
import { connect } from 'react-redux' |
|
|
|
import cnames from 'classnames' |
|
|
|
import cnames from 'classnames' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import { reqGameFullStatus } from '@/api/wsapi' |
|
|
|
|
|
|
|
import { ifEmpty } from '@/utils/validator' |
|
|
|
|
|
|
|
|
|
|
|
import './table.scss' |
|
|
|
import './table.scss' |
|
|
|
import Title from '@/components/title' |
|
|
|
import Title from '@/components/title' |
|
|
|
import Card from '@/components/card' |
|
|
|
import Card from '@/components/card' |
|
|
|
@ -11,6 +14,7 @@ import coin2Icon from '@/assets/icon/coin-2.svg' |
|
|
|
import plus1Icon from '@/assets/icon/plus-1.svg' |
|
|
|
import plus1Icon from '@/assets/icon/plus-1.svg' |
|
|
|
import sub1Icon from '@/assets/icon/sub-1.svg' |
|
|
|
import sub1Icon from '@/assets/icon/sub-1.svg' |
|
|
|
import Taro from '@tarojs/taro' |
|
|
|
import Taro from '@tarojs/taro' |
|
|
|
|
|
|
|
import { showToast } from '@/utils/application' |
|
|
|
|
|
|
|
|
|
|
|
function PlayerStatus() { |
|
|
|
function PlayerStatus() { |
|
|
|
return ( |
|
|
|
return ( |
|
|
|
@ -20,17 +24,63 @@ function PlayerStatus() { |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function Table() { |
|
|
|
function cardDot(card, cardBackCode) { |
|
|
|
|
|
|
|
if (!card || !card.suit) { |
|
|
|
|
|
|
|
return cardBackCode; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return card['dot']; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const { username, nickname, avatar } = useSelector(state => state.user); |
|
|
|
function cardSuit(card) { |
|
|
|
|
|
|
|
return card.suit || 'D'; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const players = [1, 2, 3, 4, 5, 6]; |
|
|
|
class Table extends Component { |
|
|
|
const playerRows = players.reduce((arr, item, idx) => { |
|
|
|
constructor(props) { |
|
|
|
|
|
|
|
super(props) |
|
|
|
|
|
|
|
this.state = { |
|
|
|
|
|
|
|
inGame: false, |
|
|
|
|
|
|
|
tableNo: 0, |
|
|
|
|
|
|
|
stage: 0, // 游戏阶段: 1等待玩家准备;2下大盲注;3下小盲注;4发公共牌;5发第四张公共牌,轮流下注;6发第五张公共牌,轮流下注,7比牌结算 |
|
|
|
|
|
|
|
chip: 0, |
|
|
|
|
|
|
|
RoundTimes: 0, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
players: [], |
|
|
|
|
|
|
|
publicCard: [], |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
componentDidMount() { |
|
|
|
|
|
|
|
console.log('table mount') |
|
|
|
|
|
|
|
setTimeout(() => { |
|
|
|
|
|
|
|
reqGameFullStatus() |
|
|
|
|
|
|
|
.then(res => { |
|
|
|
|
|
|
|
this.setState({ |
|
|
|
|
|
|
|
inGame: !!res.inGame, |
|
|
|
|
|
|
|
tableNo: res.tableNo, |
|
|
|
|
|
|
|
stage: res.gameStage, |
|
|
|
|
|
|
|
chip: res.chip || 0, |
|
|
|
|
|
|
|
RoundTimes: res.RoundTimes || 0, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
players: res.players, |
|
|
|
|
|
|
|
publicCard: res.publicCard, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
console.log('res game', res, res.publicCard[0].dot, ifEmpty(res.publicCard[0].dot, -3)) |
|
|
|
|
|
|
|
window.publicCard = res.publicCard |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
.catch(err => { |
|
|
|
|
|
|
|
showToast({title: err}) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
}, 2000) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
render() { |
|
|
|
|
|
|
|
const { username, nickname, avatar } = this.props.user; // useSelector(state => state.user); |
|
|
|
|
|
|
|
// const players = [1, 2, 3, 4, 5, 6]; |
|
|
|
|
|
|
|
const playerRows = this.state.players.reduce((arr, player, idx) => { |
|
|
|
const row = parseInt(idx / 2); |
|
|
|
const row = parseInt(idx / 2); |
|
|
|
let rowArr = arr[row] || []; |
|
|
|
let rowArr = arr[row] || []; |
|
|
|
rowArr[idx % 2] = { index: idx, item }; |
|
|
|
rowArr[idx % 2] = { index: idx, player }; |
|
|
|
arr[row] = rowArr; |
|
|
|
arr[row] = rowArr; |
|
|
|
parseInt() |
|
|
|
|
|
|
|
return arr; |
|
|
|
return arr; |
|
|
|
}, []); |
|
|
|
}, []); |
|
|
|
|
|
|
|
|
|
|
|
@ -75,8 +125,8 @@ function Table() { |
|
|
|
<View className="desktop-wrap"> |
|
|
|
<View className="desktop-wrap"> |
|
|
|
<View className="desktop-cards"> |
|
|
|
<View className="desktop-cards"> |
|
|
|
{ |
|
|
|
{ |
|
|
|
[1, 2, 3, -3, -3].map((item, i) => ( |
|
|
|
this.state.publicCard.map((card, i) => ( |
|
|
|
<Card key={i} w={38} h={48} dot={item} suit={2} /> |
|
|
|
<Card key={i} w={38} h={48} dot={cardDot(card, -3)} suit={cardSuit(card)} /> |
|
|
|
)) |
|
|
|
)) |
|
|
|
} |
|
|
|
} |
|
|
|
</View> |
|
|
|
</View> |
|
|
|
@ -144,5 +194,10 @@ function Table() { |
|
|
|
</View> |
|
|
|
</View> |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function mapStateToProps(state) { |
|
|
|
|
|
|
|
return {user: state.user} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export default Table |
|
|
|
export default connect(mapStateToProps)(Table) |
|
|
|
|