diff --git a/src/components/game/Lobby.js b/src/components/game/Lobby.js index 73ad546..c7aaa02 100644 --- a/src/components/game/Lobby.js +++ b/src/components/game/Lobby.js @@ -139,11 +139,11 @@ const Lobby = () => { })); } - window.addEventListener('beforeunload', (event) => { - leaveUser(); - event.preventDefault(); - event.returnValue = ''; - }); + // window.addEventListener('beforeunload', (event) => { + // leaveUser(); + // event.preventDefault(); + // event.returnValue = ''; + // }); }); return () => { diff --git a/src/components/game/YutPan.jsx b/src/components/game/YutPan.jsx index 86c31a9..b833465 100644 --- a/src/components/game/YutPan.jsx +++ b/src/components/game/YutPan.jsx @@ -46,6 +46,8 @@ function YutPan() { const [lastStep, setLastStep] = useState(false); const [loading, setLoading] = useState("flex"); + const [stepEvent, setStepEvent] = useState(true); + const [showRoulette, setShowRoulette] = useState(false); useEffect(() => { @@ -385,6 +387,7 @@ function YutPan() { setMyTurn(false); if (myPlayer == ("player" + (index + 1))) { setMyTurn(true); + setStepEvent(true); } } if (player.SessionId === undefined || player.SessionId === "") { @@ -411,8 +414,23 @@ function YutPan() { let commend = message.message; if (commend === "oneMore") { setTimeout(() => oneMore(), 2000) - } else if (commend === "mini-game-step") { + } else if (commend === "mini-game-step-open") { setShowRoulette(true); + } else if (commend === "mini-game-step-close") { + setShowRoulette(false); + } + } else if (message.type === "passTurn") { + let player = message.message; + if (myPlayer === player) { + setTimeout(() => { + setMyTurn(false); + setLastStep(false); + stompClient.send( + `/app/main/passTurn/${roomId}`, + {name: myPlayer}, // 헤더 설정 + JSON.stringify({message: "pass"}) + ); + }, 0) } } else if (message.type === "resultArr") { setTimeout(() => setResultArr(JSON.parse(message.message)), 0) @@ -439,13 +457,19 @@ function YutPan() { JSON.stringify({message: "join"}) ); } - } - else { + } else { console.log("error : " + JSON.parse(message.message).toString()); } }); + stompClient.subscribe(`/topic/mini-game/${roomId}`, (msg) => { + const message = JSON.parse(msg.body) + if (message.type === "result") { + let getPlayers = JSON.parse(message.message); + } + }); + stompClient.send( `/app/main/join/${roomId}`, @@ -460,8 +484,9 @@ function YutPan() { }, [myPlayer]); useEffect(() => { - if (resultArr.length === 0 && !yutThrowAble && myTurn && lastStep) { + if (resultArr.length === 0 && !yutThrowAble && myTurn && lastStep && stepEvent) { stepOnEvent(parseInt(players[myPlayer].index, 10)) + setStepEvent(false); } }, [resultArr]); @@ -599,6 +624,7 @@ function YutPan() { //기본 땅 밟을 시 이벤트 const defaultStateEvent = (index) => { + console.log("default state event"); const ele = yutIndexRefs.current.find(s => s.classList[0] === "YutState" + index); if (ele?.classList[2] === undefined) { @@ -622,14 +648,17 @@ function YutPan() { //땅 주인이 내가 아니면 } else { //통행료 내기 - // console.log((players[myPlayer].money - yutStates.find(states => states.YutIndex === parseInt(index)).price * 1.5)); - // updatePlayer(myPlayer, {money: (players[myPlayer].money - yutStates.find(states => states.YutIndex === parseInt(index)).price * 1.5)}); - // updatePlayer(owner, {money: (players[owner].money + yutStates.find(states => states.YutIndex === parseInt(index)).price * 1.5)}); - // client.send( - // `/app/main/arrowClick/${roomId}`, - // {name: myPlayer, location: index}, // 헤더 설정 - // JSON.stringify({message: "move this"}) - // ); + const statePrice = yutStates.find(states => states.YutIndex === parseInt(index)).price; + client.send( + `/app/main/pay-toll/${roomId}`, + { + name: myPlayer, + location: index, + price: statePrice, + owner: owner + }, // 헤더 설정 + JSON.stringify({message: "pay toll"}) + ); passTurn(); } @@ -797,7 +826,7 @@ function YutPan() { {/*
한번더
*/} - {/*
pass turn
*/} +
pass turn
{Object.keys(players).map((key, index) => { diff --git a/src/components/game/YutStates.js b/src/components/game/YutStates.js index 7a44918..28e22b2 100644 --- a/src/components/game/YutStates.js +++ b/src/components/game/YutStates.js @@ -5,19 +5,19 @@ export const yutStates = [ {name: "미니게임", left: 208.52, top: 417.05, border: '20px #FFE263 solid', YutIndex: 3}, {name: "전주", left: 154.55, top: 409.94, border: '20px #eeeeee solid', YutIndex: 4, price : 40}, {name: "익산", left: 104.26, top: 389.11, border: '20px #eeeeee solid', YutIndex: 5, price : 50}, - {name: "뭐하지", left: 61.41, top: 356.31, border: '20px #A5A5A5 solid', YutIndex: 6}, + {name: "갈림길", left: 61.41, top: 356.31, border: '20px #A5A5A5 solid', YutIndex: 6}, {name: "울산", left: 27.94, top: 312.78, border: '20px #eeeeee solid', YutIndex: 7, price : 70}, {name: "부산", left: 7.10, top: 262.49, border: '20px #eeeeee solid', YutIndex: 8, price : 80}, {name: "미니게임", left: 0, top: 208.52, border: '20px #FFE263 solid', YutIndex: 9}, {name: "경주", left: 7.10, top: 154.55, border: '20px #eeeeee solid', YutIndex: 10, price : 100}, {name: "대구", left: 27.94, top: 104.26, border: '20px #eeeeee solid', YutIndex: 11, price : 110}, - {name: "KTX", left: 60.27, top: 60.47, border: '20px #A5A5A5 solid', YutIndex: 12}, + {name: "갈림길", left: 60.27, top: 60.47, border: '20px #A5A5A5 solid', YutIndex: 12}, {name: "천안", left: 104.26, top: 27.94, border: '20px #eeeeee solid', YutIndex: 13, price : 130}, {name: "공주", left: 154.55, top: 7.11, border: '20px #eeeeee solid', YutIndex: 14, price : 140}, {name: "미니게임", left: 208.52, top: 0, border: '20px #FFE263 solid', YutIndex: 15}, {name: "청주", left: 262.49, top: 7.11, border: '20px #eeeeee solid', YutIndex: 16, price : 160}, {name: "충주", left: 312.78, top: 27.94, border: '20px #eeeeee solid', YutIndex: 17, price : 170}, - {name: "탐라국", left: 356.54, top: 61.18, border: '20px #A5A5A5 solid', YutIndex: 18, price : 180}, + {name: "갈림길", left: 356.54, top: 61.18, border: '20px #A5A5A5 solid', YutIndex: 18}, {name: "인천", left: 389.11, top: 104.26, border: '20px #eeeeee solid', YutIndex: 19, price : 190}, {name: "수원", left: 409.94, top: 154.55, border: '20px #eeeeee solid', YutIndex: 20, price : 200}, {name: "미니게임", left: 417.04, top: 208.52, border: '20px #FFE263 solid', YutIndex: 21}, @@ -26,7 +26,7 @@ export const yutStates = [ {name: "경성", left: 98.30, top: 319.42, border: '20px #eeeeee solid', YutIndex: 30, price : 300}, {name: "미니게임", left: 135.20, top: 282.52, border: '20px #FFE263 solid', YutIndex: 31}, {name: "함흥", left: 172.09, top: 245.63, border: '20px #eeeeee solid', YutIndex: 32, price : 320}, - {name: "뭐였지", left: 208.76, top: 208.96, border: '20px #A5A5A5 solid', YutIndex: 100}, + {name: "갈림길", left: 208.76, top: 208.96, border: '20px #A5A5A5 solid', YutIndex: 100}, {name: "원주", left: 245.87, top: 171.85, border: '20px #eeeeee solid', YutIndex: 34, price : 340}, {name: "미니게임", left: 282.76, top: 134.96, border: '20px #FFE263 solid', YutIndex: 35}, {name: "강릉", left: 319.65, top: 98.07, border: '20px #eeeeee solid', YutIndex: 36, price : 360}, diff --git a/src/components/game/roulette.jsx b/src/components/game/roulette.jsx index 49af859..53f862d 100644 --- a/src/components/game/roulette.jsx +++ b/src/components/game/roulette.jsx @@ -124,6 +124,14 @@ const Roulette = ({client, myPlayer}) => { default: alert("꽝! 다음 기회에"); } + client.send( + `/app/mini-game/result/${roomId}`, + { + name: myPlayer, + number: num, + }, + JSON.stringify({message: "result"}) + ); }; const rouletteStartClick = () => {