import java.util.Scanner;
public class Game{
int score = 0;
Scanner reader = new Scanner(System.in);
String name;
String enter;
public void Play() {
System.out.print("Enter Player One Name: ");
name = reader.nextLine();//enter player name
现在只使用一个玩家等待在添加另一个
之前查看它是否有效 System.out.println("Welcome Players!"+
"To win the game press enter to roll" +
"The first player to score 50 wins!!!"+
"Press enter to start the game!!!");
enter = reader.nextLine(); //This is a dummy code. Just pauses and waits for enter press.
int roll = (int)(Math.random()* 6 + 1);
score += roll; //will add roll value to current score
System.out.println("you rolled a: " + roll + " and are now on "
+ score);
while(score <= 50){
//String enter;
enter = reader.nextLine();
roll = (int)(Math.random()* 6 + 1);
score += roll;
我原本以为这会将你输入的数字加到你当前的分数上。
if(roll % 7==0){
System.out.println("move forward 2 spaces!!" +
"New score is: " + score );
}else{
System.out.println(score);
}
if(roll % 9==0){
System.out.println("Sorry move back two spaces :("+
"New score is: " + score);
}else{
System.out.println(score);
}
if (roll == 12){
System.out.println("oh no! You lost all points"+
"New score is: " + score + roll);
score = 0;
}else{
System.out.println(score );
}
System.out.println(roll);
}
}
答案 0 :(得分:0)
roll
将始终介于1到6之间,因此if
测试都不会成立。你的意思是考试score
吗?或者你想通过循环中的roll
在roll += (int)(Math.random()* 6 + 1);
积累卷?