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

[jwon] typescript-racingcar #5

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

Conversation

jwon42
Copy link
Member

@jwon42 jwon42 commented Jun 16, 2021

๐Ÿš— ์ž๋™์ฐจ ๊ฒฝ์ฃผ ๊ฒŒ์ž„ (typescript-racingcar)



๐Ÿ“— ๊ณผ์ œ ๊ธฐ๋ณธ ์š”๊ตฌ์‚ฌํ•ญ

  • ๐ŸŽฏ step1

    • ์ฃผ์–ด์ง„ ํšŸ์ˆ˜ ๋™์•ˆ n๋Œ€์˜ ์ž๋™์ฐจ๋Š” ์ „์ง„ ๋˜๋Š” ๋ฉˆ์ถœ ์ˆ˜ ์žˆ๋‹ค.
    • ์ž๋™์ฐจ์— ์ด๋ฆ„์„ ๋ถ€์—ฌํ•  ์ˆ˜ ์žˆ๋‹ค. ์ „์ง„ํ•˜๋Š” ์ž๋™์ฐจ๋ฅผ ์ถœ๋ ฅํ•  ๋•Œ ์ž๋™์ฐจ ์ด๋ฆ„์„ ๊ฐ™์ด ์ถœ๋ ฅํ•œ๋‹ค.
    • ์ž๋™์ฐจ ์ด๋ฆ„์€ ์‰ผํ‘œ(,)๋ฅผ ๊ธฐ์ค€์œผ๋กœ ๊ตฌ๋ถ„ํ•˜๋ฉฐ ์ด๋ฆ„์€ 5์ž ์ดํ•˜๋งŒ ๊ฐ€๋Šฅํ•˜๋‹ค.
    • ์‚ฌ์šฉ์ž๋Š” ๋ช‡ ๋ฒˆ์˜ ์ด๋™์„ ํ•  ๊ฒƒ์ธ์ง€๋ฅผ ์ž…๋ ฅํ•  ์ˆ˜ ์žˆ์–ด์•ผ ํ•œ๋‹ค.
    • ์ „์ง„ํ•˜๋Š” ์กฐ๊ฑด์€ 0์—์„œ 9 ์‚ฌ์ด์—์„œ random ๊ฐ’์„ ๊ตฌํ•œ ํ›„ random ๊ฐ’์ด 4 ์ด์ƒ์ผ ๊ฒฝ์šฐ ์ „์ง„ํ•˜๊ณ , 3 ์ดํ•˜์˜ ๊ฐ’์ด๋ฉด ๋ฉˆ์ถ˜๋‹ค.
    • ์ž๋™์ฐจ ๊ฒฝ์ฃผ ๊ฒŒ์ž„์„ ์™„๋ฃŒํ•œ ํ›„ ๋ˆ„๊ฐ€ ์šฐ์Šนํ–ˆ๋Š”์ง€๋ฅผ ์•Œ๋ ค์ค€๋‹ค. ์šฐ์Šน์ž๋Š” ํ•œ ๋ช… ์ด์ƒ์ผ ์ˆ˜ ์žˆ๋‹ค.
    • ์šฐ์Šน์ž๊ฐ€ ์—ฌ๋Ÿฌ๋ช…์ผ ๊ฒฝ์šฐ ,๋ฅผ ์ด์šฉํ•˜์—ฌ ๊ตฌ๋ถ„ํ•œ๋‹ค.
  • ๐ŸŽฏ๐ŸŽฏ step2

    • ์ž๋™์ฐจ ๊ฒฝ์ฃผ ๊ฒŒ์ž„์˜ ํ„ด์ด ์ง„ํ–‰ ๋  ๋•Œ๋งˆ๋‹ค 1์ดˆ์˜ ํ…€(progressive ์žฌ์ƒ)์„ ๋‘๊ณ  ์ง„ํ–‰ํ•œ๋‹ค.
      • ์• ๋‹ˆ๋ฉ”์ด์…˜ ๊ตฌํ˜„์„ ์œ„ํ•ด setInterval, setTimeout, requestAnimationFrame ์„ ํ™œ์šฉํ•œ๋‹ค.
    • ์ •์ƒ์ ์œผ๋กœ ๊ฒŒ์ž„์˜ ํ„ด์ด ๋‹ค ๋™์ž‘๋œ ํ›„์—๋Š” ๊ฒฐ๊ณผ๋ฅผ ๋ณด์—ฌ์ฃผ๊ณ , 2์ดˆ ํ›„์— ์ถ•ํ•˜์˜ alert ๋ฉ”์„ธ์ง€๋ฅผ ๋„์šด๋‹ค.
    • ์œ„ ๊ธฐ๋Šฅ๋“ค์ด ์ •์ƒ์ ์œผ๋กœ ๋™์ž‘ํ•˜๋Š”์ง€ Cypress๋ฅผ ์ด์šฉํ•ด ํ…Œ์ŠคํŠธํ•œ๋‹ค.

