Typing game

ํ˜•์ง„ ํ˜•์ง„

Typing game

๐Ÿ‘‹ ์•ˆ๋…•ํ•˜์„ธ์š”! ์ œ๊ฐ€ ๋งŒ๋“  r4k0nb4k0n/typing-game ํ”„๋กœ์ ํŠธ๋ฅผ ์†Œ๊ฐœํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. r4k0nb4k0n.github.io/typing-game ์—์„œ ์‚ฌ์šฉํ•ด๋ณด์‹ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค!

๐Ÿง ์ด๊ฑด ๋„๋Œ€์ฒด ๋ฌด์—‡์ธ๊ฐ€์š”?

์ฃผ์–ด์ง„ ๋ฌธ์ž์—ด๋“ค์„ ๋น ๋ฅด๊ณ  ์ •ํ™•ํ•˜๊ฒŒ ์ž…๋ ฅํ•˜๋Š” ๊ฒƒ์„ ๋ชฉํ‘œ๋กœ ์‹œ๊ฐ„์„ ์žฌ์–ด ์ž์‹ ์˜ ์‹ค๋ ฅ์„ ํŒŒ์•…ํ•˜๊ณ  ๊ธฐ๋ฅผ ์ˆ˜ ์žˆ๋Š” ์›น ์‚ฌ์ดํŠธ์ž…๋‹ˆ๋‹ค.

๐Ÿ’ ์–ด์ฉŒ๋‹ค๊ฐ€ ๋งŒ๋“ค์—ˆ๋‚˜์š”?

์ €๋Š” 2021-spring-web-beginner ํŒ€์—์„œ microsoft/Web-Devs-For-Beginner ๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ์›น ๊ธฐ์ดˆ ์ง€์‹์„ ํ•™์Šตํ•˜๊ณ , ํ”„๋กœ์ ํŠธ๋ฅผ ํ†ตํ•ด ์ด๋ฅผ ์‘์šฉํ•ด๋ณด๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

Primitive Typing Game Demo

Event-Driven Programming - Build a Typing Game ํŒŒํŠธ์—์„œ ์œ„์™€ ๊ฐ™์€ ๋ฐ๋ชจ๋ฅผ ๋ดค์Šต๋‹ˆ๋‹ค. ์ด๊ฑธ ์ œ๊ฐ€ ์›ํ•˜๋Š” ํ˜•ํƒœ์™€ ๋ฐฉ์‹์œผ๋กœ ๋งŒ๋“ค์–ด๋ณด๊ณ  ์‹ถ์—ˆ์Šต๋‹ˆ๋‹ค.

๐Ÿง‘โ€๐Ÿ”ง ์–ด๋–ป๊ฒŒ ๋งŒ๋“ค์—ˆ๋‚˜์š”?

microsoft/Web-Devs-For-Beginner ๋ฅผ ํ†ตํ•ด HTML/CSS/JS ๊ธฐ์ดˆ๋ฅผ ํ•™์Šตํ•˜๊ณ  DOM ์กฐ์ž‘์„ ์‹ค์Šตํ–ˆ์Šต๋‹ˆ๋‹ค. Typing game๋„ ์ด๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ๋งŒ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค. ์—ฌ๊ธฐ์— ์ œ๊ฐ€ ์›ํ•˜๋Š” ํ˜•ํƒœ์˜ ์›€์ง์ž„์„ ๋„ฃ๊ธฐ ์œ„ํ•ด CSS ์• ๋‹ˆ๋ฉ”์ด์…˜์„ ๋”ฐ๋กœ ์ฐพ์•„ ๊ตฌํ˜„ํ–ˆ์Šต๋‹ˆ๋‹ค. Github Pages๋ฅผ ํ†ตํ•ด ๋ฐฐํฌํ–ˆ์Šต๋‹ˆ๋‹ค.

์•„๋ž˜๋Š” directory listing์ž…๋‹ˆ๋‹ค.

1
2
3
4
5
6
7
8
9
10
11
๐Ÿ“‚ r4k0nb4k0n/typing-game
    ๐Ÿ“‚ assets/
        ๐Ÿ“„ GitHub-Mark-32px.png
        ๐Ÿ“„ Typing_dark_01_Videvo.mov
        ๐Ÿ“„ Typing_dark_02_Videvo.mov
        ๐Ÿ“„ Typing_dark_03_Videvo.mov
    ๐Ÿ“„ README.md
    ๐Ÿ“„ index.html
    ๐Ÿ“„ quotes.js    # ํƒ€์ดํ•‘ํ•  ๋ฌธ์ž์—ด๋“ค์„ ๋ฐฐ์—ด๋กœ ์ €์žฅํ•˜๋Š” ์Šคํฌ๋ฆฝํŠธ
    ๐Ÿ“„ script.js    # DOM ์กฐ์ž‘ ๋“ฑ์˜ ์Šคํฌ๋ฆฝํŠธ
    ๐Ÿ“„ style.css    # ์Šคํƒ€์ผ๊ณผ ์• ๋‹ˆ๋ฉ”์ด์…˜ ์ •์˜

