|
|
Welcome to the Java Forums.
You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:
- have access to post topics
- communicate privately with other members (PM)
- not see advertisements between posts
- have the possibility to earn one of our surprises if you are an active member
- access many other special features that will be introduced later.
Registration is fast, simple and absolutely free so please, join our community today!
If you have any problems with the registration process or your account login, please contact us.
|
|

11-17-2007, 12:09 AM
|
|
Member
|
|
Join Date: Nov 2007
Posts: 6
|
|
|
Help debugging a dice game
Hello, I am new to Java.
I use BlueJ as my compiler.
Currently i am working on a project that creates a game between 1 user and the computer. you roll the dice and add points. anyway, almost all the rules are in the source below.
/* user plays a game with the computer that has to do with rolling dice
* first to 100 wins
* rolling a 1 means you lose all points for that round
* rolling two 1's means you lose all points for the game
*/
import java.util.Scanner;
import java.util.Random;
public class Pig
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
Random gen = new Random();
int a = 0;
int d = 0;
int b = 1;
int c = 0;
int total1 = 0;
int total2 = 0;
PairOfDice user = new PairOfDice();
PairOfDice computer = new PairOfDice();
// introduction
System.out.println(" Welcome to the dice game of PIG ");
System.out.println(" Do you know the rules ? (1 for yes or 2 for no)");
d = scan.nextInt();
if (d == 1)
System.out.println(" ok, then lets begin ");
else
if (d == 2)
{
System.out.println(" In this version you will play against the computer ");
System.out.println(" to play you roll the dice, and add up your total ");
System.out.println(" If you roll a one during your roll, you lose all points during that roll.(and forfeit dice to other user)");
System.out.println(" If you roll two one's during a single roll, you lose all your points for the entire game (and forfeit dice to other user)");
System.out.println(" After rolling you can roll again or turn the dice over to the other user (the computer in this case)");
System.out.println(" If you keep the dice (be a pig) you risk losing points");
System.out.println(" If you turn them over, you risk allowing your opponent to gain points or win");
System.out.println(" The choice is yours!");
}
while (b == 1)
{
System.out.println(" ---------------------------------------------------------------------------------------------------------");
System.out.println(" press 1 to roll the dice!");
b = scan.nextInt();
// user turns
if ( b == 1 )
c = user.roll2();
if (user.facevalue1() != 1 && user.facevalue2() != 1)
{
System.out.println(" the first dice is a " + user.facevalue1());
System.out.println(" the second dice is a " + user.facevalue2());
System.out.println("your two dice combined rolled a " + c) ;
total1 = total1 + c;
System.out.println(" you get " + c + " points for this round ");
System.out.println(" your total for the entire game is " + total1);
System.out.println(" press 1 to keep the dice or press 2 to turn the dice over to the computer");
System.out.println(" --------------------------------------------------------------------------");
b = scan.nextInt();
}
if (user.facevalue1() == 1 || user.facevalue2() == 1 )
{
System.out.println(" the first dice is a " + user.facevalue1());
System.out.println(" the second dice is a " + user.facevalue2());
System.out.println(" your two dice combined rolled a " + c) ;
System.out.println(" you do not get any points for that roll, becuase a 1 was present");
System.out.println(" your total is still " + total1);
System.out.println(" the dice are automatically turned over to the computer ");
System.out.println(" -------------------------------------------------------------------------");
b = 2;
}
if (user.facevalue1() == 1 && user.facevalue2() == 1)
{
System.out.println(" the first dice is a " + user.facevalue1());
System.out.println(" the second dice is a " + user.facevalue2());
System.out.println(" your two dice combined rolled a " + c);
System.out.println(" you do not get any points for that roll, because a 1 was present");
total1 = 0;
System.out.println(" Uh Oh! you rolled two ones, you lose all your points!");
System.out.println(" Your total for the game is now " + total1 );
System.out.println(" --------------------------------------------------------------------------");
}
}
// computers turns
while (b == 2)
{
System.out.println(" the computer is now rolling..... ");
a = computer.roll2();
if (computer.facevalue1() != 1 && computer.facevalue2() != 1)
{
System.out.println(" the computers first dice is a " + computer.facevalue1());
System.out.println(" the computers first dice is a " + computer.facevalue2());
System.out.println(" the computers combined roll is a " + a);
total2 = total2 + a;
System.out.println(" the computers total is " + total2);
System.out.println(" the computer has turned the dice over to you!");
System.out.println(" --------------------------------------------------------------------------");
b = 1;
}
if (computer.facevalue1() == 1 || computer.facevalue2() == 1);
{
System.out.println(" the computers first dice is a " + computer.facevalue1());
System.out.println(" the computers first dice is a " + computer.facevalue2());
System.out.println(" the computers combined roll is a " + a);
System.out.println(" the computer does not recieve any points for that roll, because a 1 was present");
System.out.println(" the computers total is still " + total2);
System.out.println(" the dice are now yours. ");
System.out.println(" --------------------------------------------------------------------------");
b = 1;
}
if (computer.facevalue1() == 1 && computer.facevalue2() == 1);
{
System.out.println(" the computers first dice is a " + computer.facevalue1());
System.out.println(" the computers first dice is a " + computer.facevalue2());
System.out.println(" the computers combined roll is a " + a);
System.out.println(" the computer does not recieve any points for tht roll, because a 1 was present");
System.out.println(" Aren't you a lucky one, the computer rolled two 1's, the computer now has 0 points.");
System.out.println(" the dice are now yours. ");
System.out.println(" --------------------------------------------------------------------------");
b = 1;
}
}
// victory conditions
// restarting
if (total1 >= 100)
{
System.out.println(" Congragtulations, you win!");
System.out.println(" press 5 to play again ");
b = scan.nextInt();
}
if (total2 >= 100)
{
System.out.println(" Game Over! the computer wins");
System.out.println(" press 5 to play again, and get revenge " );
b = scan.nextInt();
}
if (b == 5)
{
total1 = 0;
total2 = 0;
System.out.println(" press 1 to begin ! ");
b = scan.nextInt();
}
}
}
--------------------------------------------------------------------------
that is the main code, this is the controller class that setups the PairOfDice
public class PairOfDice
{
Die die1 = new Die();
Die die2 = new Die();
public int roll2()
{
die1.roll();
die2.roll();
return die1.getFaceValue() + die2.getFaceValue();
}
public int facevalue1()
{
return die1.getFaceValue();
}
public int facevalue2()
{
return die2.getFaceValue();
}
}
-------------------------------------------------------------------------
and this is the class, that actually creates the die.
import java.util.Random;
public class Die
{
private final int MIN_FACES = 4;
private static Random generator = new Random();
private int numFaces; // number of sides on the die
public int faceValue; // current value showing on the die
//-----------------------------------------------------------------
// Defaults to a six-sided die. Initial face value is 1.
//-----------------------------------------------------------------
public Die ()
{
numFaces = 6;
faceValue = 1;
}
//-----------------------------------------------------------------
// Explicitly sets the size of the die. Defaults to a size of
// six if the parameter is invalid. Initial face value is 1.
//-----------------------------------------------------------------
public Die (int faces)
{
if (faces < MIN_FACES)
numFaces = 6;
else
numFaces = faces;
faceValue = 1;
}
//-----------------------------------------------------------------
// Rolls the die and returns the result.
//-----------------------------------------------------------------
public int roll ()
{
faceValue = generator.nextInt(numFaces) + 1;
return faceValue;
}
//-----------------------------------------------------------------
// Returns the current die value.
//-----------------------------------------------------------------
public int getFaceValue ()
{
return faceValue;
}
}
------------------------------------------------------------------------
Everything compiles fine but there is a glitch in the game, that i can't seem to fix in the code..
when i run the game the output is usually similar to this
--------------------------------------------------------------
Welcome to the dice game of PIG
Do you know the rules ? (1 for yes or 2 for no)
1
ok, then lets begin
---------------------------------------------------------------------------------------------------------
press 1 to roll the dice!
1
the first dice is a 1
the second dice is a 3
your two dice combined rolled a 4
you do not get any points for that roll, becuase a 1 was present
your total is still 0
the dice are automatically turned over to the computer
-------------------------------------------------------------------------
the computer is now rolling.....
the computers first dice is a 5
the computers first dice is a 5
the computers combined roll is a 10
the computers total is 10
the computer has turned the dice over to you!
--------------------------------------------------------------------------
the computers first dice is a 5
the computers first dice is a 5
the computers combined roll is a 10
the computer does not recieve any points for that roll, because a 1 was present
the computers total is still 10
the dice are now yours.
--------------------------------------------------------------------------
the computers first dice is a 5
the computers first dice is a 5
the computers combined roll is a 10
the computer does not recieve any points for tht roll, because a 1 was present
Aren't you a lucky one, the computer rolled two 1's, the computer now has 0 points.
the dice are now yours.
--------------------------------------------------------------------------
---------------------------------------------------------------------------
when the user rolls a 1 or two 1's, the dice are automatically turned over to the computer (like they are suppose to). but, when the computer rolls, it prints it 3 times, and automatically says it has two 1's everytime. after the computers roll, when the user hits one, the computers rolls again.(but the user is suppose to). and when you hit 2 after the computer roll, the user rolls (user is only suppose to roll if 1 is hit)
so.....if anyone can help me figure out the bug in the code, it would be greatly appreciated.
=)
If you would like to contact me VIA Aol Instant Messanger, you can at: berube52991 (i would prefer this method, because it would be easier to relay messages).
Last edited by Windoze : 11-17-2007 at 12:13 AM.
|
|

