Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
35 changes: 35 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
## κΈ°λŠ₯ μš”κ΅¬μ‚¬ν•­

### 객체별 μ—­ν• 

**View**
- [x] κ²Œμž„ 버전(μ˜μ–΄/숫자)μž…λ ₯ λ°›κΈ°
- [x] 숫자 μž…λ ₯λ°›κΈ°
- [x] μ˜μ–΄ μž…λ ₯λ°›κΈ°

**Output**
- [x] κ²Œμž„ μ‹œμž‘ 문ꡬ 좜λ ₯
- [x] UP/DOWN κ²°κ³Ό 좜λ ₯
- [x] 정닡이면 정닡문ꡬ 좜λ ₯
- [x] μ‹œλ„ν™˜ 횟수 좜λ ₯

**Controller**
- [x] κ²Œμž„ μ‹œμž‘
- [ ] μž…λ ₯κ°’ μœ νš¨μ„± 검사

**Model**
- [x] 랜덀수 생성
- [x] λžœλ€μˆ˜λ³΄λ‹€ μž…λ ₯값이 크면 UP νŒλ‹¨
- [x] λžœλ€μˆ˜λ³΄λ‹€ μž…λ ₯값이 μž‘μœΌλ©΄ DOWN νŒλ‹¨
- [x] λžœλ€μˆ˜κ°€ μž…λ ₯κ°’κ³Ό κ°™μœΌλ©΄ κ²Œμž„ μ’…λ£Œ
- [x] μ‹œλ„νšŸμˆ˜ νŒλ‹¨

**μ—λŸ¬μ²˜λ¦¬**
- [x] 버전 μ΄μ™Έμ˜ κ°’ μž…λ ₯
:[ERROR] μ‘΄μž¬ν•˜μ§€ μ•ŠλŠ” λ²„μ „μž…λ‹ˆλ‹€.
- [ ] λ²”μœ„ λ°–μ˜ 숫자 μž…λ ₯
:[ERROR] λ²”μœ„ λ‚΄μ˜ 숫자λ₯Ό μž…λ ₯ν•˜μ„Έμš”.
- [ ] λ²”μœ„ λ°–μ˜ μ•ŒνŒŒλ²³ μž…λ ₯
:[ERROR] λ²”μœ„ λ‚΄μ˜ μ•ŒνŒŒλ²³μ„ μž…λ ₯ν•˜μ„Έμš”.
- [ ] λ‹€λ₯Έ νƒ€μž…μ˜ μž…λ ₯κ°’ μž…λ ₯
:[ERROR] μž…λ ₯ 문자의 νƒ€μž…μ΄ λ§žμ§€ μ•ŠμŠ΅λ‹ˆλ‹€.
5 changes: 4 additions & 1 deletion src/main/java/leets/land/UpdownApplication.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package leets.land;

import leets.land.controller.Controller;

public class UpdownApplication {

public static void main(String[] args) {
System.out.print("hihi :D");
Controller controller = new Controller();
controller.play();
}
}
4 changes: 4 additions & 0 deletions src/main/java/leets/land/constants/Constants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package leets.land.constants;

public class Constants {
}
Comment on lines +1 to +4
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μ΄λΆ€λΆ„μ—μ„œ μ–΄λ–€ λ‚΄μš©μœΌλ‘œ μ½”λ“œλ₯Ό μˆ˜μ •ν•˜κ³  μ‹ΆμœΌμ…¨λ˜κ±΄μ§€ κΆκΈˆν•©λ‹ˆλ‹€ !!

70 changes: 70 additions & 0 deletions src/main/java/leets/land/controller/Controller.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package leets.land.controller;

import leets.land.model.AlphabetComputer;
import leets.land.model.NumberComputer;
import leets.land.view.InputView;
import leets.land.view.OutputView;

