Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3주차 기본 과제] 1 to 50 게임 #4

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open

[3주차 기본 과제] 1 to 50 게임 #4

wants to merge 17 commits into from

Conversation

seong-hui
Copy link
Contributor

@seong-hui seong-hui commented Nov 5, 2024

✨ 구현 기능 명세

💡 기본 과제

  • Context API, 전역상태 라이브러리 사용 X (ThemeProvider 제외)
  1. 헤더
  • 게임/랭킹 2개의 메뉴 선택 가능
  • 게임 선택 시 헤더 우측에 레벨 선택 Select와 타이머 표시
  • 게임 선택 시 게임 판 출력
  • 랭킹 선택 시 헤더 우측엔 아무것도 나오지 않음
  • 랭킹 선택 시 랭킹 보드 출력
  1. 게임
  • (기본) 한 종류의 레벨만 구현
  • 숫자는 항상 랜덤으로 표시됨. (초기 표시 숫자들도, 이후 열리는 숫자들도 모두 랜덤)
  • 처음에 표시되는 숫자는 클릭해야 하는 숫자의 앞에 절반임. 만약 level 1이라 118까지 클릭해야한다면, 처음에는 19까지의 숫자가 랜덤으로 보여짐
  • 게임판 위쪽에 다음으로 클릭해야할 숫자를 표시
  • 1을 누르는 순간 게임이 시작되며 헤더 우측의 타이머가 동작. 타이머는 소수점 2번째 자리까지 측정.
  • 마지막 숫자 클릭시 게임 종료
  • 게임 종료 시, 타이머를 멈추고 alert 창을 띄워주며 걸린 시간을 표시
  • 게임 종료 시, 현재 시각, 게임의 레벨, 플레이 시간 3개의 정보를 localStorage에 저장 (랭킹에서 사용)
  • 종료 창에서 확인 누르면 다시 시작할 수 있는 상태로 게임 초기화
  • 게임 중 level 변경 시 다시 시작할 수 있는 상태로 게임 초기화
  1. 랭킹
  • localStorage에서 데이터 불러오기
  • 플레이 시간 오름차순으로 보여야 함 (빨리 깬 기록이 위쪽)
  • 우측 상단의 초기화 버튼 누르면 대시보드 초기화 (localStorage도 초기화)

🔥 심화 과제

  1. 게임
  • Level 선택 가능
    Level 1: 3 x 3, Level 2: 4 x 4, Level 3: 5 x 5
  • 숫자 클릭할 때 클릭되는 것 같은 효과 (예시: 깜빡거림)
  • 게임 종료 alert 대신, React의 createPortal을 사용하여 Modal 구현
    createPortal
  1. 랭킹
  • Level 내림차순 & 시간 오름차순 정렬(정렬 기준이 2개). 높은 Level이 위쪽으로, 같은 레벨 중에선 플레이 시간이 짧은게 위쪽으로 정렬

공유과제

제목:

링크 첨부 :


❗️ 내가 새로 알게 된 점

  • ~ 부분 이렇게 구현했어요, 피드백 부탁해요!

❓ 구현 과정에서의 어려웠던/고민했던 부분

  • ~ 부분이 잘 구현한건지 잘 모르겠어요!
  • ~부분 다른 방법이 있는지 궁금해요!
  • 게임 레벨을 변경하면서 너무 변수들을 많이 남용한 것 같아서 이 부분을 어떻게 처리하셨는지 궁금합니다!

🥲 소요 시간

  • 1d

🖼️ 구현 결과물

Screen.Recording.2024-11-05.at.11.27.34.PM.mov

기본 뷰

  • 게임, 랭킹 헤더로 이동 가능
  • 레벨 선택 가능
  • 랭킹 정렬, 초기화 가능
  • 1누르면 시간 초 시작
Screen.Recording.2024-11-05.at.11.29.09.PM.mov

게임 구현

  • 게임 끝나면 게임 초 알려주는 alet
  • 게임 기록 랭킹에 저장

심화 과제 추가본

Screen.Recording.2024-12-18.at.7.47.06.PM.mov