11-17-2007, 12:40 AM
|
 |
Senior Member
|
|
Join Date: Oct 2007
Posts: 123
|
|
I don't know if this is causing your problem, but you should probably put all of your ifs in an if-else structure since they are exclusive. Also, you need to make the condition where both dice = 1 come before the condition when either of the dice is one. With the either or condition first, it is possible for both conditions to be true with the way you have it. If you implement the if-else structure, the 'both 1' condition will never be true because the 'either 1' condition will be true before it is reached.
I would do something like this:
if (computer.facevalue1() != 1 && computer.facevalue2() != 1)
{
System.out.println(" the computers first dice is a " + computer.facevalue1());
System.out.println(" the computers first dice is a " + computer.facevalue2());
System.out.println(" the computers combined roll is a " + a);
total2 = total2 + a;
System.out.println(" the computers total is " + total2);
System.out.println(" the computer has turned the dice over to you!");
System.out.println(" --------------------------------------------------------------------------");
b = 1;
}
else if (computer.facevalue1() == 1 && computer.facevalue2() == 1);
{
System.out.println(" the computers first dice is a " + computer.facevalue1());
System.out.println(" the computers first dice is a " + computer.facevalue2());
System.out.println(" the computers combined roll is a " + a);
System.out.println(" the computer does not recieve any points for that roll, because a 1 was present");
System.out.println(" the computers total is still " + total2);
System.out.println(" the dice are now yours. ");
System.out.println(" --------------------------------------------------------------------------");
b = 1;
}
else if (computer.facevalue1() == 1 || computer.facevalue2() == 1);
{
System.out.println(" the computers first dice is a " + computer.facevalue1());
System.out.println(" the computers first dice is a " + computer.facevalue2());
System.out.println(" the computers combined roll is a " + a);
System.out.println(" the computer does not recieve any points for tht roll, because a 1 was present");
System.out.println(" Aren't you a lucky one, the computer rolled two 1's, the computer now has 0 points.");
System.out.println(" the dice are now yours. ");
System.out.println(" --------------------------------------------------------------------------");
b = 1;
}
The last condition doesn't really need an if because if the dice are not both 1 or not not both 1, then one of them has to be one.
I'm not sure if this will fix your problem but it is a place to start. I hope it makes sense.
|
|

