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
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
3f50b68
feat: κ°œλ°œν™˜κ²½ μ„ΈνŒ…(eslint, prettier)
jwon42 Jun 3, 2021
2007e09
feat: Car 클래슀 생성
jwon42 Jun 3, 2021
dee9627
feat: ν…œν”Œλ¦Ώ, λ Œλ”λŸ¬ 섀계 ν›„ μ½”λ“œ μΆ”κ°€
jwon42 Jun 4, 2021
56ff4ab
feat: ν…œν”Œλ¦Ώ, λ Œλ”λŸ¬ 볡ꡬ
jwon42 Jun 4, 2021
c6b6fdb
feat: ν…œν”Œλ¦Ώ, λ Œλ”λŸ¬ 볡ꡬ
jwon42 Jun 4, 2021
c12581e
feat: 이벀트 μ„ΈνŒ…
jwon42 Jun 4, 2021
488e51b
feat: input, button에 id κ°’ λ°°μ •
jwon42 Jun 4, 2021
0758455
feat: section id λ°°μ •
jwon42 Jun 4, 2021
fa41e63
feat: game class 생성
jwon42 Jun 4, 2021
d5a1b0c
feat: spinnerDiv 쀑앙정렬 μš”μ†Œ μΆ”κ°€
jwon42 Jun 4, 2021
26e72fe
feat: model 폴더 index μΆ”κ°€
jwon42 Jun 4, 2021
e08451d
feat: eventListener μ„ΈνŒ… 및 κ΅¬ν˜„λΆ€ μΆ”κ°€
jwon42 Jun 4, 2021
10e4f37
feat: element μ‘°μž‘ ν•¨μˆ˜ μΆ”κ°€(clearInput, disableInputValue, disableButtonCl…
jwon42 Jun 4, 2021
f2824b6
feat: element μ‘°μž‘ ν•¨μˆ˜ μ˜€νƒ€ μˆ˜μ •
jwon42 Jun 4, 2021
2ef3dfa
feat: element μ‘°μž‘ν•¨μˆ˜ 이름 μˆ˜μ • 반영
jwon42 Jun 4, 2021
2cf8b36
feat: κ²Œμž„ μ‹€ν–‰ν•˜λŠ” λ‘œμ§ν•¨μˆ˜ 껍데기 생성
jwon42 Jun 4, 2021
d019b85
feat: μœ νš¨μ„± 검증뢀 파일 생성
jwon42 Jun 4, 2021
a254301
feat: 이름, μŠ€ν”Όλ„ˆ renderer μΆ”κ°€
jwon42 Jun 4, 2021
d1b1ffa
refactor: 초기 λ Œλ”λ§ 및 상황에 λ”°λ₯Έ 단일 λ Œλ”λ§μ„ μœ„ν•΄ viewμ—μ„œ 반볡 둜직 제거
jwon42 Jun 5, 2021
82327de
refactor: event.ts μ‚­μ œ
jwon42 Jun 5, 2021
f25d201
feat: querySelector, queryselectorAll 단좕 ν•¨μˆ˜ μΆ”κ°€
jwon42 Jun 5, 2021
78baebf
feat: 2단계λ₯Ό μœ„ν•œ 초기 λ Œλ”λ§ μ™„μ„±
jwon42 Jun 5, 2021
58b4440
refactor: gameν΄λž˜μŠ€μ—μ„œ count횟수 제거
jwon42 Jun 5, 2021
8a19503
feat: ν™”μ‚΄ν‘œ μ‚½μž… λ Œλ”λŸ¬ μΆ”κ°€
jwon42 Jun 5, 2021
2d9a86b
feat: carν΄λž˜μŠ€μ— indexμΆ”κ°€
jwon42 Jun 5, 2021
6ab18d5
feat: game 클래슀 생성 ν›„ κ²Œμž„ μ‹€ν–‰ν•˜λŠ” 둜직 μΆ”κ°€, 2단계 μ μš©μœ„ν•΄ μ‹œλ„νšŸμˆ˜λ³„λ‘œ 둜직 λΆ„κΈ°
jwon42 Jun 5, 2021
2a9ba84
feat: μžλ™μ°¨ 이름 μœ νš¨μ„± 검사 ν•¨μˆ˜ μΆ”κ°€
jwon42 Jun 5, 2021
b6a5ea7
feat: alert constant μ •μ˜
jwon42 Jun 5, 2021
f91ff9d
refactor: gameν΄λž˜μŠ€μ— 맀 λΌμš΄λ“œ 우승자의 indexμ €μž₯
jwon42 Jun 5, 2021
4125eb4
refactor: element disableν•˜λŠ” ν•¨μˆ˜λ₯Ό toggleν•˜λŠ” ν•¨μˆ˜λ‘œ μ—…κ·Έλ ˆμ΄λ“œ
jwon42 Jun 5, 2021
afcbab1
feat: input κ°’ μœ νš¨μ„± 검증 파트 μΆ”κ°€, κ°’ μž…λ ₯μ—¬λΆ€, 길이, 쀑볡 μ—¬λΆ€ 체크
jwon42 Jun 5, 2021
7237d02
feat: μ‹œλ„ 횟수 μ—λŸ¬ 메세지, 우승 μΆ•ν•˜ 메세지 μΆ”κ°€
jwon42 Jun 5, 2021
3d6681c
refactor: elementid μƒμˆ˜ μ •μ˜, prettier 적용, event와 lintener ν•¨μˆ˜ 뢄리
jwon42 Jun 5, 2021
feb759b
feat: git page 생성 μœ„ν•œ dist μ—…λ‘œλ“œ
jwon42 Jun 5, 2021
7fb9c40
feat: import 경둜 μˆ˜μ •
jwon42 Jun 5, 2021
d8f4190
refactor: ν•¨μˆ˜λͺ…, λ³€μˆ˜λͺ… 일뢀 μˆ˜μ •
jwon42 Jun 5, 2021
94b5eae
feat: μ‹œλ„ νšŸμˆ˜μ— 음수 μž…λ ₯λ˜λŠ” 경우 μ—λŸ¬μ²˜λ¦¬
jwon42 Jun 5, 2021
14ced3d
feat: 컴파일 된 dist폴더 κ°±μ‹ 
jwon42 Jun 5, 2021
566a3b1
refactor: rendererμ—μ„œ queryselector만 μ‚¬μš©ν•˜λ„λ‘ μˆ˜μ •
jwon42 Jun 7, 2021
694f143
refactor: game classμ—μ„œ ν™”μ‚΄ν‘œν•¨μˆ˜ 제거
jwon42 Jun 7, 2021
9febf27
refactor: removeChildNodes ν•¨μˆ˜μ—μ„œ 널체크λ₯Ό λ¨Όμ € ν•˜λ„λ‘ μˆ˜μ •
jwon42 Jun 7, 2021
bed97ec
refactor: μ‚¬μš©ν•˜μ§€ μ•ŠλŠ” alert μƒμˆ˜ 제거
jwon42 Jun 7, 2021
771cbbc
refactor: λ³€μˆ˜μ΄λ¦„ μˆ˜μ •, toggleν•¨μˆ˜ κΈ°λŠ₯ 뢄리, queryselector 미적용 λΆ€λΆ„ 적용
jwon42 Jun 7, 2021
3842968
refactor: κ²Œμž„ μž¬μ‹œμž‘ μ‹œ 이름 μž…λ ₯칸에 포컀싱, removeν•¨μˆ˜ view에 λͺ¨μ•„λ‘ 
jwon42 Jun 7, 2021
6952105
refactor: ν•œ λΌμš΄λ“œ 승자 ν™”μ‚΄ν‘œ κ·Έλ¦¬λŠ” ν•¨μˆ˜(playOnce) 둜직 μˆ˜μ •(thanks yechoi)
jwon42 Jun 7, 2021
8bcbcee
refactor: λ Œλ”λ§, 컨트둀러 더 ν™•μ‹€ν•˜κ²Œ λΆ„λ₯˜
jwon42 Jun 7, 2021
2ded7d1
refactor: μž…λ ₯λΆ€ μ—λŸ¬μ²΄ν¬ μΆ”κ°€(빈 이름 μž…λ ₯) 및 alert μƒμˆ˜ 문ꡬ μˆ˜μ •
jwon42 Jun 7, 2021
4df0077
refactor: alert μƒμˆ˜ 문ꡬ μˆ˜μ •
jwon42 Jun 7, 2021
fecd5ae
refactor: queryselector, queryselectorall 에 ν•„μš”ν•œ μƒμˆ˜ μ •μ˜, 적용
jwon42 Jun 7, 2021
e6fe29f
feat: rule, delay μƒμˆ˜ μΆ”κ°€
jwon42 Jun 7, 2021
223862e
test: cypress ν…ŒμŠ€νŠΈ μΌ€μ΄μŠ€ μΆ”κ°€
jwon42 Jun 7, 2021
dc4eb40
Delete game-control.js
jwon42 Jun 7, 2021
23cabd7
feat: delete utils.js (dist에 μœ„μΉ˜ν•˜λŠ” μ‚¬μš©ν•˜μ§€ μ•ŠλŠ” 파일)
jwon42 Jun 7, 2021
ee9c342
feat: delete play.js (dist에 μœ„μΉ˜ν•˜λŠ” μ‚¬μš©ν•˜μ§€ μ•ŠλŠ” 파일)
jwon42 Jun 7, 2021
b0c6317
feat: delete cypress/support/commands.js (μ‚¬μš©ν•˜μ§€ μ•ŠλŠ” 파일)
jwon42 Jun 7, 2021
b2468a8
feat: delete cypress/support/index.js (μ‚¬μš©ν•˜μ§€ μ•ŠλŠ” 파일)
jwon42 Jun 7, 2021
9344a9e
feat: delete cypress/fixtures/example.json (μ‚¬μš©ν•˜μ§€ μ•ŠλŠ” 파일)
jwon42 Jun 7, 2021
b62e122
feat: delete index.html.backup
jwon42 Jun 7, 2021
6df563a
feat: delete .eslintrc.js
jwon42 Jun 7, 2021
a51a9b2
refactor: eslint μ œμ•ˆ 반영
jwon42 Jun 8, 2021
efef57b
refactor: elementsID constants μˆ˜μ •
jwon42 Jun 8, 2021
b16496f
refactor: makeDelayν•¨μˆ˜ gameνŒŒμΌμ—μ„œλ§Œ μ‚¬μš©λ˜λ―€λ‘œ utilsμ—μ„œ 이동
jwon42 Jun 8, 2021
9ad005b
refactor: μΆ•ν•˜ νŒμ—… 이후 λ‹€μ‹œμ‹œμž‘ λ²„νŠΌ ν™œμ„±ν™”
jwon42 Jun 8, 2021
9a362f0
feat: delete elements.js
jwon42 Jun 8, 2021
bc933f0
refactor: for mvc
jwon42 Jun 16, 2021
2d88e56
refactor: change file name
jwon42 Jun 16, 2021
a81a040
refactor: remove SELECTOR constant
jwon42 Jun 16, 2021
c85401c
refactor: modify constants
jwon42 Jun 17, 2021
b12bee1
refactor: modify constants
jwon42 Jun 17, 2021
304d03d
refactor: cypress constants
jwon42 Jun 17, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"env": {
"browser": true,
"es2021": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 12,
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
}
}
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
package-lock.json
yarn.lock