๐Ÿ“ ๊ณผ์ œ๋ฅผ ์ง„ํ–‰ํ•˜๋ฉฐ

  1. ํŠน์ง•

    • Model, View, Controller๋กœ ๊ธฐ๋Šฅ์„ ๋ถ„๋ฆฌํ•˜์—ฌ ๊ตฌํ˜„ํ•˜๊ณ ์ž ๋…ธ๋ ฅํ–ˆ์Šต๋‹ˆ๋‹ค.
      • Model ์—๋Š” ์ž…๋ ฅ ๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅ์„ ์œ„ํ•œ InputData ํด๋ž˜์Šค, ๊ฒŒ์ž„ ์ง„ํ–‰ ๋ฐ์ดํ„ฐ ์ €์žฅ์„ ์œ„ํ•œ Car, Game ํด๋ž˜์Šค๊ฐ€ ์œ„์น˜ํ•ฉ๋‹ˆ๋‹ค.
      • View ์—๋Š” ํ…œํ”Œ๋ฆฟ๊ณผ ํ…œํ”Œ๋ฆฟ์„ ๋ Œ๋”๋ง ํ•˜๋Š” ํ•จ์ˆ˜๊ฐ€ ์œ„์น˜ํ•ฉ๋‹ˆ๋‹ค.
      • Controller ์—๋Š” ์ด๋ฒคํŠธ์™€ ๋ฆฌ์Šค๋„ˆ์— ๊ด€๋ จ๋œ ํ•จ์ˆ˜, ๊ฒŒ์ž„ ์ง„ํ–‰ ์ƒํ™ฉ์— ๋”ฐ๋ผ Model๊ณผ View๋ฅผ ์กฐ์ž‘ํ•˜๋Š” ํ•จ์ˆ˜๊ฐ€ ์œ„์น˜ํ•ฉ๋‹ˆ๋‹ค.
    • DOM ์ ‘๊ทผ ์‹œ querySelector(), querySelectorAll() ๋งŒ์„ ์‚ฌ์šฉํ–ˆ์Šต๋‹ˆ๋‹ค.
    • ์œ ์ง€๋ณด์ˆ˜ ๋ฐ ์ฝ”๋“œ ๊ฐ€๋…์„ฑ ํ–ฅ์ƒ์„ ์œ„ํ•ด ์ƒ์ˆ˜๋ฅผ ์ •์˜ํ•˜์—ฌ ์‚ฌ์šฉํ–ˆ์Šต๋‹ˆ๋‹ค.
    • ๋ชจ๋“  ํ•จ์ˆ˜๋Š” 1๊ฐ€์ง€ ๊ธฐ๋Šฅ๋งŒ์„ ์ˆ˜ํ–‰ํ•˜๊ณ , ํ•จ์ˆ˜ ์ด๋ฆ„์—์„œ ๊ทธ ๊ธฐ๋Šฅ์„ ์œ ์ถ”ํ•  ์ˆ˜ ์žˆ๋„๋ก ๋งŒ๋“œ๋ ค๊ณ  ๋…ธ๋ ฅํ–ˆ์Šต๋‹ˆ๋‹ค.
  2. ํ…œํ”Œ๋ฆฟ ๊ตฌ์กฐ

    1. ํ…œํ”Œ๋ฆฟ์€ div #app ๋‚ด๋ถ€์— 3๊ฐœ์˜ section์œผ๋กœ ๊ตฌ๋ถ„๋˜์–ด ์žˆ๊ณ  ์กฐ๊ฑด์„ ๋งŒ์กฑํ•˜๋Š” ๊ฒฝ์šฐ section ์ˆœ์ฐจ์ ์œผ๋กœ ๋ Œ๋”๋งํ•ฉ๋‹ˆ๋‹ค.
      • #input-section์€ ์‚ฌ์šฉ์ž์—๊ฒŒ ์ •๋ณด๋ฅผ ์ž…๋ ฅ๋ฐ›๋Š” ํŒŒํŠธ์ž…๋‹ˆ๋‹ค.
      • #progress-section์€ ๊ฒŒ์ž„ ์ง„ํ–‰ ๊ณผ์ • ์ถœ๋ ฅ ํŒŒํŠธ์ž…๋‹ˆ๋‹ค.
      • #result-section์€ ๊ฒŒ์ž„ ๊ฒฐ๊ณผ ์ถœ๋ ฅ ํŒŒํŠธ์ž…๋‹ˆ๋‹ค.
  3. ์ฝ”๋“œ ์ง„ํ–‰

    1. app()์„ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.
    2. #input-section์„ ๋ Œ๋”๋งํ•˜๊ณ  ์ด๋ฒคํŠธ์™€ ๋ฆฌ์Šค๋„ˆ๋ฅผ ์„ธํŒ…ํ•ฉ๋‹ˆ๋‹ค.
    3. ๋ฆฌ์Šค๋„ˆ getCarName(), getTryCount() ์—์„œ ์ž…๋ ฅ ๋ฐ์ดํ„ฐ ์œ ํšจ์„ฑ์„ ์ฒดํฌํ•ฉ๋‹ˆ๋‹ค.
    4. startGame() ์—์„œ ๊ฒŒ์ž„์„ ์ง„ํ–‰ํ•˜๋ฉฐ ๊ทธ ๊ณผ์ •์„ #progress-section์— ๋ Œ๋”๋งํ•ฉ๋‹ˆ๋‹ค.
    5. ๊ฒŒ์ž„์ด ๋๋‚˜๋ฉด ๊ฒฐ๊ณผ๋ฅผ #result-section์— ๋ Œ๋”๋งํ•ฉ๋‹ˆ๋‹ค.
    6. [๋‹ค์‹œ ์‹œ์ž‘ํ•˜๊ธฐ] ๋ฒ„ํŠผ์— ์ด๋ฒคํŠธ์™€ ๋ฆฌ์Šค๋„ˆ๋ฅผ ์„ธํŒ…ํ•ฉ๋‹ˆ๋‹ค.
    7. [๋‹ค์‹œ ์‹œ์ž‘ํ•˜๊ธฐ] ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๋ฉด div #app์˜ childNode๋ฅผ ๋ชจ๋‘ ์‚ญ์ œํ•ฉ๋‹ˆ๋‹ค.
    8. ii. ๋ถ€ํ„ฐ ๋‹ค์‹œ ์ง„ํ–‰ํ•ฉ๋‹ˆ๋‹ค.

