나는이 코드를 깔끔하게 보이게하는 데 몇 가지 문제가 있습니다. IF가 많은 경우입니다. & OR 구문을 명료화해야합니다.거푸집 롤 조합 자바
아이디어 : 5 개의 오지를 던져 예를 선택하십시오. 똑같은 타입의 3 개 1,1,1 그리고 주사위 두 개를 다시 던지고 점수를 모으기.
까다로운 것은 dice1, dice2, dice3, dice4, dice5를 플레이어가 얻는 점수를 결정하기 위해 규칙 집합과 비교하는 것입니다. 어떤 코드가 가능한 모든 조합을 검사 할 것입니까? "dicex = 1 & dicex = 1 & dicex = 1"플레이어에게 1000 포인트를 주시겠습니까?
int player1points = 0;
int player2points = 0;
Scanner in = new Scanner(System.in);
Random n1 = new Random();
int dice1 = n1.nextInt(6) + 1;
int dice2 = n1.nextInt(6) + 1;
System.out.println("Dice 1 shows " +dice1);
System.out.println("Dice 2 shows " +dice2);
System.out.println("Dice 3 shows " +dice3);
System.out.println("Dice 4 shows " +dice4);
System.out.println("Dice 5 shows " +dice5);
if /* 1+1+1+1+1 = 2000 */ (dice1==1&&dice2==1&&dice3==1&&dice4==1&&dice5==1){
System.out.println("You got 2000 points! Throw again?");
int points2000 = 2000;
player1points = player1points + points2000;
System.out.print("You have ");
System.out.print(player1points);
System.out.print(" points. Do you want to throw again?");
System.out.println("Yes/No?");
s = in.nextLine();
}
else if /* 1+1+1 = 1000 */ (dice1==1&&dice2==1&&dice3==1||dice2==1&&dice3==1&&dice4==1||dice3==1&&dice4==1&&dice5==1|| dice4==1&&dice5==1&&dice1==1||dice5==1&&dice1==1&&dice2==1||dice1==1&&dice2==1&&dice4==1||d ice2==1&&dice3==1&&dice5==1||dice3==1&&dice4==1&&dice1==1||dice4==1&&dice5==1&&dice1==1||dice1==1&&dice3==1&&dice5==1){
System.out.println("You got 1000 points!");
int points1000 = 1000;
player1points = player1points + points1000;
System.out.print("You have ");
System.out.print(player1points);
System.out.print(" points. Do you want to throw again?");
System.out.println("Yes/No?");
s = in.nextLine();
}
이것은 자바 스크립트가 아닙니다 ... –
@AnubianNoob 그렇다면 코드와 태그를 보았습니다. 그래도 고정 시켰습니다 : P –
많은 영어 원어민조차도 잘못 이해합니다. "주사위"는 복수형입니다. (하나 이상). "죽는다"는 단수이다. 예 : 1 개의 주사위, 2 개의 주사위. ("오지"라는 단어는 문제의 양면 개체와 관련이 없으며 전혀 관련이없는 동사의 결합입니다.) –