[Java] 단어 맞추기 게임

JTI·2022년 12월 1일
0

📌 Code list

목록 보기
14/55
post-thumbnail
import java.util.*;
public class ArrTest {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[][] words = {
                {"chair", "의자"},
                {"computer", "컴퓨터"},
                {"integer", "정수"}
        };
        for(int i = 0; i < words.length; i++) {
            System.out.printf("Q%d. %s의 뜻은?: ", i + 1, words[i][0]);
            String info = sc.nextLine();
            int count = 0;

            for(int j = 3; j > 0; j--) {

				//맞추면 안의 반복문 나감 -> 다음 퀴즈
                if(info.equals(words[i][1])) {
                    System.out.println("정답입니다 !");
                    break;
                }
				//못 맞추면 3번까지 기회
                System.out.println("틀렸습니다. " + j + "번의 기회!");
                info = sc.nextLine();
				
                //3번 GameOver (count = 1)
                if(j == 1 && !info.equals(words[i][1])) {
                    System.out.println("Game Over!");
                    count++;
                }
            }
            //3번 GameOver -> 다음 퀴즈 실행 놉 -> 프로그램 종료
            if(count == 1) {
                break;
            }
        }
    }
}
profile
Fill in my own colorful colors🎨

0개의 댓글