@seong-hui seong-hui requested review from seueooo and bongtta November 5, 2024 13:38
Copy link

@bongtta bongtta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3주차 과제하시느라 너무 고생하셨습니다!! 저번에 들어보니 무지 바쁘신 것 같았는데ㅜㅜ

코드리뷰 하면서 모르는 것도 많고 처음 보는 것도 많아서 이것저것 찾아보느라 조금 늦었지만..ㅜㅜ 많은 도움이 되었습니다!!

또 저는 아직 파일을 잘 분리하지 못해서 한 파일에서 길게 코드를 작성하는데, 성희님 코드랑 파일 구조 보면서 많이 배웠습니다🙇‍♀️ 저도 다음엔 파일을 좀 더 깔끔하게 잘 분리해보겠습니다..!!!

import styled from "styled-components";
import Button from "../button/Button";
import Dropdown from "../dropDown/Dropdown";
import { useLocation, useNavigate } from "react-router-dom";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useLocation이랑 useNavigate는 처음 봤는데, 페이지를 이동하면서 state 값을 전달하고 데이터를 전달 받는 것이군요..! 새로운 것 알아갑니다!👍

Comment on lines +9 to +14
const onClickGameBtn = () => {
navigate("/");
};
const onClickRankBtn = () => {
navigate("/ranking");
};
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

랭킹 페이지를 누르면 주소 뒤에 "/ranking"이 뜨는데, 게임 페이지를 누르면 왜 "/"가 안 뜨는지 궁금합니다...!!

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

앗..ㅎㅎ 4주차 과제하면서 알게 되었습니다!!!!!! 하핫😅

onClick={() => handleCardClick(number, index)}
/>
) : (
<EmptyCard key={index} />
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저는 visibility 속성을 사용해서 두 번째 선택된 카드를 클릭하면 카드가 hidden 되게 하려다... 효과가 안 먹혀서 포기했는데, 빈 카드를 만드는 방법도 있었네요!! 코드 반영 때 참고하겠습니당🧐🙇‍♀️

Comment on lines +42 to +47
{records.map((record, index) => (
<TableRow key={index}>
<TableData>{record.currentTime}</TableData>
<TableData>Level {record.level}</TableData>
<TableData>{record.gameTime}초</TableData>
</TableRow>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

리액트의 key에 관해 검색하다가 알게 되었는데, key에 index값을 부여하면 배열 데이터가 변경 되었을 때 성능이 떨어질 수 있어 사용하지 않는 것이 좋다고 합니다..! (아니면 혹시 특별한 이유가 있는 것일까요..?!?🤔)


const Mainpage = () => {
const [time, setTime] = useState(0);
const timerRef = useRef(null);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useRef도 처음 보는데..~ useRef를 사용해서 변수를 선언하면 리렌더링 없이 값을 유지할 수 있네요..!!! 새로운 것 또또 알아갑니당...ㅎ..ㅎ

@@ -0,0 +1,22 @@
import styled from "styled-components";
import Header from "../components/header/header";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요기 header도 대문자로 수정하면 좋을 것 같습니다..!!

Comment on lines +15 to +42
const getCardSettings = (level) => {
switch (level) {
case 1:
return {
gameSize: 3,
middleNum: 9,
hideEndNum: 18,
};
case 2:
return {
gameSize: 4,
middleNum: 16,
hideEndNum: 32,
};
case 3:
return {
gameSize: 5,
middleNum: 25,
hideEndNum: 50,
};
default:
return {
gameSize: 3,
middleNum: 9,
hideEndNum: 18,
};
}
};
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

레벨 별로 다른 화면 설정을 반환할 때 switch문을 사용한 것 너무 좋은 것 같습니다!

Comment on lines +2 to +5
const gameData = {
currentTime: currentTime,
level: level,
gameTime: time,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기서 프로퍼티 이름이랑 변수 이름이 동일하기 때문에 currentTime이랑 level은 더 간단하게 줄일 수 있을 것 같습니다..!
const gameData = { currentTime, level, gameTime:time }
일부러 형식을 통일하려고 한 것이라면..!!! 죄송합니닿ㅎ😳😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants