-
Notifications
You must be signed in to change notification settings - Fork 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
Java baseball game 김태근 #5
base: main
Are you sure you want to change the base?
The head ref may contain hidden characters: "java_baseball_game_\uAE40\uD0DC\uADFC"
Changes from 1 commit
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 |
---|---|---|
|
@@ -5,52 +5,56 @@ | |
import java.util.Scanner; | ||
|
||
public class GameManager { | ||
private List<Integer> playerNum = new ArrayList<>(); | ||
private List<Integer> comNum = new ArrayList<>(); | ||
public void generateGame(){ | ||
private List<Integer> playerNumber = new ArrayList<>(); | ||
private List<Integer> computerNumber = new ArrayList<>(); | ||
|
||
public void generateGame() { | ||
Computer com = new Computer(); | ||
// 컴퓨터 숫자 생성. | ||
comNum = com.randNum(); | ||
computerNumber = com.randomNumber(); | ||
} | ||
public void gameStart(){ | ||
|
||
public void gameStart() { | ||
GameEngine gameEngine = new GameEngine(); | ||
gameEngine.setComNum(comNum); | ||
gameEngine.setComNum(computerNumber); | ||
|
||
while(true){ | ||
while (true) { | ||
//플레이어 숫자 입력 | ||
Player player = new Player(); | ||
try{ | ||
playerNum = player.inputNum(); | ||
}catch (Exception e){ | ||
try { | ||
playerNumber = player.inputNumber(); | ||
} catch (Exception e) { | ||
System.out.println("잘못된 입력입니다."); | ||
System.exit(0); | ||
} | ||
|
||
gameEngine.setPlayerNum(playerNum); | ||
gameEngine.setPlayerNum(playerNumber); | ||
gameEngine.printScore(); | ||
if (!gameEngine.continueGame()) { | ||
System.out.println("3개의 숫자를 모두 맞히셨습니다! 게임 종료"); | ||
break; | ||
} | ||
} | ||
} | ||
public boolean resumeGame(){ | ||
|
||
public boolean isResumeGame() { | ||
System.out.println("게임을 새로 시작하려면 1, 종료하려면 2를 입력하세요."); | ||
Scanner sc = new Scanner(System.in); | ||
int choice = sc.nextInt(); | ||
|
||
switch (choice) { | ||
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. 혹시 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. 자료구조 수업에서 switch구문이 확장성면에서 좋다고해서 수정해보았습니다. 하하😋 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. 생각해보니, 확장의 여지가 없는 것 같기도 합니다🥲 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. 조건이 여러가지인 경우에는, (아니면 조건에 따라서 다른 종류의 객체를 반환해야 할때...) |
||
case 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. 이런 경우에는 public enum GameSignal {
RESTART(1), END(2);
int signal;
GameSignal(int signal) {
this.signal = signal;
}
// add getter...
} 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. 아하...! enum을 통해서 와... 신기합니다 |
||
return true; | ||
default: | ||
default: | ||
return false; | ||
} | ||
|
||
} | ||
public List<Integer> getPlayerNum(){ | ||
return playerNum; | ||
|
||
public List<Integer> getPlayerNum() { | ||
return playerNumber; | ||
} | ||
public List<Integer> getComNum(){ | ||
return comNum; | ||
|
||
public List<Integer> getComNum() { | ||
return computerNumber; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,13 @@ | ||
package com.taegeun; | ||
|
||
public class Main { | ||
public static void main(String[] args){ | ||
while (true){ | ||
GameManager gameManager = new GameManager(); | ||
|
||
public static void main(String[] args) { | ||
GameManager gameManager = new GameManager(); | ||
do { | ||
gameManager.generateGame(); | ||
System.out.println(gameManager.getComNum()); | ||
gameManager.gameStart(); | ||
|
||
if (!gameManager.resumeGame()){ | ||
break; | ||
} | ||
|
||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
} while (gameManager.isResumeGame()); | ||
} | ||
} | ||
} | ||
//computer 숫자를 알고 싶을 때... | ||
//System.out.println(gameManager.getComNum()); |
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.
아직 축약어인 메서드들의 이름 수정을 안하신 것 같아요!
IntelliJ
에서 macOS는⇧F6
, Windows/Linux에서는Shift+F6
을 사용하여 이름 변경 리팩토링이 안전하게 일괄적으로 가능합니다!IntelliJ
에는 정말 편리한 단축키 & 기능이 많으니 사용해보시고 익히시는 것도 좋은 것 같아요! 😊 (저도 아직 무지성 Alt + Enter만 하지만...😂)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.
앗,,, 다 살펴보았다고 생각했는데,, 꼼꼼한 리뷰 감사합니다. 매의 눈이십니다😯
편의기능 추천도 감사합니다!