11-17-2007, 12:52 AM
|
|
Member
|
|
Join Date: Nov 2007
Posts: 6
|
|
|
.
That explanation does make sense.
I'm trying to implement the else if structures into the code, like you showed, but i keep getting an error on the last "else if" of the computer turns.
It won't compile because of ("else without if"). but there is an if there......
this line: else if (computer.facevalue1() == 1 || computer.facevalue2() == 1);
|
|

11-17-2007, 01:03 AM
|
 |
Senior Member
|
|
Join Date: Oct 2007
Posts: 123
|
|
|
You need to get rid of the semicolons after the conditions. Sorry, I should have caught that but I just copied and pasted your code. Those might end up being part of your problem.
Last edited by ShoeNinja : 11-17-2007 at 01:06 AM.
|
|

11-17-2007, 01:17 AM
|
|
Member
|
|
Join Date: Nov 2007
Posts: 6
|
|
|
.
I implemented the else if statements, but the problem is still occuring.
I've got a more narrow explanation of what is happening.
Everything after the //computer turns comment is printing when the computers turn is active.
Is it a problem with loops...or?
I'm pretty confused about why it's doing this, haha.
|
|

11-17-2007, 11:22 AM
|
|
Senior Member
|
|
Join Date: Jul 2007
Posts: 1,222
|
|
Besides the errant semi–colons and the change of if to else if there was a missing re–assignment of "b" and the need to wrap both while loops in another while loop that allows the turn to transfer from "computer" back to "user".
Ready for some work on closing/redirection.
import java.util.Scanner;
import java.util.Random;
public class PigRx
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
Random gen = new Random();
int a = 0;
int d = 0;
int b = 1;
int c = 0;
int total1 = 0;
int total2 = 0;
PairOfDice user = new PairOfDice();
PairOfDice computer = new PairOfDice();
// introduction
System.out.println(" Welcome to the dice game of PIG ");
System.out.println(" Do you know the rules ? (1 for yes or 2 for no)");
d = scan.nextInt();
if (d == 1)
System.out.println(" ok, then lets begin ");
else if (d == 2)
{
System.out.println(" In this version you will play against " +
"the computer ");
System.out.println(" to play you roll the dice, and add up your total ");
System.out.println(" If you roll a one during your roll, you " +
"lose all points during that roll.(and forfeit " +
"dice to other user)");
System.out.println(" If you roll two one's during a single roll, " +
"you lose all your points for the entire " +
"game (and forfeit dice to other user)");
System.out.println(" After rolling you can roll again or turn " +
"the dice over to the other user (the " +
"computer in this case)");
System.out.println(" If you keep the dice (be a pig) you " +
"risk losing points");
System.out.println(" If you turn them over, you risk allowing " +
"your opponent to gain points or win");
System.out.println(" The choice is yours!");
}
while(b == 1)
{
while (b == 1)
{
System.out.println(" ----------------------------------------" +
"-----------------------------------------" +
"------------------------");
System.out.println(" press 1 to roll the dice!");
b = scan.nextInt();
// user turns
if ( b == 1 )
c = user.roll2();
if (user.facevalue1() != 1 && user.facevalue2() != 1)
{
System.out.println(" the first dice is a " + user.facevalue1());
System.out.println(" the second dice is a " + user.facevalue2());
System.out.println("your two dice combined rolled a " + c) ;
total1 = total1 + c;
System.out.println(" you get " + c + " points for this round ");
System.out.println(" your total for the entire game is " + total1);
System.out.println(" press 1 to keep the dice or press 2 to " +
"turn the dice over to the computer");
System.out.println(" ------------------------" +
"--------------------------------------------------");
b = scan.nextInt();
}
else if (user.facevalue1() == 1 || user.facevalue2() == 1 )
{
System.out.println(" the first dice is a " + user.facevalue1());
System.out.println(" the second dice is a " + user.facevalue2());
System.out.println(" your two dice combined rolled a " + c) ;
System.out.println(" you do not get any points for that roll, " +
"becuase a 1 was present");
System.out.println(" your total is still " + total1);
System.out.println(" the dice are automatically turned over " +
"to the computer ");
System.out.println(" --------------------------------" +
"-----------------------------------------");
b = 2;
}
else if (user.facevalue1() == 1 && user.facevalue2() == 1)
{
System.out.println(" the first dice is a " + user.facevalue1());
System.out.println(" the second dice is a " + user.facevalue2());
System.out.println(" your two dice combined rolled a " + c);
// System.out.println(" you do not get any points for that roll, " +
// "because a 1 was present");
total1 = 0;
System.out.println(" Uh Oh! you rolled two ones, you lose all " +
"your points!");
System.out.println(" Your total for the game is now " + total1 );
System.out.println(" --------------------------" +
"------------------------------------------------");
// b must be set to 2 so the computer can have a turn
// otherwise it can go back to the top of this loop
b = 2;
}
}
// computers turns
while (b == 2)
{
System.out.println(" the computer is now rolling..... ");
a = computer.roll2();
if (computer.facevalue1() != 1 && computer.facevalue2() != 1)
{
System.out.println(" the computers first dice is a " +
computer.facevalue1());
System.out.println(" the computers second dice is a " + // first
computer.facevalue2());
System.out.println(" the computers combined roll is a " + a);
total2 = total2 + a;
System.out.println(" the computers total is " + total2);
System.out.println(" the computer has turned the dice over to you!");
System.out.println(" -------------------------------" +
"-------------------------------------------");
b = 1;
}
else if (computer.facevalue1() == 1 || computer.facevalue2() == 1) //;
{
System.out.println(" the computers first dice is a " +
computer.facevalue1());
System.out.println(" the computers second dice is a " + // first
computer.facevalue2());
System.out.println(" the computers combined roll is a " + a);
System.out.println(" the computer does not recieve any points for " +
"that roll, because a 1 was present");
System.out.println(" the computers total is still " + total2);
System.out.println(" the dice are now yours. ");
System.out.println(" ------------------------------" +
"--------------------------------------------");
b = 1;
}
else if (computer.facevalue1() == 1 && computer.facevalue2() == 1) //;
{
System.out.println(" the computers first dice is a " +
computer.facevalue1());
System.out.println(" the computers second dice is a " + // first
computer.facevalue2());
System.out.println(" the computers combined roll is a " + a);
// System.out.println(" the computer does not recieve any points " +
// "for tht roll, because a 1 was present");
System.out.println(" Aren't you a lucky one, the computer rolled" +
" two 1's, the computer now has 0 points.");
System.out.println(" the dice are now yours. ");
System.out.println(" -------------------------------------" +
"-------------------------------------");
b = 1;
}
}
// victory conditions
// restarting
if (total1 >= 100)
{
System.out.println(" Congragtulations, you win!");
System.out.println(" press 5 to play again ");
b = scan.nextInt();
}
if (total2 >= 100)
{
System.out.println(" Game Over! the computer wins");
System.out.println(" press 5 to play again, and get revenge " );
b = scan.nextInt();
}
if (b == 5)
{
total1 = 0;
total2 = 0;
System.out.println(" press 1 to begin ! ");
b = scan.nextInt();
}
}
}
}
|
|

