Skip to content

Commit

Permalink
Merge pull request #94 from 5wonju/feat/#73-quiz-result-per-round
Browse files Browse the repository at this point in the history
Feat/#73 ๋งค ๋ผ์šด๋“œ ํ€ด์ฆˆ ๊ฒฐ๊ณผ ์†Œ์ผ“ ํ†ต์‹ 
  • Loading branch information
3o14 authored May 14, 2024
2 parents 927ee5c + 5812042 commit 3a98258
Show file tree
Hide file tree
Showing 17 changed files with 119 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { Center, Cylinder, Text3D } from '@react-three/drei'
import { CylinderCollider, RigidBody } from '@react-three/rapier'
import React from 'react'
import { AnswerEnum } from '../lib/store-type'
import { useAnswerSelectStore } from '../lib/store'
import { useAnswerSelectStore, useRoundResultStore } from '../lib/store'

const AnswerSpot = () => {
const answers = Object.values(AnswerEnum).slice(0, 4)
const { selectAnswer, setSelectAnswer } = useAnswerSelectStore()

return answers.map((answer, index) => (
<group key={answer} rotation-y={((index + 1) / 4) * Math.PI * 2}>
<group position-x={8} position-z={-8}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ const GameField = () => {
}

// ๊ฐœ๋ฐœ์šฉ ๊ฒŒ์ž„ ์‹œ์ž‘
// useEffect(() => {
// startGame()
// }, [])
useEffect(() => {
startGame()
}, [])

return (
<>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useState } from 'react'
import { formatTime, QuizAnswer } from '../../lib/util'
import { useAnswerSelectStore, useQuizStore } from '../../lib/store'
import { useAnswerSelectStore, useQuizStore, useRoundResultStore } from '../../lib/store'
import RoomInfo from './RoomInfo'

const QuizContent = () => {
Expand All @@ -17,7 +17,11 @@ const QuizContent = () => {
}
const [time, setTime] = useState(quiz.timeLimit) // ์ดˆ๊ธฐ ์‹œ๊ฐ„: 10์ดˆ
const { selectAnswer } = useAnswerSelectStore()
const { answer: quizAnswer } = useRoundResultStore((state) => ({
answer: state.answer,
}))

// const quizAnswer = 'A'

useEffect(() => {
const timer = setInterval(() => {
Expand Down Expand Up @@ -58,7 +62,11 @@ const QuizContent = () => {
<li
key={index}
className={`flex items-center gap-3 glass ${
selectAnswer === QuizAnswer[index] ? 'bg-indigo-400 bg-opacity-40' : ''
selectAnswer === QuizAnswer[index]
? 'bg-indigo-400 bg-opacity-40'
: QuizAnswer[index] === quizAnswer
? 'bg-lime-400 bg-opacity-40'
: ''
} text-black gap-1 w-full rounded-xl transition-colors border-2 backdrop-blur-md border-opacity-75 border-white px-4 py-2`}
>
<span className="font-medium bg-indigo-600 text-white rounded-full size-6 flex items-center justify-center">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const RoomInfo = ({ quizNum = 0 }: { quizNum?: number }) => {
<span>{roomInfo.probCategory}</span>
<span>{roomInfo.probNum} Round</span>
{/* ๊ฒŒ์ž„ ์‹œ์ž‘ ํ›„์— ๋ณด์ผ ๋ถ€๋ถ„ */}
<span>2/8</span>
<span>{quizNum}/{roomInfo.probNum}</span>
</fieldset>
</>
)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect } from 'react'
import { useGameRoomStore } from '../../lib/store'
import { useGameRoomStore, useRoundResultStore } from '../../lib/store'
import { gameStateEnum } from '../../lib/store-type'
import CountdownContent from '../boardContent/CountContent'
import IntroductionContent from '../boardContent/IntroductionContent'
Expand All @@ -10,6 +10,9 @@ const GameBoard = () => {
gameState: state.gameState,
countdownGame: state.countdownGame,
}))
const { setAnswer } = useRoundResultStore((state) => ({
setAnswer: state.setAnswer,
}))

// useEffect(() => {
// countdownGame()
Expand All @@ -20,6 +23,7 @@ const GameBoard = () => {
case gameStateEnum.READY:
return <IntroductionContent />
case gameStateEnum.COUNTDOWN:
setAnswer(null)
return <CountdownContent />
case gameStateEnum.GAME:
return <QuizContent />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { useEffect, useState } from 'react'
import { rankList, teamColorToCssText } from '../../lib/util'
import { wonUserList } from '../../lib/dummy'
import { wonUserList } from '../../lib/dummy' // dummy data
import { teamEnum } from '../../lib/store-type'
import { useRoundResultStore } from '../../lib/store'

const QuizResult = () => {
const { roundResults } = useRoundResultStore((state) => ({
roundResults: state.roundResults,
}))
const [result, setResult] = useState({
winTeam: false,
0: false,
Expand Down Expand Up @@ -48,27 +52,28 @@ const QuizResult = () => {
</section>
{/* ๋ฆฌ์ŠคํŠธ ์š”์†Œ ํ•˜๋‚˜์”ฉ ๋“ฑ์žฅํ•˜๊ธฐ */}
<ul className="flex-1 flex flex-col gap-3 pt-5 justify-around">
{wonUserList.map((wonUser, index) => (
<li
key={index}
className={`${
result[index as keyof typeof result] ? 'visible animate-fadeIn' : 'invisible'
}
{roundResults &&
roundResults.map((wonUser, index) => (
<li
key={index}
className={`${
result[index as keyof typeof result] ? 'visible animate-fadeIn' : 'invisible'
}
glass bg-opacity-60 flex gap-4 justify-around items-end px-3 py-2`}
>
<p className="font-semibold text-xl text-darkGray3">{rankList[wonUser.rank]}.</p>
<p className="fle1 flex flex-col items-start">
<span className="font-normal text-xs text-darkGray3 h-3">{wonUser.time}์ดˆ</span>
<span
className={`${
teamColorToCssText[wonUser.team as teamEnum]
} font-medium text-xl overflow-hidden w-24 select-none truncate`}
>
{wonUser.nickname}
</span>
</p>
</li>
))}
>
<p className="font-semibold text-xl text-darkGray3">{rankList[wonUser.rank]}.</p>
<p className="fle1 flex flex-col items-start">
<span className="font-normal text-xs text-darkGray3 h-3">{wonUser.time}์ดˆ</span>
<span
className={`${
teamColorToCssText[wonUser.team as teamEnum]
} font-medium text-xl overflow-hidden w-24 select-none truncate`}
>
{wonUser.nickname}
</span>
</p>
</li>
))}
</ul>
</div>
)
Expand Down
9 changes: 8 additions & 1 deletion frontend/app/(page)/(needProtection)/game/lib/store-type.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IRoomInfo } from '../../lobby/lib/type'
import { IGameResult, IGameScore, IQuiz, IUserInfo } from './type'
import { IGameResult, IGameScore, IQuiz, IUserInfo, IUserRoundResult } from './type'

// :: ๊ฒŒ์ž„ ์ƒํƒœ
export enum gameStateEnum {
Expand Down Expand Up @@ -102,3 +102,10 @@ export interface IGameResultState {
gameResult: IGameResult | null
setGameResult: (gameResult: IGameResult) => void
}

export interface IRoundResultState {
answer: AnswerEnum | null
roundResults: IUserRoundResult[] | null
setAnswer: (answer: AnswerEnum | null) => void
setRoundResults: (gameResults: IUserRoundResult[]) => void
}
22 changes: 21 additions & 1 deletion frontend/app/(page)/(needProtection)/game/lib/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ import {
IModalState,
IPlayerState,
IQuizState,
IRoundResultState,
ITeamSetBoardState,
playerMoveStateEnum,
teamEnum,
} from './store-type'
import { IQuiz, IUserInfo } from './type'
import { IQuiz, IUserInfo, IUserRoundResult } from './type'

// :: RoomStore
export const useGameRoomStore = create<IGameRoomState>()(
Expand Down Expand Up @@ -193,3 +194,22 @@ export const useGameResultStore = create<IGameResultState>()(
{ name: 'GameResultStore' }
)
)

// :: ๋งค ๋ผ์šด๋“œ ๊ฒฐ๊ณผ (์ •๋‹ต ํŒ€, ์ •๋‹ต์ž ์ˆœ์œ„, ์ •๋‹ต ํŒ€์˜ ํš๋“ ํฌ์ธํŠธ)
export const useRoundResultStore = create<IRoundResultState>()(
devtools(
immer((set) => ({
answer: null,
roundResults: null,
setAnswer: (answer: AnswerEnum | null) =>
set((state) => {
state.answer = answer
}),
setRoundResults: (roundResults: IUserRoundResult[]) =>
set((state) => {
state.roundResults = roundResults
}),
})),
{ name: 'RoundResultStore' }
)
)
8 changes: 8 additions & 0 deletions frontend/app/(page)/(needProtection)/game/lib/type.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,11 @@ interface TeamResultProps {
teamPoint: number
teamResult: IUserResult[]
}

interface IUserRoundResult {
nickname: string
team: teamEnum
userId: number
rank: number
time: number
}
4 changes: 2 additions & 2 deletions frontend/app/(page)/(needProtection)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const ProtectedLayout = ({
case '/login':
return (
<ProtectedLogin>
<main className="pt-14 h-full">
<main className="pt-12 h-screen">
<HeaderNavigationBar />
{children}
</main>
Expand All @@ -33,7 +33,7 @@ const ProtectedLayout = ({
return (
<ProtectedRoute>
<ProtectedSocket>
<main className="pt-14 h-full">
<main className="pt-12 h-screen">
<HeaderNavigationBar />
{children}
</main>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const WaitingRoomList: React.FC = () => {
{roomList.length > 0 ? (
roomList.map((room) => <WaitingRoom key={room.roomId} room={room} />)
) : (
<fieldset className="flex flex-col gap-2 justify-center items-center col-span-2 pb-10 text-black select-none">
<fieldset className="flex flex-col gap-2 justify-center h-[calc(100vh/2)] items-center col-span-2 pb-10 text-black select-none">
<p className="text-xl">ํ˜„์žฌ ๋งŒ๋“ค์–ด์ง„ ๋ฐฉ์ด ์—†์Šต๋‹ˆ๋‹ค ๐Ÿ‘€</p>
<p className='font-light text-darkGray2'>์ƒˆ๋กœ์šด ๋ฐฉ์„ ๋งŒ๋“ค์–ด ๋ณด์„ธ์š”</p>
</fieldset>
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/(page)/(needProtection)/lobby/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const Lobby = () => {
useSetupSocket(socket)

return (
<main className="grid grid-cols-3 grid-rows-3 h-[calc(100vh-3.5rem)]">
<main className="grid grid-cols-3 grid-rows-3 h-[calc(100vh-3rem)]">
<section className="col-span-3 row-span-2 ">
<WaitingRoomList />
</section>
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/component/Navigation/HeaderNavigationBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const HeaderNavigationBar = () => {
}, [currentPath])

return (
<section className="flex justify-between items-center absolute mt-2 bg-white top-0 h-12 w-full px-4 select-none">
<section className="flex justify-between items-center absolute bg-white top-0 h-12 w-full px-4 select-none">
<div>
<h1 className="text-purple-300 font-bold my-auto text-center text-2xl px-3">
<Link href="/">LOGO</Link>
Expand Down
25 changes: 24 additions & 1 deletion frontend/app/hooks/useSetupSocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,22 @@ import {
useGameRoomStore,
useGameScoreStore,
useQuizStore,
useRoundResultStore,
} from '../(page)/(needProtection)/game/lib/store'
import { useWaitingRoomStore } from '../(page)/(needProtection)/lobby/lib/store'
import { IGameResult, IGameScore, IQuiz, IUserInfo } from '../(page)/(needProtection)/game/lib/type'
import {
IGameResult,
IGameScore,
IQuiz,
IUserInfo,
IUserRoundResult,
} from '../(page)/(needProtection)/game/lib/type'
import { IRoomInfo, IRoomOfLobby } from '../(page)/(needProtection)/lobby/lib/type'
import { SOCKET_RES_CODE } from '../lib/type.d'
import { useEffect } from 'react'
import { IChat, useChatLogsStore } from '../lib/store'
import { setUserScores } from '../lib/util'
import { AnswerEnum } from '../(page)/(needProtection)/game/lib/store-type'

// ์ฑ„ํŒ… ๊ด€๋ จ ์†Œ์ผ“ ์…‹ํŒ…
// - ๋Œ€๊ธฐ๋ฐฉ + ๊ฒŒ์ž„๋ฐฉ ๊ณตํ†ต์œผ๋กœ ์‚ฌ์šฉ
Expand Down Expand Up @@ -129,9 +137,14 @@ const useSetUpGame = (socket: WebSocket | null) => {
const { setQuiz } = useQuizStore()
const { setGameScore } = useGameScoreStore()
const { setGameResult } = useGameResultStore()
const { setAnswer, setRoundResults } = useRoundResultStore((state) => ({
setAnswer: state.setAnswer,
setRoundResults: state.setRoundResults,
}))
const router = useRouter()

const successUpdateRoomInfo = (roomInfo: IRoomOfLobby) => {
console.log('๋ฐฉ ์ •๋ณด ์—…๋ฐ์ดํŠธ ์„ฑ๊ณต ์‘๋‹ต', roomInfo)
setRoomInfo({
roomId: roomInfo.roomId,
roomTitle: roomInfo.roomTitle,
Expand Down Expand Up @@ -182,6 +195,12 @@ const useSetUpGame = (socket: WebSocket | null) => {
setGameUserList(newUserList)
}

const successQuizAnswerRank = (data: { answer: AnswerEnum; userRank: IUserRoundResult[] }) => {
console.log('๋งค ๋ผ์šด๋“œ ํ€ด์ฆˆ ์ •๋‹ต ๋ฐ ์ •๋‹ต์ž ์ˆœ์œ„ ๋ฐœํ‘œ')
setAnswer(data.answer)
setRoundResults(data.userRank)
}

const setUpGame = () => {
if (socket === null || socket.readyState !== WebSocket.OPEN) {
console.log('Socket is null or not connected.')
Expand Down Expand Up @@ -239,6 +258,10 @@ const useSetUpGame = (socket: WebSocket | null) => {
console.log('๋‹ค๋ฅธ ์œ ์ € ๋ฐฉ ๋‚˜๊ฐ”์Œ ์‘๋‹ต')
successOtherUserExit(responseData.data.userList)
break
case SOCKET_RES_CODE.ANSWER_TOP:
console.log('๋งค ๋ผ์šด๋“œ ํ€ด์ฆˆ ์ •๋‹ต ๋ฐ ์ •๋‹ต์ž ์ˆœ์œ„ ๋ฐœํ‘œ')
successQuizAnswerRank(responseData.data)
break
default:
console.log('์ด๋ฒคํŠธ ์ฝ”๋“œ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค. ํ˜„์žฌ๋Š” ์ฑ„ํŒ…์— ๋Œ€ํ•œ ์ด๋ฒคํŠธ ์ฝ”๋“œ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค.')
break
Expand Down
8 changes: 3 additions & 5 deletions frontend/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import ReactQueryProviders from './hooks/useReactQuery'
const inter = Inter({ subsets: ['latin'] })

export const metadata: Metadata = {
title: 'Create Next App',
title: '๐ŸŽฒ ๋ชจ ์•„๋‹ˆ๋ฉด ๋„',
description: 'Generated by create next app',
}

Expand All @@ -17,10 +17,8 @@ export default function RootLayout({
}>) {
return (
<html lang="en">
<body className={inter.className}>
<ReactQueryProviders>
<div id="root">{children}</div>
</ReactQueryProviders>
<body id="root" className={inter.className}>
<ReactQueryProviders>{children}</ReactQueryProviders>
</body>
</html>
)
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/lib/type.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export enum SOCKET_RES_CODE {
MOVE_CHARACTER = 110, // "์œ ์ € ์ด๋™",
CHANGE_ZONE_OWNER = 120, // null,
CHANGE_ZONE_OTHER = 121, // null,
ANSWER_TOP = 130, // null,
ANSWER_TOP = 130, // "๋งค ๋ผ์šด๋“œ ํ€ด์ฆˆ ์ •๋‹ต ๋ฐ ์ •๋‹ต์ž ์ˆœ์œ„ ๋ฐœํ‘œ",
NEXT_QUESTION = 140, // "๋‹ค์Œ ๋ฌธ์ œ ์ถœ์ œ",
GAME_RESULT_INFO = 150, // "๊ฒŒ์ž„ ๊ฒฐ๊ณผ(์šฐ์ŠนํŒ€ ๋ฐ ์œ ์ €๋ณ„ ํš๋“ ํฌ์ธํŠธ)",
ONE_PROBLEM_END_GET_TEAM_POINT = 160, // "ํ˜„์žฌ ํŒ€ ๋ณ„ ์ด ์ ์ˆ˜์™€ ๊ฐœ์ธ ์ ์ˆ˜ ์‘๋‹ต",
Expand Down
4 changes: 2 additions & 2 deletions frontend/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default function Home() {
return (
<>
<HeaderNavigationBar />
<main className="flex h-full items-center justify-between mx-10 px-10 pt-14">
<main className="flex h-[calc(100%-3rem)] items-center justify-between px-10 pt-12">
<fieldset className="flex flex-col gap-16 w-1/2">
<AutoInstruction />
<button
Expand All @@ -30,7 +30,7 @@ export default function Home() {
</button>
</fieldset>

<fieldset className="h-full my-auto w-1/2">
<fieldset className="h-[90%] my-auto w-1/2">
<PreviewImage />
</fieldset>
</main>
Expand Down

0 comments on commit 3a98258

Please sign in to comment.