# Created by https://www.toptal.com/developers/gitignore/api/node,vscode,intellij,webstorm
# Edit at https://www.toptal.com/developers/gitignore?templates=node,vscode,intellij,webstorm

Expand Down Expand Up @@ -192,7 +195,7 @@ typings/

# Nuxt.js build / generate output
.nuxt
dist
# dist

# Gatsby files
.cache/
Expand Down
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parser": "typescript",
"singleQuote": true,
"trailingComma": "all",
"printWidth": 120
}
1 change: 1 addition & 0 deletions cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
5 changes: 5 additions & 0 deletions cypress/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "[email protected]",
"body": "Fixtures are a great way to mock data for responses to routes"
}
139 changes: 139 additions & 0 deletions cypress/integration/racingcar.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import { ALERT, DELAY } from '../../dist/constants.js';

let carNamesSample = 'jwon, yeji, holee, yshin';
let tryCountSample = 3;

const carNameInputAndSubmit = (carNames) => {
if (carNames) {
cy.get('#car-names-input').type(carNames);
}
cy.get('#car-names-submit').click();
};

const tryCountInputAndSubmit = (tryCount) => {
if (tryCount) {
cy.get('#racing-count-input').type(tryCount);
}
cy.get('#racing-count-submit').click();
};

const catchAlertMessage = (alertMessage) => {
cy.on('window:alert', txt => {
expect(txt).to.contains(alertMessage);
});
};

