// 我一整天都在研究这个问题,但似乎仍然被卡住了。// 我没有收到任何明显的错误,但循环似乎被破坏了。// 我是一个初学者,所以很可能我错过了一些大事,但只是忽略了它。// 我的课的作业要在午夜截止,哈哈。// 我觉得我构建了基本格式,但是我对使用循环的不熟悉确实让我陷入了困境。我在网上其他地方查看过,但人们制作的许多“骰子”程序仅与一个六面骰子有关,并且不涉及基于回合的用户输入。// 任何有用的提示都很棒,有没有更有效的方法来构建这个游戏?我知道创建多个类会清理程序的外观,但目前我实际上只是在寻找功能。
package prgm06;
import java.util.Scanner;
public class DiceGame
{
public static void main(String []args) //main DiceGame loop.
{
String answer;
Scanner stdIn = new Scanner(System.in);
int userWin = 0, userLose = 0, turnCounter = 0;
System.out.println("\t" + "Welcome to Computer Dice");
System.out.println("-----------------------------------------");
System.out.println("The outcome of your roll will determine" + "\n" + "if you win or lose the round." + "\n");
System.out.println("Any Quad and you win.");
System.out.println("Any Triple and you win.");
System.out.println("Any High Pair and you win.");
System.out.println("Anything else and you lose.");
System.out.println("-----------------------------------------");
System.out.println("Do you wish to play? [y,n]: ");
do { // I always want the dice to roll unless "n" is selected.
answer = stdIn.next();
int d1 = (int)(Math.random() * 4) + 1;
int d2 = (int)(Math.random() * 4) + 1;
int d3 = (int)(Math.random() * 4) + 1;
int d4 = (int)(Math.random() * 4) + 1;
}
while(answer.equalsIgnoreCase("y")); // issues with "y" not printing if/ else statements
{
int d1 = (int)(Math.random() * 4) + 1;
int d2 = (int)(Math.random() * 4) + 1;
int d3 = (int)(Math.random() * 4) + 1;
int d4 = (int)(Math.random() * 4) + 1;
System.out.println(d1 + "\t" + d2 + "\t" + d3 + "\t" + d4);
绝地无双
相关分类