a_giunta67
Baseband Member
- Messages
- 37
First off, I'm a complete noob at programming. I'm taking a Java class in school and I can't figure out why this loop freezes. The assignment is to make a Craps game using the Objectdraw library.
Code:
import java.io.*;
import objectdraw.*;
public class craps extends WindowController{
private RandomIntGenerator die = new RandomIntGenerator(1, 6);
int roll1;
int roll2;
int userPoint;
int rollTotal;
int reRollTotal;
boolean firstRoll;
boolean reRoll;
public void begin(){
setSize(500,500);
new Text("Click to roll.", 10, 20, canvas);
roll1 = die.nextValue();
roll2 = die.nextValue();
rollTotal = (roll1+roll2);
}
public void onMousePress(){
firstRoll = true;
reRoll = false;
if(firstRoll == true){
canvas.clear();
new Text("You rolled a " + (rollTotal),10,20,canvas);
if(rollTotal == 7 || rollTotal == 11){
new Text("You win!", 10, 40, canvas);
}
else if(rollTotal == 2 || rollTotal == 3 || rollTotal == 12){
new Text("You've crapped out.", 10, 40, canvas);
firstRoll = false;
reRoll = false;
}
else{
new Text("You didn't win or crap out. Your point is " + rollTotal + ". \nRoll again.", 10, 40, canvas);
userPoint = rollTotal;
reRoll = true;
firstRoll = false;
}
while(!firstRoll){
reRollTotal = roll1+roll2;
new Text(reRollTotal, 10, 80, canvas);
}
}
}
}