describe('0. μ΄ˆκΈ°ν™”λ©΄ λ‘œλ”© ν…ŒμŠ€νŠΈ', () => {
beforeEach(() => {
cy.visit('http://localhost:5500');
});

it('μžλ™μ°¨ κ²½μ£Ό κ²Œμž„μ„ μ‹€ν–‰ν•˜λ©΄, 인풋 μ„Ήμ…˜μ΄ 보이고 μžλ™μ°¨ μž…λ ₯창이 ν™œμ„±ν™”λœλ‹€.=', () => {
cy.get('#input-section').should('be.visible');
cy.get('#car-names-input').should('not.be.disabled');
cy.get('#car-names-submit').should('not.be.disabled');
});
});

describe('1. μžλ™μ°¨ 이름 μž…λ ₯ ν…ŒμŠ€νŠΈ', () => {
beforeEach(() => {
cy.visit('http://localhost:5500');
});

it('μžλ™μ°¨ 이름을 μž…λ ₯ν•˜μ§€ μ•Šκ³  확인 λ²„νŠΌμ„ ν΄λ¦­ν•˜λ©΄, 경고창을 λ„μš΄λ‹€', () => {
carNameInputAndSubmit('');
catchAlertMessage(ALERT.CARNAME_NOTHING);
});

it('μžλ™μ°¨ 이름을 1개만 μž…λ ₯ν•˜κ³  확인 λ²„νŠΌμ„ ν΄λ¦­ν•˜λ©΄, 경고창을 λ„μš΄λ‹€', () => {
carNameInputAndSubmit('jwon');
catchAlertMessage(ALERT.CARNAME_ALONE);
});

it('λΉ„μ–΄μžˆλŠ” μžλ™μ°¨ 이름을 μž…λ ₯ν•˜κ³  확인 λ²„νŠΌμ„ ν΄λ¦­ν•˜λ©΄, 경고창을 λ„μš΄λ‹€', () => {
carNameInputAndSubmit('jwon, , holee');
catchAlertMessage(ALERT.CARNAME_EMPTY);
});

it('μ€‘λ³΅λœ μžλ™μ°¨ 이름을 μž…λ ₯ν•˜κ³  확인 λ²„νŠΌμ„ ν΄λ¦­ν•˜λ©΄, 경고창을 λ„μš΄λ‹€', () => {
carNameInputAndSubmit('jwon, jwon, yechoi, holee, yshin');
catchAlertMessage(ALERT.CARNAME_DOUBLE);
});

it('5κΈ€μž λ„˜λŠ” μžλ™μ°¨ 이름을 μž…λ ₯ν•˜κ³  확인 λ²„νŠΌμ„ ν΄λ¦­ν•˜λ©΄, 경고창을 λ„μš΄λ‹€', () => {
carNameInputAndSubmit('jwon, yechoi');
catchAlertMessage(ALERT.CARNAME_LENGTH);
});

it('μžλ™μ°¨ 이름을 μ •μƒμ μœΌλ‘œ μž…λ ₯ν•˜κ³  확인 λ²„νŠΌμ„ ν΄λ¦­ν•˜λ©΄, μžλ™μ°¨ 이름 μž…λ ₯μΉΈκ³Ό 클릭 λ²„νŠΌμ„ λΉ„ν™œμ„±ν™” ν•˜κ³  μ‹œλ„ 횟수 μž…λ ₯μΉΈκ³Ό μ‹œλ„ 횟수 λ²„νŠΌμ„ ν™œμ„±ν™”ν•œλ‹€', () => {
carNameInputAndSubmit(carNamesSample);
cy.get('#car-names-input').should('be.disabled');
cy.get('#car-names-submit').should('be.disabled');
cy.get('#racing-count-input').should('not.be.disabled');
cy.get('#racing-count-submit').should('not.be.disabled');
});

it('μžλ™μ°¨ 이름을 μ •μƒμ μœΌλ‘œ μž…λ ₯ν•˜κ³  확인 λ²„νŠΌμ„ ν΄λ¦­ν•˜λ©΄, 진행상황 μ„Ήμ…˜μ΄ λ‘œλ”©λœλ‹€. ', () => {
carNameInputAndSubmit(carNamesSample);
tryCountInputAndSubmit(tryCountSample);
cy.get('#progress-section').should('be.visible');
});
});