11-17-2007, 06:22 PM
|
|
Member
|
|
Join Date: Nov 2007
Posts: 6
|
|
|
thanks
Thanks alot for that explanation.
i had fixed it a few hours before i read your post. but i wasn't really sure exactly what was causing it still....i just went in and tried a bunch of different things haha.
well here is my final copy of the code, that I think i will turn in. tell me what you think...and\or how i could improve it.
/* user plays a game with the computer that has to do with rolling dice
* first to 100 wins
* rolling a 1 means you lose all points for that round
* rolling two 1's means you lose all points for the game
*/
import java.util.Scanner;
import java.util.Random;
import java.io.*;
public class Pig
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
Random gen = new Random();
int a = 0;
int d = 0;
int b = 1;
int c = 0;
int total1 = 0;
int total2 = 0;
PairOfDice user = new PairOfDice();
PairOfDice computer = new PairOfDice();
// introduction
System.out.println(" Welcome to the dice game of PIG ");
System.out.println(" Do you know the rules ? (1 for yes or 2 for no)");
d = scan.nextInt();
if (d == 1)
System.out.println(" ok, then lets begin ");
if (d == 2)
{
System.out.println(" In this version you will play against the computer ");
System.out.println(" to play you roll the dice, and add up your total ");
System.out.println(" If you roll a one during your roll, you lose all points during that roll.(and forfeit dice to other user)");
System.out.println(" If you roll two one's during a single roll, you lose all your points for the entire game (and forfeit dice to other user)");
System.out.println(" After rolling you can roll again or turn the dice over to the other user (the computer in this case)");
System.out.println(" If you keep the dice (be a pig) you risk losing points");
System.out.println(" If you turn them over, you risk allowing your opponent to gain points or win");
System.out.println(" The choice is yours!");
System.out.println(" HINT: once your score is above 100, you need to be generous before you can claim victory ");
}
do
{
// victory conditions
if (total1 >= 100)
{
System.out.println(" Congragtulations, you win!");
System.out.println(" press 5 to play again ");
total1 = 0;
total2 = 0;
b = scan.nextInt();
}
else
if (total2 >= 100)
{
System.out.println(" Game Over! the computer wins");
System.out.println(" press 5 to play again, and get revenge " );
total1 = 0;
total2 = 0;
b = scan.nextInt();
}
else
if (b == 5)
{
total1 = 0;
total2 = 0;
System.out.println(" press 1 to begin ! ");
b = scan.nextInt();
}
while (b == 1)
{
System.out.println(" ---------------------------------------------------------------------------------------------------------");
System.out.println(" press 1 to roll the dice!");
b = scan.nextInt();
// user turns
if ( b == 1 )
c = user.roll2();
System.out.println("rolling.....");
System.out.println("-------------------");
try
{
Thread.sleep(3000);
}
catch(InterruptedException e) {}
if (user.facevalue1() == 1 && user.facevalue2() == 1 && b == 1)
{
System.out.println(" the first dice is a " + user.facevalue1());
System.out.println(" the second dice is a " + user.facevalue2());
System.out.println(" your two dice combined rolled a " + c);
System.out.println(" you do not get any points for that roll, because a 1 was present");
total1 = 0;
System.out.println(" Uh Oh! you rolled two ones, you lose all your points!");
System.out.println(" your total for the game is now " + total1 );
System.out.println(" the dice are automatically turned over to the computer ");
System.out.println(" --------------------------------------------------------------------------");
b = 2;
}
else if (user.facevalue1() == 1 && b == 1 || user.facevalue2() == 1 && b == 1)
{
System.out.println(" the first dice is a " + user.facevalue1());
System.out.println(" the second dice is a " + user.facevalue2());
System.out.println(" your two dice combined rolled a " + c) ;
System.out.println(" you do not get any points for that roll, becuase a 1 was present");
System.out.println(" your total is still " + total1);
System.out.println(" the dice are automatically turned over to the computer ");
System.out.println(" -------------------------------------------------------------------------");
b = 2;
}
else
{
System.out.println(" the first dice is a " + user.facevalue1());
System.out.println(" the second dice is a " + user.facevalue2());
System.out.println(" your two dice combined rolled a " + c) ;
total1 = total1 + c;
System.out.println(" you get " + c + " points for this round ");
System.out.println(" your total for the entire game is " + total1);
System.out.println(" press 1 to keep the dice or press 2 to turn the dice over to the computer");
System.out.println(" --------------------------------------------------------------------------");
b = scan.nextInt();
if ( b == 1)
{
System.out.println (" you kept the dice...(you're being a pig) ");
}
if (b == 2)
{
System.out.println (" you've been generous and turned the dice over to the computer");
System.out.println(" --------------------------------------------------------------------------");
}
}
}
// computers turns
while (b == 2)
{
if (b == 2)
{
System.out.println(" the computer is now rolling..... ");
System.out.println("------------------------------------");
a = computer.roll2();
try
{
Thread.sleep(3000);
}
catch(InterruptedException e) {}
}
if (computer.facevalue1() == 1 && computer.facevalue2() == 1 && b == 2)
{
System.out.println(" the computers first dice is a " + computer.facevalue1());
System.out.println(" the computers second dice is a " + computer.facevalue2());
System.out.println(" the computers combined roll is a " + a);
total2 = 0;
System.out.println(" the computer rolled two 1's! the computers total is now 0.");
System.out.println(" the dice are now automatically yours. ");
System.out.println(" --------------------------------------------------------------------------");
b = 1;
}
else if (computer.facevalue1() == 1 && b == 2 || computer.facevalue2() == 1 && b == 2)
{
System.out.println(" the computers first dice is a " + computer.facevalue1());
System.out.println(" the computers second dice is a " + computer.facevalue2());
System.out.println(" the computers combined roll is a " + a);
System.out.println(" the computer does not recieve any points for that roll, because a 1 was present");
System.out.println(" The computers total is still " + total2 );
System.out.println(" the dice are now automatically yours. ");
System.out.println(" --------------------------------------------------------------------------");
b = 1;
}
else
{
System.out.println(" the computers first dice is a " + computer.facevalue1());
System.out.println(" the computers second dice is a " + computer.facevalue2());
System.out.println(" the computers combined roll is a " + a);
total2 = total2 + a;
System.out.println(" the computers total is " + total2);
System.out.println(" Press 1 to have the computer give the dice to you, press 2 to let the computer roll again");
System.out.println(" --------------------------------------------------------------------------");
b = 1;
b = scan.nextInt();
if (b == 1)
{
System.out.println (" The computer has turned the dice over to you ");
}
if (b == 2)
{
System.out.println(" the computer will roll again. ");
System.out.println(" --------------------------------------------------------------------------");
}
}
}
}
while (b == 1 || b == 2);
}
}
I've tested about 10 games on it, and it seems to run just as it is suppose to.
feel free to be a beta tester =p haha.'
Also, i was considering maybe putting a Jlabel to display the scores on the top of the app...but im not really sure how to use Jlabels yet, any assistance?
Last edited by Windoze : 11-17-2007 at 06:30 PM.
|
|

11-22-2007, 03:01 AM
|
|
Member
|
|
Join Date: Nov 2007
Posts: 2
|
|
|
Hi, i have the same problem at school.
The teacher gave me premade code.
Im from norway so i've tried to have this translated
How would u make up a program?
And in this program u have to reach 100 points. Its kind of different then urs but i u have an ideas the are appreciated
Klassen Person
import javax.swing.*;
public class Person {
private String name;
private int points;
//constructor(s)
public String findName() {
//...
}
public int findPoints() {
//...
}
public void zeromakePoints() {
//...
}
public void spill(dice t) {
//the logic for the persons game is here
}
}
Klassen Machine
import javax.swing.*;
public class Machine {
//attributter
// constructor
// accessmethods
// other methods
public void spill(Terning t) {
//the logic for the machine is here
}
}
Last edited by pijamatoje : 11-22-2007 at 03:05 AM.
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|