๐Ÿง— ์–ด๋””์„œ ์‚ฝ์งˆ์„ ํ–ˆ๋‚˜์š”?

1. Multiple videos on background

๋ฐฐ๊ฒฝ์— 3๊ฐœ์˜ ๋™์˜์ƒ์ด ์ฐจ๋ก€๋Œ€๋กœ ๋‚˜์™€์„œ ๋ฐ˜๋ณต์žฌ์ƒ ํ•˜๋Š” ๊ฒƒ์„ ๊ตฌํ˜„ํ–ˆ์Šต๋‹ˆ๋‹ค.

์ฒ˜์Œ์—๋Š” ํ•˜๋‚˜์˜ <video> element๋ฅผ ๋‘๊ณ , onended ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ๋ฅผ ํ†ตํ•ด ํ•ด๋‹น element DOM์˜ src ์†์„ฑ์„ ์ง์ ‘ ๊ต์ฒดํ•˜๋Š” ์‹์œผ๋กœ ๊ตฌํ˜„ํ–ˆ๋Š”๋ฐ, ์ด๋Š” Flickering์ด ๋ฐœ์ƒํ•˜์—ฌ ๋Š๋ฆฌ๊ณ  ์˜ค๋ฅ˜๊ฐ€ ๊ฑธ๋ฆฐ ๊ฒƒ์ฒ˜๋Ÿผ ๋ณด์˜€์Šต๋‹ˆ๋‹ค.

๋”ฐ๋ผ์„œ ๋™์˜์ƒ ๊ฐœ์ˆ˜๋งŒํผ <video> element๋“ค์„ ๋งŒ๋“ค๊ณ , ๊ฐ๊ฐ style.visibility๋ฅผ ๋จน์—ฌ์„œ ๋‹จ ํ•˜๋‚˜์˜ <video> ๋งŒ ๋ณด์ด๊ฒŒ ํ–ˆ๋‹ค๊ฐ€ ended ์ด๋ฒคํŠธ๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด ๋‹ค์Œ ๋™์˜์ƒ๋งŒ ๋ณด์ด๊ฒŒ ํ•˜๊ณ  ๋‚˜๋จธ์ง€ <video> element๋“ค์€ ์•ˆ๋ณด์ด๊ฒŒ ๊ฐ€๋ ธ์Šต๋‹ˆ๋‹ค.

์•„๋ž˜๋Š” ํ•ด๋‹น ์ฝ”๋“œ์ž…๋‹ˆ๋‹ค.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<!DOCTYPE html>
<video
  playsinline
  muted
  id="bgvid1"
  src="./assets/Typing_dark_01_Videvo.mov"
  onended="bgvid_onended()"
  style="visibility: visible;"
></video>
<video
  playsinline
  muted
  id="bgvid2"
  src="./assets/Typing_dark_02_Videvo.mov"
  onended="bgvid_onended()"
  style="visibility: hidden;"
></video>
<video
  playsinline
  muted
  id="bgvid3"
  src="./assets/Typing_dark_03_Videvo.mov"
  onended="bgvid_onended()"
  style="visibility: hidden;"
></video>
<html>
  <head></head>
  <body></body>
</html>
<script type="text/javascript">
  const bgvids = document.querySelectorAll("video");

  function bgvid_onended() {
    bgvids[bgvid_index].style.visibility = "hidden";
    bgvids[bgvid_index].currentTime = 0;
    bgvid_index = (bgvid_index + 1) % bgvids.length;
    bgvids[bgvid_index].play();
    bgvids[bgvid_index].style.visibility = "visible";
  }

  let bgvid_index = 0;
  bgvids[bgvid_index].play();
</script>

2. Fake caret

ํˆฌ๋ช…ํ•œ input์„ ๋งŒ๋“ค๊ณ , ๊ทธ ์•ˆ์˜ caret๋„ ์ œ๊ฐ€ ์›ํ•˜๋Š” ๋ชจ์–‘์ธ ๊ฐ€๋ž˜๋–ก์œผ๋กœ ๊ตฌํ˜„ํ–ˆ์Šต๋‹ˆ๋‹ค.