describe('2. μ‹œλ„ 횟수 μž…λ ₯ ν…ŒμŠ€νŠΈ', () => {
beforeEach(() => {
cy.visit('http://localhost:5500');
});

it('횟수λ₯Ό μž…λ ₯ν•˜μ§€ μ•Šκ³  확인 λ²„νŠΌμ„ ν΄λ¦­ν•˜λ©΄, 경고창을 λ„μš΄λ‹€', () => {
carNameInputAndSubmit(carNamesSample);
tryCountInputAndSubmit();
catchAlertMessage(ALERT.TRYCOUNT_NOTHING);
});

it('음수λ₯Ό μž…λ ₯ν•˜κ³  확인 λ²„νŠΌμ„ ν΄λ¦­ν•˜λ©΄, 경고창을 λ„μš΄λ‹€', () => {
carNameInputAndSubmit(carNamesSample);
tryCountInputAndSubmit(-5);
catchAlertMessage(ALERT.TRYCOUNT_UINT);
});

it('50 이상을 μž…λ ₯ν•˜κ³  확인 λ²„νŠΌμ„ ν΄λ¦­ν•˜λ©΄, 경고창을 λ„μš΄λ‹€', () => {
carNameInputAndSubmit(carNamesSample);
tryCountInputAndSubmit(51);
catchAlertMessage(ALERT.TRYCOUNT_TOO_BIG);
});
});

