- Feb 20, 2009
- 2,272
- 182
- 265
Hey Guys,
Been learning java for a while now never really attempted a game, but here is my Craps Game...
It runs in command prompt..
Any coders out there tell me what you think.
Been learning java for a while now never really attempted a game, but here is my Craps Game...
It runs in command prompt..
Code:
public class DiceDemo{
public static void main(String[] args){
//First Roll Dice
int dice1 = (int) (Math.random()*6 + 1);
int dice2 = (int) (Math.random()*6 + 1);
int sum = dice1 + dice2;
int Marker = 0; // declare Marker here
//First Roll Totals
System.out.println("Dice 1 Rolled .... " + dice1);
System.out.println("Dice 2 Rolled .... " + dice2);
System.out.println("In Total you scored .. " + sum);
//Determination time
if(sum==2 || sum==3 || sum==12){
System.out.println("You Loose");
} else if(sum==7 || sum==11){
System.out.println("WINNER!");
} else {
Marker = sum; // initialize marker here
do{ // start do while here
//Marker = sum;
System.out.println("-------------------------------------------");
System.out.println(" ++NEW ROLL++");
System.out.println(" Your Marker IS : " + Marker);
//Variables
int dice3 = (int) (Math.random()*6 + 1);
int dice4 = (int) (Math.random()*6 + 1);
//int total = dice3 + dice4;
sum = dice3 + dice4; // reinialize sum
//Second Roll Dice
//DO Section
//do { Remove start of do
System.out.println("You Rolled a ... " + sum);
if (sum == Marker){
System.out.println("You win!");
} else if(sum == 7) {
System.out.println("You lose!");
}
} while((sum != Marker) && (sum != 7));
} // else
}//main
}//class
Any coders out there tell me what you think.