diff --git a/README.md b/README.md index 003db037a..cc3750060 100644 --- a/README.md +++ b/README.md @@ -1,76 +1,75 @@ -# java-blackjack - -## ๐Ÿš€ ๊ธฐ๋Šฅ ์š”๊ตฌ ์‚ฌํ•ญ - -## โœ… 1๋‹จ๊ณ„ - ๋ธ”๋ž™์žญ ๊ตฌํ˜„ - -๋ธ”๋ž™์žญ ๊ฒŒ์ž„์„ ๋ณ€ํ˜•ํ•œ ํ”„๋กœ๊ทธ๋žจ์„ ๊ตฌํ˜„ํ•œ๋‹ค. ๋ธ”๋ž™์žญ ๊ฒŒ์ž„์€ ๋”œ๋Ÿฌ์™€ ํ”Œ๋ ˆ์ด์–ด ์ค‘ ์นด๋“œ์˜ ํ•ฉ์ด 21 ๋˜๋Š” 21์— ๊ฐ€์žฅ ๊ฐ€๊นŒ์šด ์ˆซ์ž๋ฅผ ๊ฐ€์ง€๋Š” ์ชฝ์ด ์ด๊ธฐ๋Š” ๊ฒŒ์ž„์ด๋‹ค. - -์นด๋“œ์˜ ์ˆซ์ž ๊ณ„์‚ฐ์€ ์นด๋“œ ์ˆซ์ž๋ฅผ ๊ธฐ๋ณธ์œผ๋กœ ํ•˜๋ฉฐ, ์˜ˆ์™ธ๋กœ Ace๋Š” 1 ๋˜๋Š” 11๋กœ ๊ณ„์‚ฐํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ, King, Queen, Jack์€ ๊ฐ๊ฐ 10์œผ๋กœ ๊ณ„์‚ฐํ•œ๋‹ค. -๊ฒŒ์ž„์„ ์‹œ์ž‘ํ•˜๋ฉด ํ”Œ๋ ˆ์ด์–ด๋Š” ๋‘ ์žฅ์˜ ์นด๋“œ๋ฅผ ์ง€๊ธ‰ ๋ฐ›์œผ๋ฉฐ, ๋‘ ์žฅ์˜ ์นด๋“œ ์ˆซ์ž๋ฅผ ํ•ฉ์ณ 21์„ ์ดˆ๊ณผํ•˜์ง€ ์•Š์œผ๋ฉด์„œ 21์— ๊ฐ€๊น๊ฒŒ ๋งŒ๋“ค๋ฉด ์ด๊ธด๋‹ค. 21์„ ๋„˜์ง€ ์•Š์„ ๊ฒฝ์šฐ ์›ํ•œ๋‹ค๋ฉด ์–ผ๋งˆ๋“ ์ง€ ์นด๋“œ๋ฅผ ๊ณ„์† ๋ฝ‘์„ ์ˆ˜ ์žˆ๋‹ค. -๋”œ๋Ÿฌ๋Š” ์ฒ˜์Œ์— ๋ฐ›์€ 2์žฅ์˜ ํ•ฉ๊ณ„๊ฐ€ 16์ดํ•˜์ด๋ฉด ๋ฐ˜๋“œ์‹œ 1์žฅ์˜ ์นด๋“œ๋ฅผ ์ถ”๊ฐ€๋กœ ๋ฐ›์•„์•ผ ํ•˜๊ณ , 17์  ์ด์ƒ์ด๋ฉด ์ถ”๊ฐ€๋กœ ๋ฐ›์„ ์ˆ˜ ์—†๋‹ค. -๊ฒŒ์ž„์„ ์™„๋ฃŒํ•œ ํ›„ ๊ฐ ํ”Œ๋ ˆ์ด์–ด๋ณ„๋กœ ์ŠนํŒจ๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค. - -## ๐Ÿ’ป ์‹คํ–‰ ๊ฒฐ๊ณผ -``` -๊ฒŒ์ž„์— ์ฐธ์—ฌํ•  ์‚ฌ๋žŒ์˜ ์ด๋ฆ„์„ ์ž…๋ ฅํ•˜์„ธ์š”.(์‰ผํ‘œ ๊ธฐ์ค€์œผ๋กœ ๋ถ„๋ฆฌ) -pobi,jason - -๋”œ๋Ÿฌ์™€ pobi, jason์—๊ฒŒ 2์žฅ์„ ๋‚˜๋ˆ„์—ˆ์Šต๋‹ˆ๋‹ค. -๋”œ๋Ÿฌ: 3๋‹ค์ด์•„๋ชฌ๋“œ -pobi์นด๋“œ: 2ํ•˜ํŠธ, 8์ŠคํŽ˜์ด๋“œ -jason์นด๋“œ: 7ํด๋กœ๋ฒ„, K์ŠคํŽ˜์ด๋“œ - -pobi๋Š” ํ•œ์žฅ์˜ ์นด๋“œ๋ฅผ ๋” ๋ฐ›๊ฒ ์Šต๋‹ˆ๊นŒ?(์˜ˆ๋Š” y, ์•„๋‹ˆ์˜ค๋Š” n) -y -pobi์นด๋“œ: 2ํ•˜ํŠธ, 8์ŠคํŽ˜์ด๋“œ, Aํด๋กœ๋ฒ„ -pobi๋Š” ํ•œ์žฅ์˜ ์นด๋“œ๋ฅผ ๋” ๋ฐ›๊ฒ ์Šต๋‹ˆ๊นŒ?(์˜ˆ๋Š” y, ์•„๋‹ˆ์˜ค๋Š” n) -n -pobi์นด๋“œ: 2ํ•˜ํŠธ, 8์ŠคํŽ˜์ด๋“œ, Aํด๋กœ๋ฒ„ -jason์€ ํ•œ์žฅ์˜ ์นด๋“œ๋ฅผ ๋” ๋ฐ›๊ฒ ์Šต๋‹ˆ๊นŒ?(์˜ˆ๋Š” y, ์•„๋‹ˆ์˜ค๋Š” n) -n -jason์นด๋“œ: 7ํด๋กœ๋ฒ„, K์ŠคํŽ˜์ด๋“œ - -๋”œ๋Ÿฌ๋Š” 16์ดํ•˜๋ผ ํ•œ์žฅ์˜ ์นด๋“œ๋ฅผ ๋” ๋ฐ›์•˜์Šต๋‹ˆ๋‹ค. - -๋”œ๋Ÿฌ ์นด๋“œ: 3๋‹ค์ด์•„๋ชฌ๋“œ, 9ํด๋กœ๋ฒ„, 8๋‹ค์ด์•„๋ชฌ๋“œ - ๊ฒฐ๊ณผ: 20 -pobi์นด๋“œ: 2ํ•˜ํŠธ, 8์ŠคํŽ˜์ด๋“œ, Aํด๋กœ๋ฒ„ - ๊ฒฐ๊ณผ: 21 -jason์นด๋“œ: 7ํด๋กœ๋ฒ„, K์ŠคํŽ˜์ด๋“œ - ๊ฒฐ๊ณผ: 17 - -## ์ตœ์ข… ์ŠนํŒจ -๋”œ๋Ÿฌ: 1์Šน 1ํŒจ -pobi: ์Šน -jason: ํŒจ -``` - -## โœ… 2๋‹จ๊ณ„ - ๋ธ”๋ž™์žญ ๊ตฌํ˜„ - -- 1๋‹จ๊ณ„ ๋ฏธ์…˜์ด ์–ด๋Š์ •๋„ ๊ตฌํ˜„๋œ ํ›„์— ๊ณต๊ฐœํ•  ์˜ˆ์ • - -## ๐Ÿ–ฅ๏ธ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์š”๊ตฌ ์‚ฌํ•ญ -- indent(์ธ๋ดํŠธ, ๋“ค์—ฌ์“ฐ๊ธฐ) depth๋ฅผ 3๋ฅผ ๋„˜์ง€ ์•Š๋„๋ก ๊ตฌํ˜„ํ•œ๋‹ค. 2๊นŒ์ง€๋งŒ ํ—ˆ์šฉํ•œ๋‹ค. ( ๊ฐœ์ธ์˜ ์—ญ๋Ÿ‰์— ๋งž์ถฐ 1๊นŒ์ง€ ํ—ˆ์šฉํ•˜์—ฌ ์ง„ํ–‰ํ•ด๋ณผ ๊ฒƒ์„ ์ถ”์ฒœ ) - - ์˜ˆ๋ฅผ ๋“ค์–ด while๋ฌธ ์•ˆ์— if๋ฌธ์ด ์žˆ์œผ๋ฉด ๋“ค์—ฌ์“ฐ๊ธฐ๋Š” 2์ด๋‹ค. - - ํžŒํŠธ: indent(์ธ๋ดํŠธ, ๋“ค์—ฌ์“ฐ๊ธฐ) depth๋ฅผ ์ค„์ด๋Š” ์ข‹์€ ๋ฐฉ๋ฒ•์€ ํ•จ์ˆ˜(๋˜๋Š” ๋ฉ”์„œ๋“œ)๋ฅผ ๋ถ„๋ฆฌํ•˜๋ฉด ๋œ๋‹ค. -- 3ํ•ญ ์—ฐ์‚ฐ์ž๋ฅผ ์“ฐ์ง€ ์•Š๋Š”๋‹ค. -- else ์˜ˆ์•ฝ์–ด๋ฅผ ์“ฐ์ง€ ์•Š๋Š”๋‹ค. - - else ์˜ˆ์•ฝ์–ด๋ฅผ ์“ฐ์ง€ ๋ง๋ผ๊ณ  ํ•˜๋‹ˆ switch/case๋กœ ๊ตฌํ˜„ํ•˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ๋Š”๋ฐ switch/case๋„ ํ—ˆ์šฉํ•˜์ง€ ์•Š๋Š”๋‹ค. - - ํžŒํŠธ: if๋ฌธ์—์„œ ๊ฐ’์„ ๋ฐ˜ํ™˜ํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ๊ตฌํ˜„ํ•˜๋ฉด else ์˜ˆ์•ฝ์–ด๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š์•„๋„ ๋œ๋‹ค. -- ํ•ต์‹ฌ ๋กœ์ง์„ ๊ตฌํ˜„ํ•˜๋Š” ์ฝ”๋“œ์™€ UI๋ฅผ ๋‹ด๋‹นํ•˜๋Š” ๋กœ์ง์„ ๊ตฌ๋ถ„ํ•œ๋‹ค. - - UI ๋กœ์ง์„ InputView, ResultView์™€ ๊ฐ™์€ ํด๋ž˜์Šค๋ฅผ ์ถ”๊ฐ€ํ•ด ๋ถ„๋ฆฌํ•œ๋‹ค. -- ํ•จ์ˆ˜(๋˜๋Š” ๋ฉ”์„œ๋“œ)์˜ ๊ธธ์ด๊ฐ€ 10๋ผ์ธ์„ ๋„˜์–ด๊ฐ€์ง€ ์•Š๋„๋ก ๊ตฌํ˜„ํ•œ๋‹ค. -- ํ•จ์ˆ˜(๋˜๋Š” ๋ฉ”์†Œ๋“œ)๊ฐ€ ํ•œ ๊ฐ€์ง€ ์ผ๋งŒ ํ•˜๋„๋ก ์ตœ๋Œ€ํ•œ ์ž‘๊ฒŒ ๋งŒ๋“ค์–ด๋ผ. - -## ๐Ÿ”ฅ ์ถ”๊ฐ€๋œ ์š”๊ตฌ ์‚ฌํ•ญ -- Java 11 ์œผ๋กœ ๋ณ€๊ฒฝํ•œ๋‹ค. -- ๋ชจ๋“  ์›์‹œ ๊ฐ’๊ณผ ๋ฌธ์ž์—ด์„ ํฌ์žฅํ•œ๋‹ค [์ฐธ๊ณ  ๊ธ€](https://tecoble.techcourse.co.kr/post/2020-05-29-wrap-primitive-type/) -- ๊ตฌํ˜„ํ•œ ๊ธฐ๋Šฅ์— Test๋ฅผ ์ถ”๊ฐ€ํ•œ๋‹ค. ๋‹จ, UI(System.out, System.in) ๋กœ์ง์€ ์ œ์™ธ -- ๋ฐฐ์—ด ๋Œ€์‹  ์ปฌ๋ ‰์…˜์„ ์‚ฌ์šฉํ•œ๋‹ค. -- 3๊ฐœ ์ด์ƒ์˜ ์ธ์Šคํ„ด์Šค ๋ณ€์ˆ˜๋ฅผ ๊ฐ€์ง„ ํด๋ž˜์Šค๋ฅผ ์“ฐ์ง€ ์•Š๋Š”๋‹ค. -- ๋”œ๋Ÿฌ์™€ ํ”Œ๋ ˆ์ด์–ด์—์„œ ๋ฐœ์ƒํ•˜๋Š” ์ค‘๋ณต ์ฝ”๋“œ๋ฅผ ์ œ๊ฑฐํ•ด์•ผ ํ•œ๋‹ค. -- ์ผ๊ธ‰ ์ปฌ๋ ‰์…˜์„ ์“ด๋‹ค. [์ฐธ๊ณ  ๊ธ€](https://jojoldu.tistory.com/412) - -## ๐Ÿ“š ๊ณผ์ œ ์ง„ํ–‰ ์š”๊ตฌ ์‚ฌํ•ญ -- ๋ฏธ์…˜์€ ํ•ด๋‹น ์ €์žฅ์†Œ๋ฅผ Fork/Cloneํ•จ์œผ๋กœ๋ถ€ํ„ฐ ์‹œ์ž‘๋œ๋‹ค. -- ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•˜๊ธฐ ์ „์— java-baseball/docs/README.md ํŒŒ์ผ์— ๊ตฌํ˜„ํ•  ๊ธฐ๋Šฅ ๋ชฉ๋ก์„ ์ •๋ฆฌํ•ด ์ถ”๊ฐ€ํ•œ๋‹ค. -- Git์˜ ์ปค๋ฐ‹ ๋‹จ์œ„๋Š” ์•ž ๋‹จ๊ณ„์—์„œ README.md ํŒŒ์ผ์— ์ •๋ฆฌํ•œ ๊ธฐ๋Šฅ ๋ชฉ๋ก ๋‹จ์œ„๋กœ ์ถ”๊ฐ€ํ•œ๋‹ค. -- ์ปค๋ฐ‹ ๋ฉ”์‹œ์ง€ [์ปจ๋ฒค์…˜ ๊ฐ€์ด๋“œ](https://gist.github.com/stephenparish/9941e89d80e2bc58a153)๋ฅผ ์ฐธ๊ณ ํ•ด ์ปค๋ฐ‹ ๋ฉ”์‹œ์ง€๋ฅผ ์ž‘์„ฑํ•œ๋‹ค. +# ๊ธฐ๋Šฅ ๋ชฉ๋ก + +
+ +## view + +- [x] ์ž…๋ ฅ + - [x] ํ”Œ๋ ˆ์ด์–ด ๋ชฉ๋ก ์ž…๋ ฅ + - [x] ํ”Œ๋ ˆ์ด์–ด๊ฐ€ ์นด๋“œ๋ฅผ ๋ฐ›์„์ง€ ์—ฌ๋ถ€(y/n) ์ž…๋ ฅ + - [x] y ๋˜๋Š” n์ธ์ง€ ๊ฒ€์ฆ + +- [x] ์ถœ๋ ฅ + - [x] ํ”Œ๋ ˆ์ด์–ด ์ด๋ฆ„ ์ž…๋ ฅํ•˜๊ธฐ ๋ฌธ๊ตฌ + - [x] ๊ฒŒ์ž„ ์‹œ์ž‘ ์‹œ ์นด๋“œ 2์žฅ ๋ฐฐ๋ถ„์— ๋Œ€ํ•œ ๋ฌธ๊ตฌ + - [x] ์ฐธ์—ฌ์ž ์นด๋“œ ๋ฆฌ์ŠคํŠธ ๋‚ด์˜ ์นด๋“œ ์ถœ๋ ฅ (jason์นด๋“œ: 7ํด๋กœ๋ฒ„, K์ŠคํŽ˜์ด๋“œ) + - [x] ํ”Œ๋ ˆ์ด์–ด๊ฐ€ ์นด๋“œ๋ฅผ ๋ฐ›์„์ง€ ์—ฌ๋ถ€(y/n) ๋ฌป๋Š” ๋ฌธ๊ตฌ + - [x] ๋”œ๋Ÿฌ ์นด๋“œ ์ถ”๊ฐ€์ ์œผ๋กœ ๋ฐ›์•˜์„ ๋•Œ ๋ฌธ๊ตฌ + - [x] ์นด๋“œ ์ ์ˆ˜ ๊ณ„์‚ฐ ๊ฒฐ๊ณผ ์ถœ๋ ฅ + - [x] ์ตœ์ข… ์ŠนํŒจ ๊ฒฐ๊ณผ ์ถœ๋ ฅ + +
+ +## domain + +### participant + +- [x] ์ฐธ๊ฐ€์ž(ํด๋ž˜์Šค) + - [x] ์ ์ˆ˜ ๋ฐ˜ํ™˜ ๊ธฐ๋Šฅ +- [x] ํ”Œ๋ ˆ์ด์–ด(์ฐธ๊ฐ€์ž ์ƒ์†) + +- [x] ๋”œ๋Ÿฌ(์ฐธ๊ฐ€์ž ์ƒ์†) + +- [x] ์ด๋ฆ„: ์ฐธ๊ฐ€์ž์˜ ํ•„๋“œ + +- [x] ํ”Œ๋ ˆ์ด์–ด ๋ฆฌ์ŠคํŠธ + +- [x] ์นด๋“œ ๋ฆฌ์ŠคํŠธ: ๋”œ๋Ÿฌ์™€ ํ”Œ๋ ˆ์ด์–ด๊ฐ€ ๋ฐฐ๋ถ„ ๋ฐ›์€ ์นด๋“œ๋“ค ๋‹ด๋Š” ๋ฆฌ์ŠคํŠธ + - [x] ์ ์ˆ˜ ๊ณ„์‚ฐ ๊ธฐ๋Šฅ + +### carddeck + +- [x] ์นด๋“œ ์‹ฌ๋ณผ(ํ•˜ํŠธ~์ŠคํŽ˜์ด๋“œ) + +- [x] ์นด๋“œ ๋žญํฌ(๋žญํฌ(์—์ด์Šค~์žญ,ํ€ธ,ํ‚น)์™€ ์ˆซ์ž ๊ฐ’) + +- [x] ์นด๋“œ: ์‹ฌ๋ณผ(ํ•˜ํŠธ, ์ŠคํŽ˜์ด๋“œ, ๋‹ค์ด์•„๋ชฌ๋“œ, ํด๋กœ๋ฒ„)๊ณผ ๋žญํฌ(์—์ด์Šค~ํ‚น) ์กฐํ•ฉ์œผ๋กœ ์ด๋ฃจ์–ด์ง„ ์นด๋“œ + +- [x] ์นด๋“œ๋ฑ: 52๊ฐ€์ง€ ์นด๋“œ ๋‹ด๊ณ  ์žˆ๋Š” ํ•˜๋‚˜์˜ ์นด๋“œ๋ฑ + - [x] ์นด๋“œ๋ฑ์—์„œ ์นด๋“œ ์ถ”์ถœํ•˜์—ฌ ๋ฐ˜ํ™˜ + +### constants + +- [x] ์ƒ์ˆ˜ + +- [x] ์ŠนํŒจ ๊ฒฐ๊ณผ ์ƒ์ˆ˜ + + +### ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง + +- [x] ๋ธ”๋ž™์žญ: ์นด๋“œ๋ฑ ์ƒ์„ฑ, ์ฐธ๊ฐ€์ž์— ์นด๋“œ ๋ฐฐ๋ถ„ + +- [x] ์นด๋“œ ์ ์ˆ˜ ๊ณ„์‚ฐ + +- [x] ๋”œ๋Ÿฌ ์Šน๋ฆฌ ์ฑ„ํฌ + +
+ +## controller + +- [x] ๊ฒŒ์ž„ ๋งค๋‹ˆ์ € + - [x] ๊ฒŒ์ž„ ์‹œ์ž‘ + - [x] ์ฐธ๊ฐ€์ž ์ƒ์„ฑ + - [x] ๋ธ”๋ž™์žญ ๊ฒŒ์ž„ ์‹œ์ž‘ + - [x] ์ ์ˆ˜ ๊ณ„์‚ฐ ๊ฒฐ๊ณผ ์ถœ๋ ฅ + - [x] ์ตœ์ข… ์ŠนํŒจ ๊ฒฐ๊ณผ ์ถœ๋ ฅ \ No newline at end of file diff --git a/md b/md new file mode 100644 index 000000000..e69de29bb diff --git a/src/main/java/Application.java b/src/main/java/Application.java new file mode 100644 index 000000000..b0b0391f1 --- /dev/null +++ b/src/main/java/Application.java @@ -0,0 +1,9 @@ +import controller.GameManager; + +public class Application { + + public static void main(String[] args) { + GameManager gameManager = new GameManager(); + gameManager.gameStart(); + } +} diff --git a/src/main/java/carddeck/Card.java b/src/main/java/carddeck/Card.java new file mode 100644 index 000000000..f468f9e32 --- /dev/null +++ b/src/main/java/carddeck/Card.java @@ -0,0 +1,25 @@ +package carddeck; + +public class Card { + + private final CardSuit cardSuit; + private final CardRank cardRank; + + public Card(CardSuit cardSuit, CardRank cardRank) { + this.cardSuit = cardSuit; + this.cardRank = cardRank; + } + + @Override + public String toString() { + return this.cardRank.getRank() + this.cardSuit.getValue(); + } + + public CardSuit getCardSuit() { + return this.cardSuit; + } + + public CardRank getCardRank() { + return this.cardRank; + } +} diff --git a/src/main/java/carddeck/CardDeck.java b/src/main/java/carddeck/CardDeck.java new file mode 100644 index 000000000..06ab436bd --- /dev/null +++ b/src/main/java/carddeck/CardDeck.java @@ -0,0 +1,42 @@ +package carddeck; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class CardDeck { + + private List cardDeck; + + public CardDeck() { + initializeCardDeck(); + shuffleCardDeck(); + } + + private void initializeCardDeck() { + CardSuit[] suits = CardSuit.values(); + CardRank[] ranks = CardRank.values(); + + this.cardDeck = new ArrayList(); + + for (CardSuit suit : suits) { + for (CardRank rank : ranks) { + Card card = new Card(suit, rank); + this.cardDeck.add(card); + } + } + } + + private void shuffleCardDeck() { + Collections.shuffle(this.cardDeck); + } + + public Card drawCard() { + if (this.cardDeck.isEmpty()) { + throw new IllegalArgumentException("์นด๋“œ๋ฑ์ด ๋น„์–ด ์žˆ์Šต๋‹ˆ๋‹ค."); + } + + return this.cardDeck.remove(0); + } + +} diff --git a/src/main/java/carddeck/CardRank.java b/src/main/java/carddeck/CardRank.java new file mode 100644 index 000000000..a0e9fac72 --- /dev/null +++ b/src/main/java/carddeck/CardRank.java @@ -0,0 +1,25 @@ +package carddeck; + +public enum CardRank { + + ACE("A", 1), TWO("2", 2), THREE("3", 3), FOUR("4", 4), FIVE("5", 5), + SIX("6", 6), SEVEN("7", 7), EIGHT("8", 8), NINE("9", 9), TEN("10", 10), + JACK("J", 10), QUEEN("Q", 10), KING("K", 10); + + private final String rank; + private final int value; + + CardRank(String rank, int value) { + this.rank = rank; + this.value = value; + } + + public String getRank() { + return rank; + } + + public int getValue() { + return value; + } + +} diff --git a/src/main/java/carddeck/CardSuit.java b/src/main/java/carddeck/CardSuit.java new file mode 100644 index 000000000..a5b43dbec --- /dev/null +++ b/src/main/java/carddeck/CardSuit.java @@ -0,0 +1,16 @@ +package carddeck; + +public enum CardSuit { + HEARTS("ํ•˜ํŠธ"), DIAMONDS("๋‹ค์ด์•„๋ชฌ๋“œ"), CLUBS("ํด๋กœ๋ฒ„"), SPADES("์ŠคํŽ˜์ด๋“œ"); + + private final String value; + + CardSuit(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + +} diff --git a/src/main/java/constants/Constant.java b/src/main/java/constants/Constant.java new file mode 100644 index 000000000..09d18ba76 --- /dev/null +++ b/src/main/java/constants/Constant.java @@ -0,0 +1,8 @@ +package constants; + +public class Constant { + + public static final String YES = "y"; + public static final String NO = "n"; + +} diff --git a/src/main/java/constants/Result.java b/src/main/java/constants/Result.java new file mode 100644 index 000000000..1b5c21503 --- /dev/null +++ b/src/main/java/constants/Result.java @@ -0,0 +1,18 @@ +package constants; + +public enum Result { + PLAYER_WIN("์Šน"), + PLAYER_LOSE("ํŒจ"), + BUST("ํŒจ"), + PUSH("๋ฌด์Šน๋ถ€"); + + private final String value; + + Result(String value) { + this.value = value; + } + + public String getValue() { + return this.value; + } +} diff --git a/src/main/java/controller/GameManager.java b/src/main/java/controller/GameManager.java new file mode 100644 index 000000000..27607ff1d --- /dev/null +++ b/src/main/java/controller/GameManager.java @@ -0,0 +1,132 @@ +package controller; + +import constants.Constant; +import constants.Result; +import domain.BlackJack; +import domain.DealerWinChecker; +import participant.*; +import view.InputView; +import view.OutputView; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +public class GameManager { + + private InputView inputView; + private OutputView outputView; + private BlackJack blackJack; + + public GameManager() { + this.inputView = new InputView(); + this.outputView = new OutputView(); + } + + public void gameStart() { + List participants = getParticipants(); + Dealer dealer = getDealer(participants); + + this.blackJack = new BlackJack(participants); + for (Participant participant : participants) { + outputView.printParticipantCardList(participant); + } + + outputView.printEmptyLine(); + + for (Participant participant : participants) { + if (!participant.isDealer()) { + askForAdditionCard(participant); + } + } + + outputView.printEmptyLine(); + + if (blackJack.isDealerAboveThreshold(dealer)) { + blackJack.distributeCard(dealer); + outputView.printDealerGetOneMoreCard(); + } + + for (Participant participant : participants) { + int score = participant.getScore(); + outputView.printScore(participant, score); + } + + outputView.printEmptyLine(); + + DealerWinChecker dealerWinChecker = new DealerWinChecker(dealer); + HashMap playerResult = new HashMap<>(); + for (Participant participant : participants) { + if (!participant.isDealer()) { + Result result = dealerWinChecker.checkDealerWin((Player) participant); + playerResult.put(participant.getName(), result.getValue()); + } + } + + List dealerResult = new ArrayList(); + dealerResult.add(dealerWinChecker.getWinNum()); + dealerResult.add(dealerWinChecker.getLoseNum()); + dealerResult.add(dealerWinChecker.getPushNum()); + + outputView.printFinalResult(dealerResult, playerResult); + + } + + private List getParticipants() { + List playerList = getPlayerList(); + + List participants = new ArrayList(); + Dealer dealer = new Dealer(); + participants.add(dealer); + for (Player player : playerList) { + participants.add((Participant) player); + } + + List playerNameList = new ArrayList(); + for (Player player : playerList) { + playerNameList.add(player.getName()); + } + outputView.printInitialCardDistributionMessage(playerNameList); + return participants; + } + + private Dealer getDealer(List participants) { + for (Participant participant : participants) { + if (participant.isDealer()) { + return (Dealer) participant; + } + } + return null; + } + + private List getPlayerList() { + try { + outputView.printInputPlayerNameMessage(); + List nameList = inputView.inputPlayerName(); + PlayerList playerList = new PlayerList(nameList); + return playerList.getPlayerList(); + } catch (IllegalArgumentException e) { + System.out.println(e.getMessage()); + return getPlayerList(); + } + } + + private void askForAdditionCard(Participant participant) { + String name = participant.getName(); + try { + outputView.printAskForAdditionalCard(name); + String answer = inputView.askForAdditionalCard(); + if (answer.equals(Constant.YES)) { + this.blackJack.distributeCard(participant); + outputView.printParticipantCardList(participant); + askForAdditionCard(participant); + } + if (answer.equals(Constant.NO)) { + outputView.printParticipantCardList(participant); + } + } catch (IllegalArgumentException e) { + System.out.println("[ERROR] " + e.getMessage()); + askForAdditionCard(participant); + } + } +} diff --git a/src/main/java/domain/BlackJack.java b/src/main/java/domain/BlackJack.java new file mode 100644 index 000000000..d9a7ad2e4 --- /dev/null +++ b/src/main/java/domain/BlackJack.java @@ -0,0 +1,49 @@ +package domain; + +import carddeck.Card; +import carddeck.CardDeck; +import participant.Dealer; +import participant.Participant; + +import java.util.List; + +public class BlackJack { + + private final int INITIAL_CARD_DISTRIBUTION_COUNT = 2; + public final int DEALER_THRESHOLD = 16; + + private List participants; + private CardDeck cardDeck; + + public BlackJack(List participants) { + this.participants = participants; + this.cardDeck = new CardDeck(); + initialCardDistribution(); + } + + private void initialCardDistribution() { + for (Participant participant : participants) { + for (int i = 0; i < INITIAL_CARD_DISTRIBUTION_COUNT; i++) { + distributeCard(participant); + } + } + } + + public void distributeCard(Participant participant) { + try { + Card card = this.cardDeck.drawCard(); + participant.receiveCard(card); + } catch (IllegalArgumentException e) { + System.out.println("[ERROR] " + e.getMessage()); + } + } + + public boolean isDealerAboveThreshold(Dealer dealer) { + int score = dealer.getScore(); + if (score <= DEALER_THRESHOLD) { + return true; + } + return false; + } + +} diff --git a/src/main/java/domain/DealerWinChecker.java b/src/main/java/domain/DealerWinChecker.java new file mode 100644 index 000000000..5a40f122d --- /dev/null +++ b/src/main/java/domain/DealerWinChecker.java @@ -0,0 +1,70 @@ +package domain; + +import constants.Constant; +import constants.Result; +import participant.Dealer; +import participant.Player; + +public class DealerWinChecker { + + private final int TARGET_SCORE = 21; + private int dealerScore; + private int winNum; + private int loseNum; + private int pushNum; + + public DealerWinChecker(Dealer dealer) { + this.dealerScore = dealer.getScore(); + this.winNum = 0; + this.loseNum = 0; + } + + public Result checkDealerWin(Player player) { + int playerScore = player.getScore(); + boolean dealerBust = checkBust(this.dealerScore); + boolean playerBust = checkBust(playerScore); + if (dealerBust && playerBust) { + this.loseNum += 1; + return Result.BUST; + } + if (!dealerBust) { + if (playerBust || (this.dealerScore > playerScore)) { + this.winNum += 1; + return Result.PLAYER_LOSE; + } + } + if(!playerBust) { + if (dealerBust || (playerScore > this.dealerScore)) { + this.loseNum += 1; + return Result.PLAYER_WIN; + } + } + if (!(dealerBust && playerBust)) { + if (playerScore == this.dealerScore) { + pushNum += 1; + return Result.PUSH; + } + } + return null; + } + + private boolean checkBust(int score) { + if (score > TARGET_SCORE) { + return true; + } + return false; + } + + public int getWinNum() { + return this.winNum; + } + + public int getLoseNum() { + return this.loseNum; + } + + public int getPushNum() { + return this.pushNum; + } + +} diff --git a/src/main/java/participant/CardList.java b/src/main/java/participant/CardList.java new file mode 100644 index 000000000..820cd22e2 --- /dev/null +++ b/src/main/java/participant/CardList.java @@ -0,0 +1,48 @@ +package participant; + +import carddeck.Card; +import carddeck.CardRank; + +import java.util.ArrayList; +import java.util.List; + +public class CardList { + + private List cardList; + + public CardList() { + this.cardList = new ArrayList(); + } + + public void addCard(Card card) { + this.cardList.add(card); + } + + public int calculateScore() { + int sum = 0; + int numOfAce = 0; + for (Card card : cardList) { + CardRank cardRank = card.getCardRank(); + if (cardRank.getRank().equals(CardRank.ACE.getRank())) { + numOfAce += 1; + } + sum += cardRank.getValue(); + } + sum = calculateAceValue(numOfAce, sum); + return sum; + } + + private int calculateAceValue(int numOfAce, int sum) { + for (int i = 0; i < numOfAce; i++) { + if (sum + 10 <= 21) { + sum += 10; + } + } + return sum; + } + + public List getCardList() { + return this.cardList; + } + +} diff --git a/src/main/java/participant/Dealer.java b/src/main/java/participant/Dealer.java new file mode 100644 index 000000000..2de5272ce --- /dev/null +++ b/src/main/java/participant/Dealer.java @@ -0,0 +1,14 @@ +package participant; + +public class Dealer extends Participant{ + + public Dealer() { + super(new Name("๋”œ๋Ÿฌ")); + } + + @Override + public boolean isDealer() { + return true; + } + +} diff --git a/src/main/java/participant/Name.java b/src/main/java/participant/Name.java new file mode 100644 index 000000000..2f63c6318 --- /dev/null +++ b/src/main/java/participant/Name.java @@ -0,0 +1,23 @@ +package participant; + +public class Name { + + private String name; + + public Name(String name) { + String trimmedName = name.trim(); + IsNameEmpty(name); + this.name = name; + } + + private void IsNameEmpty(String name) { + if (name.isEmpty() || name.isBlank()) { + throw new IllegalArgumentException("์ด๋ฆ„ ๋นˆ์นธ ๋ถˆ๊ฐ€"); + } + } + + public String getName() { + return this.name; + } + +} diff --git a/src/main/java/participant/Participant.java b/src/main/java/participant/Participant.java new file mode 100644 index 000000000..63b148574 --- /dev/null +++ b/src/main/java/participant/Participant.java @@ -0,0 +1,37 @@ +package participant; + +import carddeck.Card; + +import java.util.List; + +public class Participant { + + private Name name; + private CardList cardList; + + public Participant(Name name) { + this.name = name; + this.cardList = new CardList(); + } + + public boolean isDealer() { + return false; + } + + public void receiveCard(Card card) { + this.cardList.addCard(card); + } + + public String getName() { + return this.name.getName(); + } + + public int getScore() { + return this.cardList.calculateScore(); + } + + public List getCardList() { + return this.cardList.getCardList(); + } + +} diff --git a/src/main/java/participant/Player.java b/src/main/java/participant/Player.java new file mode 100644 index 000000000..78cb14882 --- /dev/null +++ b/src/main/java/participant/Player.java @@ -0,0 +1,12 @@ +package participant; + +public class Player extends Participant{ + public Player(Name name) { + super(name); + } + + @Override + public boolean isDealer() { + return false; + } +} diff --git a/src/main/java/participant/PlayerList.java b/src/main/java/participant/PlayerList.java new file mode 100644 index 000000000..ad1b342e4 --- /dev/null +++ b/src/main/java/participant/PlayerList.java @@ -0,0 +1,46 @@ +package participant; + +import java.util.ArrayList; +import java.util.List; + +public class PlayerList { + + private List playerList; + + public PlayerList(List playerNameList) { + List nameList = hasDuplicateNames(playerNameList); + this.playerList = generatePlayerList(nameList); + } + + private void IsNameEqualsDealer(String name) { + if (name.equals("๋”œ๋Ÿฌ")) { + throw new IllegalArgumentException("๋”œ๋Ÿฌ ์ด๋ฆ„ ์‚ฌ์šฉ ๋ถˆ๊ฐ€"); + } + } + + private List hasDuplicateNames(List playerNameList) { + List processedNameList = new ArrayList(); + for (String name : playerNameList) { + String trimmedName = name.trim(); + if (processedNameList.contains(trimmedName)) { + throw new IllegalArgumentException("์ด๋ฆ„ ์ค‘๋ณต"); + } + processedNameList.add(trimmedName); + } + return processedNameList; + } + + private List generatePlayerList(List processedNameList) { + List playerList = new ArrayList(); + for (String name : processedNameList) { + IsNameEqualsDealer(name); + playerList.add(new Player(new Name(name))); + } + return playerList; + } + + public List getPlayerList() { + return this.playerList; + } + +} diff --git a/src/main/java/view/InputView.java b/src/main/java/view/InputView.java new file mode 100644 index 000000000..2290d63ef --- /dev/null +++ b/src/main/java/view/InputView.java @@ -0,0 +1,43 @@ +package view; + +import constants.Constant; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Scanner; + +public class InputView { + + private Scanner sc; + + public InputView() { + this.sc = new Scanner(System.in); + } + + public List inputPlayerName() { + String playerNameStr = this.sc.nextLine(); + if (playerNameStr.isBlank()) { + throw new IllegalArgumentException("๊ฐ’์„ ์ž…๋ ฅํ•˜์‹œ์˜ค."); + } + List list = Arrays.asList(playerNameStr.split(",")); + List playerNameList = new ArrayList(); + for (String name : list) { + playerNameList.add(name.trim()); + } + return playerNameList; + } + + public String askForAdditionalCard() { + String answer = this.sc.nextLine(); + validateAnswer(answer); + return answer; + } + + private void validateAnswer(String value) { + if (!(value.equals(Constant.YES) || value.equals(Constant.NO))) { + throw new IllegalArgumentException("y ๋˜๋Š” n์„ ์ž…๋ ฅํ•˜์‹œ์˜ค."); + } + } + +} diff --git a/src/main/java/view/OutputView.java b/src/main/java/view/OutputView.java new file mode 100644 index 000000000..37c4befe3 --- /dev/null +++ b/src/main/java/view/OutputView.java @@ -0,0 +1,98 @@ +package view; + +import carddeck.Card; +import participant.Dealer; +import participant.Participant; +import participant.Player; + +import java.util.HashMap; +import java.util.List; + +public class OutputView { + public void printInputPlayerNameMessage() { + System.out.println("๊ฒŒ์ž„์— ์ฐธ์—ฌํ•  ์‚ฌ๋žŒ์˜ ์ด๋ฆ„์„ ์ž…๋ ฅํ•˜์„ธ์š”.(์‰ผํ‘œ ๊ธฐ์ค€์œผ๋กœ ๋ถ„๋ฆฌ)"); + } + + public void printInitialCardDistributionMessage(List names) { + StringBuilder stringBuilder = new StringBuilder(); + for (int i = 0; i < names.size(); i++) { + stringBuilder.append(names.get(i)); + if (i < names.size() - 1) { + stringBuilder.append(", "); + } + } + System.out.printf("\n๋”œ๋Ÿฌ์™€ %s์—๊ฒŒ 2์žฅ์„ ๋‚˜๋ˆ„์—ˆ์Šต๋‹ˆ๋‹ค.\n", stringBuilder); + } + + public void printParticipantCardList(Participant participant) { + List cardList = participant.getCardList(); + StringBuilder stringBuilder = new StringBuilder(); + if (participant instanceof Player) { + stringBuilder.append(participant.getName()).append("์นด๋“œ: "); + } + if (participant instanceof Dealer) { + stringBuilder.append(participant.getName()).append(": "); + } + stringBuilder.append(cardListString(cardList)); + System.out.println(stringBuilder); + } + + private StringBuilder cardListString(List cardList) { + StringBuilder stringBuilder = new StringBuilder(); + for (int i = 0; i < cardList.size(); i++) { + stringBuilder.append(cardList.get(i).toString()); + if (i < cardList.size() - 1) { + stringBuilder.append(", "); + } + } + return stringBuilder; + } + + public void printEmptyLine() { + System.out.println(); + } + + public void printAskForAdditionalCard(String name) { + System.out.printf("%s๋Š” ํ•œ์žฅ์˜ ์นด๋“œ๋ฅผ ๋” ๋ฐ›๊ฒ ์Šต๋‹ˆ๊นŒ?(์˜ˆ๋Š” y, ์•„๋‹ˆ์˜ค๋Š” n)\n", name); + } + + public void printDealerGetOneMoreCard() { + System.out.println("๋”œ๋Ÿฌ๋Š” 16์ดํ•˜๋ผ ํ•œ์žฅ์˜ ์นด๋“œ๋ฅผ ๋” ๋ฐ›์•˜์Šต๋‹ˆ๋‹ค.\n"); + } + + public void printScore(Participant participant, int score) { + List cardList = participant.getCardList(); + StringBuilder stringBuilder = new StringBuilder(); + if (participant instanceof Player) { + stringBuilder.append(participant.getName()).append("์นด๋“œ: "); + } + if (participant instanceof Dealer) { + stringBuilder.append(participant.getName()).append(" ์นด๋“œ: "); + } + stringBuilder.append(cardListString(cardList).append(" - ๊ฒฐ๊ณผ: ").append(score)); + System.out.println(stringBuilder); + } + + public void printFinalResult(List dealerResult, HashMap playerResult) { + System.out.println("## ์ตœ์ข… ์ŠนํŒจ"); + System.out.println(getDealerString(dealerResult)); + for (String name : playerResult.keySet()) { + System.out.println(name + ": " + playerResult.get(name)); + } + } + + private StringBuilder getDealerString(List dealerResult) { + StringBuilder dealerString = new StringBuilder(); + dealerString.append("๋”œ๋Ÿฌ: "); + if (dealerResult.get(0) > 0) { + dealerString.append(dealerResult.get(0)).append("์Šน "); + } + if (dealerResult.get(1) > 0) { + dealerString.append(dealerResult.get(1)).append("ํŒจ "); + } + if (dealerResult.get(2) > 0) { + dealerString.append(dealerResult.get(2)).append("๋ฌด์Šน๋ถ€"); + } + return dealerString; + } +} diff --git a/src/test/java/test.java b/src/test/java/test.java new file mode 100644 index 000000000..53ba7f616 --- /dev/null +++ b/src/test/java/test.java @@ -0,0 +1,2 @@ +public class test { +}