基本上,这种掷骰子游戏几乎可以正常运行。在Java中运行它。我现在只有两个问题:
之前我一直在将我的代码与许多掷骰游戏进行比较,但是并没有很多帮助,并且很少有例子可以说明问题。同样,我在代码中采用的方法主要由我的讲师强制执行,并尽我所能执行。如果我的代码中有任何令人发指的罪过,那是我的错,但是需要很多复杂的东西。
import java.util.Scanner;
import java.util.Random;
//ISSUES: Roll 2 won't initiate a win if it equals the point. Win, loss, and game counters.
public class Craps_MCCH {
public static void main(String[] args){
Scanner keyboard = new Scanner(System.in);
Random rand = new Random();
System.out.println("Hey, over there. Yeah, you. What's your name?");
String name = keyboard.nextLine();
System.out.println("Are you serious? " + name + "? We don't use real names here.");
System.out.println("This is a serious operation. Give me your codename.");
String code = keyboard.nextLine();
System.out.println("Oh. " + code +". Okay. Sure.");
System.out.println();
System.out.println("So, want to play Craps?");
System.out.println("y/n");
char letter = '0';
letter = keyboard.nextLine().charAt(0);
while(letter == 'y' || letter == 'Y'){
System.out.println("Press Enter to roll.");
keyboard.nextLine();
int die1 = rand.nextInt(6)+1;
int die2 = rand.nextInt(6)+1;
System.out.println("For roll 1, you rolled a " + die1 + " and a " + die2);
int outcome = die1 + die2;
if(outcome == 7 || outcome ==11){
System.out.println("Wow, won already! No prize for new gize.");
}
else if(outcome == 2){
System.out.println("We call that snake-eyes. You lose. Do better");
}
else if(outcome == 12){
System.out.println("Choo-choo it's the boxcar children! Also you lose.");
}
else {
System.out.println(outcome + " is now your point. Roll it again to win.");
int die3 = rand.nextInt(6)+1;
int die4 = rand.nextInt(6)+1;
int outcome2 = (die3+die4);
System.out.println();
System.out.println("Let's roll. Press Enter.");
keyboard.nextLine();
int rcount = 3;
System.out.println("Roll 2: \n" + die1 + " and " + die2);
while(outcome2 != 7 || outcome2 != 11){
if(outcome == outcome2){
System.out.println("Huzzah! You've won!");
//win = win+1;
break;
}
else{
System.out.println("Point is " + outcome);
die3 = rand.nextInt(6)+1;
die4 = rand.nextInt(6)+1;
outcome2 = die3+die4;
System.out.println("Roll " + rcount++ + ":");
System.out.println("You rolled " + outcome2);
System.out.println("Press Enter.");
keyboard.nextLine();
}
}
if(outcome2 == 7 || outcome2 == 11){
System.out.println("After all that... no dice.");
//loss = loss+1;
}
}
//System.out.println("Current wins: " + win);
//System.out.println("Current losses: " + loss);
System.out.println();
System.out.println("Wins: ");
System.out.println("Losses: ");
System.out.println("Games played: ");
System.out.println();
System.out.println("Would you like to play again?");
System.out.println("y/n");
letter = keyboard.nextLine().charAt(0);
}
}
}
我希望游戏在第二局结束时最终会获胜,但我不知道该如何实现。另外,还需要计算我的赢,输和比赛。
我们被鼓励尽可能让我们的教授开心,因为他是一个愚蠢的家伙,并且不喜欢运行相同的无聊的旧程序,所以我尝试用他的打印语句来招待他,如果这看起来很愚蠢,我感到抱歉。但只希望它对他来说很有趣,并赋予它一些个性。
我不知道如何玩掷骰子,但请重新考虑您的while循环。