|
@@ -1,28 +1,34 @@
|
|
|
-import { useState } from 'react'
|
|
|
+import { useContext, useEffect, useState } from 'react'
|
|
|
import './Checkerboard.css'
|
|
|
+import { POINT } from '../Constant';
|
|
|
import tableData from './CheckerboardData'
|
|
|
import Navigation from '../component/Navigation'
|
|
|
+import RevRoomContext from '../provider/RevRoomContext';
|
|
|
+import GlobalSocketContext from '../provider/GlobalSocketContext';
|
|
|
const bgline = [
|
|
|
["x", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n"],
|
|
|
["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14"]
|
|
|
];
|
|
|
const constant = {a:1, b:2, c:3, d:4, e:5, f:6, g:7, h:8, i:9, j:10, k:11, l:12, m:13, n:14}
|
|
|
const Checkerboard = function () {
|
|
|
+ const { room, data } = useContext(RevRoomContext)
|
|
|
+ const socket = useContext(GlobalSocketContext)
|
|
|
const [table, updateTable] = useState(tableData)
|
|
|
const [userStatus, setGameStatus] = useState(0)
|
|
|
+ useEffect(()=>{
|
|
|
+ updateTable(data)
|
|
|
+ }, [data])
|
|
|
const goBangTouchEvent = function (x, y, value) {
|
|
|
- if ( userStatus === 0 ) {
|
|
|
+ if ( room.status === 0 ) {
|
|
|
console.log( "棋盘未开始呢!!" )
|
|
|
return
|
|
|
}
|
|
|
if (value === 0) {
|
|
|
- table[x][y] = userStatus
|
|
|
- updateTable({ ...table })
|
|
|
- switch (userStatus) {
|
|
|
- case 1: setGameStatus(2); break;
|
|
|
- case 2: setGameStatus(1); break;
|
|
|
- default: setGameStatus(0)
|
|
|
- }
|
|
|
+ data[x][y] = room.status
|
|
|
+ socket.send(JSON.stringify({
|
|
|
+ instruct: POINT,
|
|
|
+ data:data
|
|
|
+ }))
|
|
|
if ( userStatus !== 0 ) {
|
|
|
win(x, y, table)
|
|
|
}
|