๐Ÿ’ก ์—๋Ÿฌ ์ฒ˜๋ฆฌ (์ •์˜๋˜์ง€ ์•Š์€ ๋™์ž‘์— ๋Œ€ํ•œ ๋‚ด์šฉ ํฌํ•จ)

  • ์ž๋™์ฐจ ์ด๋ฆ„ ์ž…๋ ฅ

    • ๊ณต๋ฐฑ ์ž…๋ ฅ -> ๊ฒฝ๊ณ ์ฐฝ -> ์žฌ์ž…๋ ฅ ํ•„์š”
    • ์ž๋™์ฐจ 1๋Œ€๋งŒ ์ž…๋ ฅ -> ๊ฒฝ๊ณ ์ฐฝ -> 2๋Œ€ ์ด์ƒ ์ž…๋ ฅ ํ•„์š”
    • ์ž๋™์ฐจ ์ด๋ฆ„ ์ค‘๋ณต -> ๊ฒฝ๊ณ ์ฐฝ -> ์žฌ์ž…๋ ฅ ํ•„์š”
    • ์ž๋™์ฐจ ์ด๋ฆ„์ด 5๊ธ€์ž ์ดˆ๊ณผ -> ๊ฒฝ๊ณ ์ฐฝ -> ์žฌ์ž…๋ ฅ ํ•„์š”
    • [์ด๋ฆ„1, ์ด๋ฆ„2 , , ์ด๋ฆ„3] ์ด ์ž…๋ ฅ๋œ ๊ฒฝ์šฐ -> ๊ฒฝ๊ณ ์ฐฝ -> ์žฌ์ž…๋ ฅ ํ•„์š”
  • ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ

    • ๊ณต๋ฐฑ ์ž…๋ ฅ -> ๊ฒฝ๊ณ ์ฐฝ -> ์žฌ์ž…๋ ฅ ํ•„์š”
    • ์Œ์ˆ˜ ์ž…๋ ฅ -> ๊ฒฝ๊ณ ์ฐฝ -> 50 ์ดํ•˜ ์ž์—ฐ์ˆ˜ ์ž…๋ ฅ ํ•„์š”
    • 51 ์ด์ƒ ์ž…๋ ฅ -> ๊ฒฝ๊ณ ์ฐฝ -> 50 ์ดํ•˜ ์ž์—ฐ์ˆ˜ ์ž…๋ ฅ ํ•„์š”
      (์ˆ˜์‹ญํšŒ ์ด์ƒ์˜ ํšŸ์ˆ˜ ์ž…๋ ฅ์€ ์›ํ™œํ•œ ๊ฒŒ์ž„ ์ง„ํ–‰์„ ์œ„ํ•ด ๊ธˆ์ง€์‹œ์ผฐ์Šต๋‹ˆ๋‹ค)