<input> element์˜ css(border, background)๋ฅผ ์ˆ˜์ •ํ•˜์—ฌ ํˆฌ๋ช…ํ•˜๊ฒŒ ๋งŒ๋“ค์–ด๋ณด๋ ค ํ–ˆ์œผ๋‚˜ ์ž˜ ์ ์šฉ๋˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค. ์ด๋Š” <h1> element์— contenteditable="true" attribute๋ฅผ ์ถ”๊ฐ€ํ•˜์—ฌ ์ž…๋ ฅ์ด ๊ฐ€๋Šฅํ•˜๋„๋ก ๋งŒ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค. ์ด๋ฅผ ํ†ตํ•ด ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ํˆฌ๋ช…ํ•˜๊ฒŒ ๋งŒ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค. ์ด ์•ˆ์˜ caret์„ ๋‚ด๊ฐ€ ์›ํ•˜๋Š” ๋ชจ์–‘์ธ ๋‘๊บผ์šด ํฐ์ƒ‰ ๋ง‰๋Œ€๊ธฐ ๋ชจ์–‘์œผ๋กœ ๋ฐ”๊พธ๋ ค๊ณ  ๊ด€๋ จ attribute๋ฅผ ์ฐพ์•„๋ดค์œผ๋‚˜ caret-color๋งŒ ์ฐพ์•„์„œ ์‚ฌ์šฉํ–ˆ์Šต๋‹ˆ๋‹ค. ๋˜๋‹ค๋ฅธ <h1> element๋ฅผ ๋‘๊บผ์šด ํฐ์ƒ‰ ๋ง‰๋Œ€๊ธฐ ๋ชจ์–‘์— ๊นœ๋นก์ด๋Š” ์• ๋‹ˆ๋ฉ”์ด์…˜์„ ์ถ”๊ฐ€ํ•œ css๋ฅผ ์ ์šฉํ•˜์—ฌ fake caret์„ ๋งŒ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค. ์‹ค์ œ caret์˜ caret-color๋ฅผ transparent๋กœ ์ ์šฉํ•˜์—ฌ ๊ฐ€๋ฆฌ๊ณ , fake caret์ด ๋งจ ๋์— ์žˆ๋Š” ๊ฒฝ์šฐ ๊ฐ€์งœ caret์ด ๊ทธ๋Ÿด๋“ฏํ•˜๊ฒŒ ๋ณด์ด๊ฒŒ ๋งŒ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค.

@Taehee Lee ๋‹˜์˜ ๊ธฐ๋Šฅ ์ œ์•ˆ์œผ๋กœ Fake input์„ ํ†ตํ•ด Fake caret๋„ ํ™”์‚ดํ‘œ ํ‚ค๋ฅผ ํ†ตํ•ด ์›€์ง์ด๋Š” ๊ฒƒ์„ ๊ตฌํ˜„ํ•  ์˜ˆ์ •์ž…๋‹ˆ๋‹ค. ๊ด€๋ จ PR

๐Ÿง‘โ€๐Ÿ’ป ๋งˆ์น˜๋ฉฐ

2.chores.png

๋งŽ์€ ๋ถ„๋“ค์ด ํ”ผ๋“œ๋ฐฑ์„ ํ•ด์ฃผ์…จ์Šต๋‹ˆ๋‹ค. ๐Ÿ™‡โ€โ™‚๏ธ ์ œ๋ณด๋œ ๋ฒ„๊ทธ๋“ค๊ณผ ๊ธฐ๋Šฅ ์ œ์•ˆ์ด ์ด๋งŒํผ ์Œ“์—ฌ์žˆ์œผ๋‹ˆ ์‹œ๊ฐ„ ๋‚  ๋•Œ๋งˆ๋‹ค ํ•ด์น˜์šฐ๊ฒ ์Šต๋‹ˆ๋‹ค.

์—ฌ๋Ÿฌ๋ถ„๋“ค๋„ ์ž‘๊ฒŒ๋‚˜๋งˆ ์›ํ•˜๋Š” ๊ฒƒ์„ ๋งŒ๋“œ๋Š” ํ”„๋กœ์ ํŠธ๋ฅผ ํ•ด๋ณด์…จ์œผ๋ฉด ํ•ฉ๋‹ˆ๋‹ค. ๐Ÿ‘

comments powered by Disqus