|
|
|
@ -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,129 +24,180 @@ 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) { |
|
|
|
const row = parseInt(idx / 2); |
|
|
|
super(props) |
|
|
|
let rowArr = arr[row] || []; |
|
|
|
this.state = { |
|
|
|
rowArr[idx % 2] = { index: idx, item }; |
|
|
|
inGame: false, |
|
|
|
arr[row] = rowArr; |
|
|
|
tableNo: 0, |
|
|
|
parseInt() |
|
|
|
stage: 0, // 游戏阶段: 1等待玩家准备;2下大盲注;3下小盲注;4发公共牌;5发第四张公共牌,轮流下注;6发第五张公共牌,轮流下注,7比牌结算 |
|
|
|
return arr; |
|
|
|
chip: 0, |
|
|
|
}, []); |
|
|
|
RoundTimes: 0, |
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
players: [], |
|
|
|
<View className="tab"> |
|
|
|
publicCard: [], |
|
|
|
<Title title="GAME" /> |
|
|
|
} |
|
|
|
{ |
|
|
|
} |
|
|
|
playerRows.map((row, i) => ( |
|
|
|
componentDidMount() { |
|
|
|
<View key={i} className="playerRow"> |
|
|
|
console.log('table mount') |
|
|
|
{ |
|
|
|
setTimeout(() => { |
|
|
|
row.map((player, j) => ( |
|
|
|
reqGameFullStatus() |
|
|
|
<View key={j} className="player-wrap"> |
|
|
|
.then(res => { |
|
|
|
{ |
|
|
|
this.setState({ |
|
|
|
j % 2 === 0 && |
|
|
|
inGame: !!res.inGame, |
|
|
|
<View className={cnames('player-state-wrap', {'state-left': j % 2 === 0})}> |
|
|
|
tableNo: res.tableNo, |
|
|
|
<PlayerStatus action={1} /> |
|
|
|
stage: res.gameStage, |
|
|
|
</View> |
|
|
|
chip: res.chip || 0, |
|
|
|
} |
|
|
|
RoundTimes: res.RoundTimes || 0, |
|
|
|
<View className="player-bar"> |
|
|
|
|
|
|
|
<View className={cnames("player-no", { "player-no-running": player.index === 0 })}><Text>#{player.index}</Text></View> |
|
|
|
players: res.players, |
|
|
|
<View className="card1"><Card w={38} h={48} dot={-1} suit={2} /></View> |
|
|
|
publicCard: res.publicCard, |
|
|
|
<View className="card2"><Card w={38} h={48} dot={-1} suit={3} /></View> |
|
|
|
}) |
|
|
|
<View className={cnames("player", {'player-wait': player.index !== 0})}> |
|
|
|
console.log('res game', res, res.publicCard[0].dot, ifEmpty(res.publicCard[0].dot, -3)) |
|
|
|
<View className="avatar-wrap"><Image className="avatar" src={avatar} /></View> |
|
|
|
window.publicCard = res.publicCard |
|
|
|
<View className="player-name"><Text>Player{player.item}</Text></View> |
|
|
|
}) |
|
|
|
</View> |
|
|
|
.catch(err => { |
|
|
|
<View className="wallet-wrap"> |
|
|
|
showToast({title: err}) |
|
|
|
<View className={cnames("wallet", {'wallet-wait': player.index !== 0})}> |
|
|
|
}) |
|
|
|
<View className="wallet-icon"><Image className="wallet-icon-img" src={coinIcon} /></View> |
|
|
|
}, 2000) |
|
|
|
<View className="wallet-amount"><Text>3,000,000</Text></View> |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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); |
|
|
|
|
|
|
|
let rowArr = arr[row] || []; |
|
|
|
|
|
|
|
rowArr[idx % 2] = { index: idx, player }; |
|
|
|
|
|
|
|
arr[row] = rowArr; |
|
|
|
|
|
|
|
return arr; |
|
|
|
|
|
|
|
}, []); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
|
|
|
<View className="tab"> |
|
|
|
|
|
|
|
<Title title="GAME" /> |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
playerRows.map((row, i) => ( |
|
|
|
|
|
|
|
<View key={i} className="playerRow"> |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
row.map((player, j) => ( |
|
|
|
|
|
|
|
<View key={j} className="player-wrap"> |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
j % 2 === 0 && |
|
|
|
|
|
|
|
<View className={cnames('player-state-wrap', {'state-left': j % 2 === 0})}> |
|
|
|
|
|
|
|
<PlayerStatus action={1} /> |
|
|
|
|
|
|
|
</View> |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
<View className="player-bar"> |
|
|
|
|
|
|
|
<View className={cnames("player-no", { "player-no-running": player.index === 0 })}><Text>#{player.index}</Text></View> |
|
|
|
|
|
|
|
<View className="card1"><Card w={38} h={48} dot={-1} suit={2} /></View> |
|
|
|
|
|
|
|
<View className="card2"><Card w={38} h={48} dot={-1} suit={3} /></View> |
|
|
|
|
|
|
|
<View className={cnames("player", {'player-wait': player.index !== 0})}> |
|
|
|
|
|
|
|
<View className="avatar-wrap"><Image className="avatar" src={avatar} /></View> |
|
|
|
|
|
|
|
<View className="player-name"><Text>Player{player.item}</Text></View> |
|
|
|
|
|
|
|
</View> |
|
|
|
|
|
|
|
<View className="wallet-wrap"> |
|
|
|
|
|
|
|
<View className={cnames("wallet", {'wallet-wait': player.index !== 0})}> |
|
|
|
|
|
|
|
<View className="wallet-icon"><Image className="wallet-icon-img" src={coinIcon} /></View> |
|
|
|
|
|
|
|
<View className="wallet-amount"><Text>3,000,000</Text></View> |
|
|
|
|
|
|
|
</View> |
|
|
|
|
|
|
|
<View className="pct"><Text>25%</Text></View> |
|
|
|
</View> |
|
|
|
</View> |
|
|
|
<View className="pct"><Text>25%</Text></View> |
|
|
|
|
|
|
|
</View> |
|
|
|
</View> |
|
|
|
</View> |
|
|
|
</View> |
|
|
|
</View> |
|
|
|
)) |
|
|
|
)) |
|
|
|
} |
|
|
|
} |
|
|
|
</View> |
|
|
|
</View> |
|
|
|
)) |
|
|
|
)) |
|
|
|
} |
|
|
|
} |
|
|
|
<View className="desktop-box"> |
|
|
|
<View className="desktop-box"> |
|
|
|
<View className="desktop-wrap"> |
|
|
|
<View className="desktop-wrap"> |
|
|
|
<View className="desktop-cards"> |
|
|
|
<View className="desktop-cards"> |
|
|
|
{ |
|
|
|
{ |
|
|
|
this.state.publicCard.map((card, i) => ( |
|
|
|
[1, 2, 3, -3, -3].map((item, i) => ( |
|
|
|
<Card key={i} w={38} h={48} dot={cardDot(card, -3)} suit={cardSuit(card)} /> |
|
|
|
<Card key={i} w={38} h={48} dot={item} suit={2} /> |
|
|
|
)) |
|
|
|
)) |
|
|
|
} |
|
|
|
} |
|
|
|
</View> |
|
|
|
</View> |
|
|
|
<View className="desktop-wallet"> |
|
|
|
<View className="desktop-wallet"> |
|
|
|
<View className="d-wallet-icon"> |
|
|
|
<View className="d-wallet-icon"> |
|
|
|
<Image className="d-wallet-icon-img" src={coinIcon} /> |
|
|
|
<Image className="d-wallet-icon-img" src={coinIcon} /> |
|
|
|
<Text className="d-wallet-icon-text">POT</Text> |
|
|
|
<Text className="d-wallet-icon-text">POT</Text> |
|
|
|
</View> |
|
|
|
|
|
|
|
<View className="d-wallet-amount">22,088,000</View> |
|
|
|
</View> |
|
|
|
</View> |
|
|
|
<View className="d-wallet-amount">22,088,000</View> |
|
|
|
|
|
|
|
</View> |
|
|
|
</View> |
|
|
|
|
|
|
|
{/* <View className="chatbox" style={{ display: 'none' }}> |
|
|
|
|
|
|
|
<View className='chat-window'> |
|
|
|
|
|
|
|
<View className="line">Kelly(#1)进入了游戏</View> |
|
|
|
|
|
|
|
<View className="line">Apollo(#2)进入了游戏</View> |
|
|
|
|
|
|
|
</View> |
|
|
|
|
|
|
|
<View className='chat-panel'> |
|
|
|
|
|
|
|
<View><Input name="chat" type="text" placeholder="" /></View> |
|
|
|
|
|
|
|
<View><Button>OK</Button></View> |
|
|
|
|
|
|
|
</View> |
|
|
|
|
|
|
|
</View> */} |
|
|
|
</View> |
|
|
|
</View> |
|
|
|
{/* <View className="chatbox" style={{ display: 'none' }}> |
|
|
|
|
|
|
|
<View className='chat-window'> |
|
|
|
|
|
|
|
<View className="line">Kelly(#1)进入了游戏</View> |
|
|
|
|
|
|
|
<View className="line">Apollo(#2)进入了游戏</View> |
|
|
|
|
|
|
|
</View> |
|
|
|
|
|
|
|
<View className='chat-panel'> |
|
|
|
|
|
|
|
<View><Input name="chat" type="text" placeholder="" /></View> |
|
|
|
|
|
|
|
<View><Button>OK</Button></View> |
|
|
|
|
|
|
|
</View> |
|
|
|
|
|
|
|
</View> */} |
|
|
|
|
|
|
|
</View> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<View className="self-box"> |
|
|
|
<View className="self-box"> |
|
|
|
<View className="self-wrap"> |
|
|
|
<View className="self-wrap"> |
|
|
|
<View className={cnames("player-no", { "player-no-running": true })}><Text>#7</Text></View> |
|
|
|
<View className={cnames("player-no", { "player-no-running": true })}><Text>#7</Text></View> |
|
|
|
<View className="hand-card1"><Card w={38} h={48} dot={12} suit={3} /></View> |
|
|
|
<View className="hand-card1"><Card w={38} h={48} dot={12} suit={3} /></View> |
|
|
|
<View className="hand-card2"><Card w={38} h={48} dot={12} suit={3} /></View> |
|
|
|
<View className="hand-card2"><Card w={38} h={48} dot={12} suit={3} /></View> |
|
|
|
<View className="hand-five"> |
|
|
|
<View className="hand-five"> |
|
|
|
{ |
|
|
|
{ |
|
|
|
[1, 2, 3, 4, 5].map((_, i) => ( |
|
|
|
[1, 2, 3, 4, 5].map((_, i) => ( |
|
|
|
<View key={i} className="hand-five-item"><Card w={28} h={36} dot={12} suit={2} /></View> |
|
|
|
<View key={i} className="hand-five-item"><Card w={28} h={36} dot={12} suit={2} /></View> |
|
|
|
)) |
|
|
|
)) |
|
|
|
} |
|
|
|
} |
|
|
|
</View> |
|
|
|
|
|
|
|
<View className='u-opt' style={{ display: 'flex' }}> |
|
|
|
|
|
|
|
<View> |
|
|
|
|
|
|
|
<View className="s-info-wrap"> |
|
|
|
|
|
|
|
<View className="s-avatar"><Image className="s-avatar-img" src={avatar} /></View> |
|
|
|
|
|
|
|
<View className="s-username"><Text>Prometheus</Text></View> |
|
|
|
|
|
|
|
</View> |
|
|
|
|
|
|
|
<View className="s-wallet-wrap"> |
|
|
|
|
|
|
|
<View className="s-w-amount-wrap"> |
|
|
|
|
|
|
|
<View className="s-w-amount-icon"><Image className="s-w-amount-icon-img" src={coin2Icon} /></View> |
|
|
|
|
|
|
|
<View className="s-w-amount"><Text>3,000,000</Text></View> |
|
|
|
|
|
|
|
</View> |
|
|
|
|
|
|
|
<View className="s-w-pct"><Text>0%</Text></View> |
|
|
|
|
|
|
|
</View> |
|
|
|
|
|
|
|
</View> |
|
|
|
</View> |
|
|
|
<View className="control"> |
|
|
|
<View className='u-opt' style={{ display: 'flex' }}> |
|
|
|
<View className="ctl-opt-wrap"> |
|
|
|
<View> |
|
|
|
<View className="amount-input"><Input placeholder='your chip' defaultValue={0} /></View> |
|
|
|
<View className="s-info-wrap"> |
|
|
|
<View className="amount-sub"><Image className="amount-sub-icon" src={sub1Icon} /></View> |
|
|
|
<View className="s-avatar"><Image className="s-avatar-img" src={avatar} /></View> |
|
|
|
<View className="amount-plus"><Image className="amount-plus-icon" src={plus1Icon} /></View> |
|
|
|
<View className="s-username"><Text>Prometheus</Text></View> |
|
|
|
|
|
|
|
</View> |
|
|
|
|
|
|
|
<View className="s-wallet-wrap"> |
|
|
|
|
|
|
|
<View className="s-w-amount-wrap"> |
|
|
|
|
|
|
|
<View className="s-w-amount-icon"><Image className="s-w-amount-icon-img" src={coin2Icon} /></View> |
|
|
|
|
|
|
|
<View className="s-w-amount"><Text>3,000,000</Text></View> |
|
|
|
|
|
|
|
</View> |
|
|
|
|
|
|
|
<View className="s-w-pct"><Text>0%</Text></View> |
|
|
|
|
|
|
|
</View> |
|
|
|
</View> |
|
|
|
</View> |
|
|
|
<View className="ctl-opt-wrap" style={{ marginTop: Taro.pxTransform(10) }}> |
|
|
|
<View className="control"> |
|
|
|
<View className="ctl-opt"><Button className="ctl-opt-btn-1">让牌</Button></View> |
|
|
|
<View className="ctl-opt-wrap"> |
|
|
|
<View className="ctl-opt"><Button className="ctl-opt-btn-2">弃牌</Button></View> |
|
|
|
<View className="amount-input"><Input placeholder='your chip' defaultValue={0} /></View> |
|
|
|
<View className="ctl-opt"><Button className="ctl-opt-btn-3">跟注</Button></View> |
|
|
|
<View className="amount-sub"><Image className="amount-sub-icon" src={sub1Icon} /></View> |
|
|
|
|
|
|
|
<View className="amount-plus"><Image className="amount-plus-icon" src={plus1Icon} /></View> |
|
|
|
|
|
|
|
</View> |
|
|
|
|
|
|
|
<View className="ctl-opt-wrap" style={{ marginTop: Taro.pxTransform(10) }}> |
|
|
|
|
|
|
|
<View className="ctl-opt"><Button className="ctl-opt-btn-1">让牌</Button></View> |
|
|
|
|
|
|
|
<View className="ctl-opt"><Button className="ctl-opt-btn-2">弃牌</Button></View> |
|
|
|
|
|
|
|
<View className="ctl-opt"><Button className="ctl-opt-btn-3">跟注</Button></View> |
|
|
|
|
|
|
|
</View> |
|
|
|
</View> |
|
|
|
</View> |
|
|
|
</View> |
|
|
|
</View> |
|
|
|
</View> |
|
|
|
</View> |
|
|
|
</View> |
|
|
|
</View> |
|
|
|
</View> |
|
|
|
</View> |
|
|
|
</View> |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function mapStateToProps(state) { |
|
|
|
|
|
|
|
return {user: state.user} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export default Table |
|
|
|
export default connect(mapStateToProps)(Table) |
|
|
|
|