๐Ÿ“š Cypress ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค ๋ชฉ๋ก

  • ์ดˆ๊ธฐํ™”๋ฉด ๋กœ๋”ฉ ํ…Œ์ŠคํŠธ

    • ์ž๋™์ฐจ ๊ฒฝ์ฃผ ๊ฒŒ์ž„์„ ์‹คํ–‰ํ•˜๋ฉด, ์ธํ’‹ ์„น์…˜์ด ๋ณด์ด๊ณ  ์ž๋™์ฐจ ์ด๋ฆ„ ์ž…๋ ฅ์ฐฝ์ด ํ™œ์„ฑํ™”๋œ๋‹ค
  • ์ž๋™์ฐจ ์ด๋ฆ„ ์ž…๋ ฅ ํ…Œ์ŠคํŠธ

    • ์ž๋™์ฐจ ์ด๋ฆ„์„ ์ž…๋ ฅํ•˜์ง€ ์•Š๊ณ  ํ™•์ธ ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜๋ฉด, ๊ฒฝ๊ณ ์ฐฝ์„ ๋„์šด๋‹ค
    • ์ž๋™์ฐจ ์ด๋ฆ„์„ 1๊ฐœ๋งŒ ์ž…๋ ฅํ•˜๊ณ  ํ™•์ธ ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜๋ฉด, ๊ฒฝ๊ณ ์ฐฝ์„ ๋„์šด๋‹ค
    • ๋น„์–ด์žˆ๋Š” ์ž๋™์ฐจ ์ด๋ฆ„์„ ์ž…๋ ฅํ•˜๊ณ  ํ™•์ธ ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜๋ฉด, ๊ฒฝ๊ณ ์ฐฝ์„ ๋„์šด๋‹ค
    • ์ค‘๋ณต๋œ ์ž๋™์ฐจ ์ด๋ฆ„์„ ์ž…๋ ฅํ•˜๊ณ  ํ™•์ธ ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜๋ฉด, ๊ฒฝ๊ณ ์ฐฝ์„ ๋„์šด๋‹ค
    • 5๊ธ€์ž๊ฐ€ ๋„˜๋Š” ์ž๋™์ฐจ ์ด๋ฆ„์„ ์ž…๋ ฅํ•˜๊ณ  ํ™•์ธ ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜๋ฉด, ๊ฒฝ๊ณ ์ฐฝ์„ ๋„์šด๋‹ค
    • ์ž๋™์ฐจ ์ด๋ฆ„์„ ์ •์ƒ์ ์œผ๋กœ ์ž…๋ ฅํ•˜๊ณ  ํ™•์ธ ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜๋ฉด, ์ž๋™์ฐจ ์ด๋ฆ„ ์ž…๋ ฅ์นธ๊ณผ ํด๋ฆญ ๋ฒ„ํŠผ์„ ๋น„ํ™œ์„ฑํ™” ํ•˜๊ณ  ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ์นธ๊ณผ ์‹œ๋„ ํšŸ์ˆ˜ ๋ฒ„ํŠผ์„ ํ™œ์„ฑํ™”ํ•œ๋‹ค
    • ์ž๋™์ฐจ ์ด๋ฆ„์„ ์ •์ƒ์ ์œผ๋กœ ์ž…๋ ฅํ•˜๊ณ  ํ™•์ธ ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜๋ฉด, ์ง„ํ–‰์ƒํ™ฉ ์„น์…˜์ด ๋กœ๋”ฉ๋œ๋‹ค
  • ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ํ…Œ์ŠคํŠธ

    • ํšŸ์ˆ˜๋ฅผ ์ž…๋ ฅํ•˜์ง€ ์•Š๊ณ  ํ™•์ธ ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜๋ฉด, ๊ฒฝ๊ณ ์ฐฝ์„ ๋„์šด๋‹ค
    • ์Œ์ˆ˜๋ฅผ ์ž…๋ ฅํ•˜๊ณ  ํ™•์ธ ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜๋ฉด, ๊ฒฝ๊ณ ์ฐฝ์„ ๋„์šด๋‹ค
    • 51 ์ด์ƒ์„ ์ž…๋ ฅํ•˜๊ณ  ํ™•์ธ ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜๋ฉด, ๊ฒฝ๊ณ ์ฐฝ์„ ๋„์šด๋‹ค
  • ์ง„ํ–‰ ์ƒํ™ฉ ์ถœ๋ ฅ ํ…Œ์ŠคํŠธ

    • ์ž๋™์ฐจ ์ด๋ฆ„๊ณผ ์‹œ๋„ ํšŸ์ˆ˜๋ฅผ ์ •์ƒ์ ์œผ๋กœ ์ž…๋ ฅํ•˜๊ณ  ํ™•์ธ ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜๋ฉด, ๊ฒŒ์ž„ ์ง„ํ–‰ ํ›„ ๊ฒฐ๊ณผ ์„น์…˜์ด ๋กœ๋”ฉ๋œ๋‹ค
    • ๊ฒŒ์ž„์ด ๋๋‚˜๋ฉด, ๊ฒฐ๊ณผ๋ฅผ ์ถœ๋ ฅํ•˜๊ณ  ์ถ•ํ•˜ ๋ฉ”์„ธ์ง€๋ฅผ ๋„์šด๋‹ค
  • ๊ฒŒ์ž„ ์žฌ์‹œ์ž‘ ํ…Œ์ŠคํŠธ

    • ๋‹ค์‹œ ์‹œ์ž‘ํ•˜๊ธฐ ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜๋ฉด, ์ง„ํ–‰ ์„น์…˜๊ณผ ๊ฒฐ๊ณผ ์„น์…˜์ด ์‚ฌ๋ผ์ง€๊ณ , ์ž๋™์ฐจ ์ด๋ฆ„ ์ž…๋ ฅ์นธ์ด ๋นˆ ์ƒํƒœ๋กœ ๊ฒŒ์ž„ ์‹œ์ž‘ ๋Œ€๊ธฐ์ƒํƒœ๊ฐ€ ๋œ๋‹ค

jwon42 added 30 commits June 3, 2021 20:57
jwon42 and others added 30 commits June 7, 2021 19:07
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.

1 participant