describe('3. 진행 상황 좜λ ₯ ν…ŒμŠ€νŠΈ', () => {
beforeEach(() => {
cy.visit('http://localhost:5500');
});

it('μžλ™μ°¨ 이름과 μ‹œλ„ 횟수λ₯Ό μ •μƒμ μœΌλ‘œ μž…λ ₯ν•˜κ³  확인 λ²„νŠΌμ„ ν΄λ¦­ν•˜λ©΄, κ²Œμž„ 진행 ν›„ κ²°κ³Ό μ„Ήμ…˜μ΄ λ‘œλ”©λœλ‹€', () => {
carNameInputAndSubmit(carNamesSample);
tryCountInputAndSubmit(tryCountSample);
});

it('κ²Œμž„μ΄ λλ‚˜λ©΄, κ²°κ³Όλ₯Ό 좜λ ₯ν•˜κ³  μΆ•ν•˜ 메세지λ₯Ό λ„μš΄λ‹€', () => {
carNameInputAndSubmit(carNamesSample);
tryCountInputAndSubmit(tryCountSample);
cy.wait(2000);
catchAlertMessage(ALERT.CONGRATULATION);
});
});

describe('4. κ²Œμž„ μž¬μ‹œμž‘ ν…ŒμŠ€νŠΈ', () => {
beforeEach(() => {
cy.visit('http://localhost:5500');
});

it('λ‹€μ‹œ μ‹œμž‘ν•˜κΈ° λ²„νŠΌμ„ ν΄λ¦­ν•˜λ©΄, 진행 μ„Ήμ…˜κ³Ό κ²°κ³Ό μ„Ήμ…˜μ΄ 사라지고, μžλ™μ°¨ 이름 μž…λ ₯칸이 빈 μƒνƒœλ‘œ κ²Œμž„ μ‹œμž‘ λŒ€κΈ°μƒνƒœκ°€ λœλ‹€', () => {
carNameInputAndSubmit(carNamesSample);
tryCountInputAndSubmit(tryCountSample);
cy.wait(tryCountSample * DELAY.GAME_TURN + DELAY.GAME_END);
cy.get('#restart-button').click();
cy.get('#progress-section').should('not.exist');
cy.get('#result-section').should('not.exist');
cy.get('#car-names-input').should('have.value', '');
});
});
22 changes: 22 additions & 0 deletions cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/// <reference types="cypress" />
// ***********************************************************
// This example plugins/index.js can be used to load plugins
//
// You can change the location of this file or turn off loading
// the plugins file with the 'pluginsFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/plugins-guide
// ***********************************************************

// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)

/**
* @type {Cypress.PluginConfig}
*/
// eslint-disable-next-line no-unused-vars
module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
}
25 changes: 25 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
20 changes: 20 additions & 0 deletions cypress/support/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/index.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'

// Alternatively you can use CommonJS syntax:
// require('./commands')
31 changes: 31 additions & 0 deletions dist/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const DELAY = {
// millisecond(s)
GAME_TURN: 1000,
GAME_END: 2000,
};
const RULE = {
// random(0~9) 값이 4 이상일 경우 전진, 3 μ΄ν•˜μ˜ 값이면 μ „μ§„ν•˜μ§€ μ•ŠμŒ
MIN_SCORE: 0,
MAX_SCORE: 9,
THRESHOULD_SCORE: 4,
// μžλ™μ°¨ 이름은 5자 μ΄ν•˜λ§Œ κ°€λŠ₯
MAX_CARNAME_LENGTH: 5,
// μ‹œλ„ νšŸμˆ˜λŠ” μ›ν™œν•œ κ²Œμž„μ„ μœ„ν•΄ 자체적으둜 μ œν•œ
MIN_TRYCOUNT: 1,
MAX_TRYCOUNT: 50,
};
const ALERT = {
// for check valid car name
CARNAME_NOTHING: 'μžλ™μ°¨ 이름을 μž…λ ₯ν•΄μ£Όμ„Έμš”',
CARNAME_ALONE: 'μžλ™μ°¨ 이름을 2개 이상 μž…λ ₯ν•΄μ£Όμ„Έμš”',
CARNAME_EMPTY: 'λΉ„μ–΄ μžˆλŠ” μžλ™μ°¨ 이름이 μžˆμŠ΅λ‹ˆλ‹€',
CARNAME_DOUBLE: 'μ€‘λ³΅λœ μžλ™μ°¨ 이름이 μžˆμŠ΅λ‹ˆλ‹€',
CARNAME_LENGTH: 'μžλ™μ°¨ 이름 κΈ€μžμˆ˜κ°€ μ΄ˆκ³Όλ˜μ—ˆμŠ΅λ‹ˆλ‹€ (5자 이내)',
// for check valid try count
TRYCOUNT_NOTHING: 'μ‹œλ„ 횟수λ₯Ό μž…λ ₯ν•΄μ£Όμ„Έμš”',
TRYCOUNT_UINT: 'μ‹œλ„ νšŸμˆ˜λŠ” μ–‘μ˜ μ •μˆ˜λ₯Ό μž…λ ₯ν•΄μ£Όμ„Έμš” (50 μ΄ν•˜)',
TRYCOUNT_TOO_BIG: 'μ‹œλ„ νšŸμˆ˜κ°€ λ„ˆλ¬΄ λ§ŽμŠ΅λ‹ˆλ‹€ (50 μ΄ν•˜)',
// etc.
CONGRATULATION: 'λ‹˜ μš°μŠΉμ„ μΆ•ν•˜ν•©λ‹ˆλ‹€ πŸ‘',
};
export { DELAY, RULE, ALERT };
36 changes: 36 additions & 0 deletions dist/controller/gameController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import { ALERT, DELAY } from '../constants.js';
import { $ } from '../utils.js';
import { Game } from '../model/Game.js';
import { enableButton } from '../view/utils.js';
import { renderArrowDiv, removeSpinnerDivs } from '../view/progressSectionRenderer.js';
import { renderResultSection } from '../view/resultSectionRenderer.js';
import { addRestartButtonEvent } from './restartController.js';
const playOnce = (racingGame) => {
racingGame.play();
racingGame.roundWinners.forEach((index) => {
renderArrowDiv(index);
});
racingGame.initRoundWinners();
};
const startGame = (inputData) => __awaiter(void 0, void 0, void 0, function* () {
const racingGame = new Game(inputData.carNameArray);
for (let index = 0; index < inputData.tryCount; index += 1) {
yield racingGame.makeDelay(DELAY.GAME_TURN).then(() => playOnce(racingGame));
}
racingGame.judgeFinalWinners();
removeSpinnerDivs();
renderResultSection(racingGame.finalWinners.join(', ').toLowerCase());
yield racingGame.makeDelay(DELAY.GAME_END).then(() => alert(racingGame.finalWinners.join(', ') + ALERT.CONGRATULATION));
enableButton($('#restart-button'));
addRestartButtonEvent();
});
export { startGame };
39 changes: 39 additions & 0 deletions dist/controller/inputController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { $ } from '../utils.js';
import { startGame } from './gameController.js';
import { InputData } from '../model/InputData.js';
import { renderProgressSection } from '../view/progressSectionRenderer.js';
import { clearInput, enableInput, disableInput, enableButton, disableButton } from '../view/utils.js';
const getCarNames = (inputData) => {
const carNameInput = $('#car-names-input');
const carNameArray = carNameInput === null || carNameInput === void 0 ? void 0 : carNameInput.value.split(',').map((x) => x.trim());
if (inputData.checkCarNames(carNameInput, carNameArray)) {
renderProgressSection(carNameArray);
inputData.carNameArray = carNameArray;
disableInput(carNameInput);
disableButton($('#car-names-submit'));
enableInput($('#racing-count-input'));
enableButton($('#racing-count-submit'));
$('#racing-count-input').focus();
return;
}
clearInput(carNameInput);
};
const getTryCount = (inputData) => {
const tryCountInput = $('#racing-count-input');
const tryCount = Number(tryCountInput === null || tryCountInput === void 0 ? void 0 : tryCountInput.value);
if (inputData.checkTryCount(tryCountInput)) {
inputData.tryCount = tryCount;
disableInput(tryCountInput);
disableButton($('#racing-count-submit'));
startGame(inputData);
return;
}
clearInput(tryCountInput);
};
const addInputButtonsEvent = () => {
var _a, _b;
const inputData = new InputData();
(_a = $('#car-names-submit')) === null || _a === void 0 ? void 0 : _a.addEventListener('click', () => getCarNames(inputData));
(_b = $('#racing-count-submit')) === null || _b === void 0 ? void 0 : _b.addEventListener('click', () => getTryCount(inputData));
};
export { addInputButtonsEvent };
14 changes: 14 additions & 0 deletions dist/controller/restartController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { $ } from '../utils.js';
import { removeChildNodes } from '../view/utils.js';
import { renderInputSection } from '../view/inputSectionRenderer.js';
const init = () => {
removeChildNodes($('#app'));
renderInputSection();
addRestartButtonEvent();
$('#car-names-input').focus();
};
const addRestartButtonEvent = () => {
var _a;
(_a = $('#restart-button')) === null || _a === void 0 ? void 0 : _a.addEventListener('click', () => init());
};
export { addRestartButtonEvent };
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { renderInputSection } from './view/inputSectionRenderer.js';
import { addInputButtonsEvent } from './controller/inputController.js';
const app = () => {
renderInputSection();
addInputButtonsEvent();
};
app();
Loading