public class Controller {
private final static AlphabetComputer alphabetComputer = new AlphabetComputer();
private final static NumberComputer numberComputer = new NumberComputer();
private final static InputView inputView = new InputView();
private final static OutputView outputView = new OutputView();

public void play(){
outputView.printStart();
int version = inputView.getVersion();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

버전이 λ‹€λ₯Ό λ•Œμ™€ νƒ€μž…μ΄ λ‹€λ₯Ό λ•Œμ˜ 버전을 μ¨μ£Όμ‹œλ©΄ μ’‹μ„κ±°κ°™μ•„μš”!!


if(version == 1){
numberPlay();
}else if( version == 2) {
alphabetPlay();
}else{
outputView.printErrorMessage("μ‘΄μž¬ν•˜μ§€ μ•ŠλŠ” λ²„μ „μž…λ‹ˆλ‹€.");
play();
Comment on lines +18 to +24
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μ˜ˆμ™Έ λ©”μ‹œμ§€λ₯Ό 좜λ ₯ν•˜κΈ°λ³΄λ‹€ μ˜ˆμ™Έλ₯Ό 작고 λ‹€μ‹œ ν•¨μˆ˜λ₯Ό μ‹€ν–‰ν–λŠ” λ‘œμ§μ„ κ΅¬μƒν•΄λ³΄μ‹œλŠ”κ±΄ μ–΄λ–¨κΉŒμš”?

}
}
public void numberPlay(){
while (true){
int input = inputView.getNextNumberGuess(numberComputer.getMin(), numberComputer.getMax());
if (!numberComputer.isValidInput(input)) {
outputView.printErrorMessage("λ²”μœ„ λ‚΄μ˜ 숫자λ₯Ό μž…λ ₯ν•˜μ„Έμš”.");
continue;
}
if(numberComputer.up(input)){
numberComputer.judgeUp(input);
outputView.printUpDownResult("UP");
}else if(numberComputer.down(input)){
numberComputer.judgeDown(input);
outputView.printUpDownResult("DOWN");
}else if(numberComputer.correct(input)){
outputView.printUpDownResult("μ •λ‹΅ !");
outputView.printCount(numberComputer.getCount());
break;
}
}
}

public void alphabetPlay(){
while (true){
char input = inputView.getNextAlphabetGuess(alphabetComputer.getMin(), alphabetComputer.getMax());
if (!alphabetComputer.isValidInput(input)) {
outputView.printErrorMessage("λ²”μœ„ λ‚΄μ˜ μ•ŒνŒŒλ²³μ„ μž…λ ₯ν•˜μ„Έμš”.");
continue;
}

if(alphabetComputer.up(input)){
alphabetComputer.judgeUp(input);
outputView.printUpDownResult("UP");
} else if(alphabetComputer.down(input)){
alphabetComputer.judgeDown(input);
outputView.printUpDownResult("DOWN");
} else if(alphabetComputer.correct(input)){
outputView.printUpDownResult("μ •λ‹΅ !");
outputView.printCount(alphabetComputer.getCount());
break;
}
}

}
}
61 changes: 61 additions & 0 deletions src/main/java/leets/land/model/AlphabetComputer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package leets.land.model;

import java.util.regex.Pattern;

public class AlphabetComputer {

private static char answer = (char) (Math.random() * ('z'-'A'+1) + 'A');
private static int count = 1;
private static char min = 'A';
private static char max = 'z';


public int getCount() {
return count;
}

public char getMin(){
return min;
}
public char getMax(){
return max;
}
public void judgeUp(char input) {
count++;
if (input == 'z') {
max = 'z';
min = 'A';
} else {
min = (char) (input + 1);
max = 'z';
}
}

public void judgeDown(char input) {
count++;
if (input == 'A') {
min = 'A';
max = 'z';
} else {
max = (char) (input - 1);
min = 'A';
}
}

public boolean up(char input) {
return answer > input;
}

public boolean down(char input) {
return answer < input;
}

public boolean correct(char input) {
return answer == input;
}

public boolean isValidInput(char input) {
return input >= min && input <= max;
}

}
48 changes: 48 additions & 0 deletions src/main/java/leets/land/model/NumberComputer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package leets.land.model;

public class NumberComputer {
private static int answer = (int) (Math.random() * 100) + 1;
private static int count = 1;
private static int min = 1;
private static int max = 100;


public int getCount() {
return count;
}

public int getMin() {
return min;
}

public int getMax() {
return max;
}

public void judgeUp(int input) {
count++;
min = input + 1;
}

public void judgeDown(int input) {
count++;
max = input - 1;
}

public boolean up(int input) {
return answer > input;
}

public boolean down(int input) {
return answer < input;
}

public boolean correct(int input) {
return answer == input;
}

public boolean isValidInput(int input){
return input >= min && input <= max;

}
}
24 changes: 24 additions & 0 deletions src/main/java/leets/land/view/InputView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package leets.land.view;

import java.util.Scanner;

public class InputView {
private final Scanner scanner;

public InputView(){
scanner = new Scanner(System.in);
}
public int getVersion(){
System.out.print("버전을 μž…λ ₯ν•΄μ£Όμ„Έμš” (숫자 버전: 1, μ˜μ–΄ 버전: 2) :");
return scanner.nextInt();
}

public int getNextNumberGuess(int min, int max){
System.out.printf("숫자λ₯Ό μž…λ ₯ν•΄μ£Όμ„Έμš”(%d ~ %d) : ",min ,max);
return scanner.nextInt();
}
public char getNextAlphabetGuess(char min, char max){
System.out.printf("μ˜μ–΄λ₯Ό μž…λ ₯ν•΄μ£Όμ„Έμš”(%c ~ %c) : ",min ,max);
return scanner.next().charAt(0);
}
}
19 changes: 19 additions & 0 deletions src/main/java/leets/land/view/OutputView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package leets.land.view;

public class OutputView {
public void printStart(){
System.out.println("μ—…λ‹€μš΄ κ²Œμž„μ„ μ‹œμž‘ν•©λ‹ˆλ‹€.\n");
}

public void printUpDownResult(String result){
System.out.println(result);
}

public void printCount(int count){
System.out.println("\nμ‹œλ„ν•œ 횟수 : " + count);
}

public void printErrorMessage(String message) {
System.out.println("[ERROR] " + message);
}
}