我制作的java游戏赢了';不要记分
现在只使用一个播放器,等待在添加另一个播放器之前,看看它是否与一个播放器一起工作我制作的java游戏赢了';不要记分,java,Java,现在只使用一个播放器,等待在添加另一个播放器之前,看看它是否与一个播放器一起工作 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
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
根据此代码,
roll
将始终在1到6之间,因此,if
测试都不会为真。你是不是想测试分数?或者,您可能想通过执行roll+=(int)(Math.random()*6+1)来累积roll
代码>在你的循环中?你能让它可读吗?您知道缩进是正确的,并且代码不会在方法中途停止吗?也没有main
方法。欢迎来到stackoverflow.com你已经问了这个问题,改进这个问题,而不是问同样的问题。对不起,我真的不知道我在做什么。我不知道该怎么做,也不知道明天高中期中考试该怎么做。我对编码或任何与计算机相关的知识一无所知。我的学校把我安排在课堂上,因为我既没有资格也没有能力胜任这项工作,而且我不能转到其他领域。我真的很抱歉,我会尝试修复它,但我不知道怎么做。您是否创建过游戏的新实例
?这是一个澄清请求,而不是回答;这应该是一个评论。至少他在正确的方向上,糟糕的问题可以得到糟糕的答案。OP只是转储代码,你如何回答这个问题?或者你连试都不试?
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);
}
}