Skip to content

Commit

Permalink
Merge pull request #68 from Joseonpaldo/minseok
Browse files Browse the repository at this point in the history
turn fix
  • Loading branch information
themerous authored Sep 11, 2024
2 parents 44bdb7e + 6066b98 commit 2fe4517
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 22 deletions.
10 changes: 5 additions & 5 deletions src/components/game/Lobby.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
55 changes: 42 additions & 13 deletions src/components/game/YutPan.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down Expand Up @@ -385,6 +387,7 @@ function YutPan() {
setMyTurn(false);
if (myPlayer == ("player" + (index + 1))) {
setMyTurn(true);
setStepEvent(true);
}
}
if (player.SessionId === undefined || player.SessionId === "") {
Expand All @@ -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)
Expand All @@ -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}`,
Expand All @@ -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]);

Expand Down Expand Up @@ -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) {
Expand All @@ -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();
}

Expand Down Expand Up @@ -797,7 +826,7 @@ function YutPan() {
</div>

{/*<div style={{fontSize: "20px", position: "absolute"}} onClick={start}>한번더</div>*/}
{/*<div style={{fontSize: "20px", position: "absolute", top: "10%"}} onClick={passTurn}>pass turn</div>*/}
<div style={{fontSize: "20px", position: "absolute", top: "10%"}} onClick={passTurn}>pass turn</div>


{Object.keys(players).map((key, index) => {
Expand Down
8 changes: 4 additions & 4 deletions src/components/game/YutStates.js
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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},
Expand Down
8 changes: 8 additions & 0 deletions src/components/game/roulette.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand Down

0 comments on commit 2fe4517

Please sign in to comment.