-
Notifications
You must be signed in to change notification settings - Fork 5
숫자야구게임 제출합니다! #2
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
base: chae-heechan
Are you sure you want to change the base?
Changes from all commits
a5a90c3
cb411a6
0dc3517
0c9d817
321a971
322f4cb
2efe851
ef779f4
6a9b002
83a7c97
6da84a4
716c21e
ea4473c
c9c11d5
da207b8
f999fb8
aa71193
025400d
03ace49
2d75f43
7b3b130
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 woowacourse | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
plugins { | ||
id 'java' | ||
} | ||
apply plugin: 'java' | ||
apply plugin: 'eclipse' | ||
|
||
group 'org.example' | ||
version '1.0-SNAPSHOT' | ||
version = '1.0.0' | ||
sourceCompatibility = 1.8 | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.0' | ||
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine' | ||
testImplementation('org.junit.jupiter:junit-jupiter:5.7.0') | ||
testImplementation('org.assertj:assertj-core:3.18.1') | ||
testImplementation('org.mockito:mockito-inline:3.6.0') | ||
} | ||
|
||
test { | ||
useJUnitPlatform() | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
<<<<<<< HEAD | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-bin.zip | ||
======= | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-bin.zip | ||
>>>>>>> 2d75f4343ccfdead02994a6674392d6353b04a19 | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,16 @@ | |
|
||
public class Application { | ||
public static void main(String[] args) { | ||
Scanner scanner = new Scanner(System.in); | ||
// TODO 구현 진행 | ||
final Scanner scanner = new Scanner(System.in); | ||
GamePlayer gamePlayer = new GamePlayer(); | ||
|
||
//게임 시작 | ||
while(true){ | ||
gamePlayer.play(scanner); | ||
System.out.println("게임을 새로 시작하려면 1, 종료하려면 2를 입력하세요."); | ||
if(scanner.nextInt()==1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 여기서 1만 보고 게임 시작이란 것을 알 수 있을까요? |
||
continue; | ||
Comment on lines
+13
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 다른 코드에서 try~catch로 예외처리를 해주셨는데 이 코드에서만 안해주고 있습니다. 이런 비일관성이 발생한 이유가 연관된 상태와 행위를 결정하는 기능을 묶어주는 캡슐화를 하지 않은 것으로부터 발생한 것으로 보입니다. 입력을 받는 모든 행위와 그와 관련된 상태(변수)들을 클래스를 이용해 캡슐화를 해보세요! 😃 위와 같은 이유로 게임의 비즈니스 로직과 사용자 입력을 받고, 필요한 문장을 출력하는 일이 혼재되어 있습니다. |
||
break; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,36 @@ | ||||||
package baseball; | ||||||
|
||||||
import java.util.InputMismatchException; | ||||||
import java.util.Scanner; | ||||||
|
||||||
import static baseball.Number.*; | ||||||
|
||||||
public class GamePlayer { | ||||||
|
||||||
public static void play(Scanner Input){ | ||||||
Number random = new Number(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Number 객체를 만든것 👍🏻 객체로 감싼 것은 잘 했지만 Number라는 것만 보고는 이 숫자는 무슨 숫자인지 파악할 수가 없어요. |
||||||
Number player = new Number(); | ||||||
Integer temp; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 사용자 입력을 받아서 그 상태를 가지고 있는 변수가 temp라는 이름으로 그 의도를 드러내지 못하고 있습니다. 클린코드라는 책에서는 한 챕터를 의미 있는 이름으로 할당할 만큼 의도가 분명한 이름의 중요성은 아무리 강조해도 지나치지 않은 것 같습니다! 코딩할 때 힘들더라도 의미 있는 이름을 지어주려고 노력해보세요. 😃
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. int가 아닌 Integer 클래스를 사용한 이유는 무엇인가요? 두개는 무슨 차이가 있을까요? |
||||||
|
||||||
//랜덤 수 생성 | ||||||
random.setNumber(random.createNumber()); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. random이란 Number클래스의 인스턴스에 값을 Number 내부가 아닌 외부에서 set해주고 있네요. 위와 같은 경우는 random이라는 인스턴스가 생성될 때 createNumber를 하면 되는 것이니 생성자를 활용해보는건 어떨까요? |
||||||
|
||||||
//게임 내 n트 | ||||||
while(true) { | ||||||
//입력 받고 비정상적인 입력 처리하고 저장 | ||||||
System.out.print("숫자를 입력해 주세요 : "); | ||||||
try { | ||||||
temp = Input.nextInt(); | ||||||
}catch (InputMismatchException e) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 구체적인 Exception 클래스 사용 👍🏻 |
||||||
throw new IllegalArgumentException("올바른 입력이 아닙니다!"); | ||||||
} | ||||||
Comment on lines
+22
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. try~catch로 예외 처리를 시도해주셨지만 catch 문에서 발생한 예외 상황에 예외 객체를 던지기만 할뿐 어떤 처리도 해주고 있지 않고 있습니다. 숫자를 다시 입력받거나 다른 처리를 해주는 것이 낫지 않을까요? |
||||||
|
||||||
inputCheck(temp); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 코딩 컨벤션에 따르면 checkInput이 어울릴 것 같아요! |
||||||
player.setNumber(splitNumber(temp)); | ||||||
|
||||||
Referee referee = new Referee(); | ||||||
if (referee.judgement(random.getNumber(), player.getNumber())) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2.10. 메서드 이름은 동사/전치사로 시작 컨벤션이 안지켜지고 있네요. |
||||||
break; | ||||||
} | ||||||
} | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
지금의 코드는 인스턴스(
gamePlayer
)를 통해 메소드(play
)를 호출하고있어요.하지만 play는 static 메소드이고, static 메소드는 인스턴스를 생성 할 필요가 없이
Gameplayer.play
로 호출이 가능해요.GamePlayer.play
와gamePlayer.play
는 무슨 차이가 있을까요?