Results 1 to 18 of 18
Thread: dice game code creating help!
- 11-17-2011, 11:04 AM #1
Member
- Join Date
- Nov 2011
- Posts
- 7
- Rep Power
- 0
dice game code creating help!
Hello! I know it is silly to ask that kind of question but can someone help me to create code to kind of the dice game that with random number generator simulating dice rolls. And rolling ends only when comes 1 or 6! And print out every roll points and all score and throw times!
Thank you in advance!
- 11-17-2011, 01:26 PM #2
Re: dice game code creating help!
There are many people here that will help you get your code to work.
Post your code and your questions. Or ask specific questions about the problems you are having.
- 11-20-2011, 08:52 PM #3
Member
- Join Date
- Nov 2011
- Posts
- 7
- Rep Power
- 0
Re: dice game code creating help!
I know that in it there is still a lot of work but there is nothing working out for me!Java Code:import java.util.Random; //genere nejausi izveletus skaitljus public final class Dice { public static final void main(String... aArgs){ log("Jusu metieni:"); int START = 1; int END = 6; Random random = new Random(); for (int idx = 1; idx <= 100; ++idx){ showRandomInteger(START, END, random); } log("Pabeigts."); } private static void showRandomInteger(int aStart, int aEnd, Random aRandom){ if ( aStart > aEnd ) { throw new IllegalArgumentException("Start cannot exceed End."); } long range = (long)aEnd - (long)aStart + 1; long fraction = (long)(range * aRandom.nextDouble()); int randomNumber = (int)(fraction + aStart); log("Jusu metienu rezultati : " + randomNumber); } private static void log(String aMessage){ System.out.println(aMessage); } }
Thank you!Last edited by Norm; 11-20-2011 at 09:11 PM. Reason: added code tags
- 11-20-2011, 08:56 PM #4
Re: dice game code creating help!
Please explain. Show the program's output and explain what is wrong with what it printed.there is nothing working out for me!
If you get errors copy and paste here the full text.
- 11-20-2011, 09:08 PM #5
Member
- Join Date
- Nov 2011
- Posts
- 7
- Rep Power
- 0
Re: dice game code creating help!
that far everything is okay but i cant understand how can i make it to stop on 1 or 6 ??? :?
- 11-20-2011, 09:10 PM #6
Re: dice game code creating help!
What are you trying to stop?how can i make it to stop on 1 or 6
Can you show the programs output and add comments to that output showing where the problem is?
- 11-20-2011, 09:16 PM #7
Member
- Join Date
- Nov 2011
- Posts
- 7
- Rep Power
- 0
Re: dice game code creating help!
--------------------Configuration: <Default>--------------------
Jusu metieni:
Jusu metienu rezultati : 6
Jusu metienu rezultati : 5
Jusu metienu rezultati : 6
Jusu metienu rezultati : 2
Jusu metienu rezultati : 5
Jusu metienu rezultati : 5
Jusu metienu rezultati : 6
Jusu metienu rezultati : 4
Jusu metienu rezultati : 4
Jusu metienu rezultati : 2
Jusu metienu rezultati : 6
Jusu metienu rezultati : 4
Jusu metienu rezultati : 3
Jusu metienu rezultati : 2
Jusu metienu rezultati : 6
Jusu metienu rezultati : 6
Jusu metienu rezultati : 1
Jusu metienu rezultati : 4
Jusu metienu rezultati : 3
Jusu metienu rezultati : 5
Jusu metienu rezultati : 4
Jusu metienu rezultati : 6
Jusu metienu rezultati : 6
Jusu metienu rezultati : 4
Jusu metienu rezultati : 5
Jusu metienu rezultati : 2
Jusu metienu rezultati : 4
Jusu metienu rezultati : 6
Jusu metienu rezultati : 4
Jusu metienu rezultati : 6
Jusu metienu rezultati : 3
Jusu metienu rezultati : 4
Jusu metienu rezultati : 4
Jusu metienu rezultati : 2
Jusu metienu rezultati : 3
Jusu metienu rezultati : 3
Jusu metienu rezultati : 2
Jusu metienu rezultati : 1
Jusu metienu rezultati : 1
Jusu metienu rezultati : 6
Jusu metienu rezultati : 5
Jusu metienu rezultati : 1
Jusu metienu rezultati : 4
Jusu metienu rezultati : 2
Jusu metienu rezultati : 3
Jusu metienu rezultati : 3
Jusu metienu rezultati : 6
Jusu metienu rezultati : 3
Jusu metienu rezultati : 6
Jusu metienu rezultati : 3
Jusu metienu rezultati : 3
Jusu metienu rezultati : 1
Jusu metienu rezultati : 3
Jusu metienu rezultati : 3
Jusu metienu rezultati : 4
Jusu metienu rezultati : 4
Jusu metienu rezultati : 5
Jusu metienu rezultati : 5
Jusu metienu rezultati : 6
Jusu metienu rezultati : 2
Jusu metienu rezultati : 4
Jusu metienu rezultati : 3
Jusu metienu rezultati : 2
Jusu metienu rezultati : 1
Jusu metienu rezultati : 3
Jusu metienu rezultati : 4
Jusu metienu rezultati : 1
Jusu metienu rezultati : 2
Jusu metienu rezultati : 5
Jusu metienu rezultati : 6
Jusu metienu rezultati : 5
Jusu metienu rezultati : 1
Jusu metienu rezultati : 6
Jusu metienu rezultati : 4
Jusu metienu rezultati : 4
Jusu metienu rezultati : 3
Jusu metienu rezultati : 1
Jusu metienu rezultati : 1
Jusu metienu rezultati : 4
Jusu metienu rezultati : 4
Jusu metienu rezultati : 1
Jusu metienu rezultati : 2
Jusu metienu rezultati : 3
Jusu metienu rezultati : 3
Jusu metienu rezultati : 1
Jusu metienu rezultati : 4
Jusu metienu rezultati : 1
Jusu metienu rezultati : 6
Jusu metienu rezultati : 4
Jusu metienu rezultati : 3
Jusu metienu rezultati : 3
Jusu metienu rezultati : 4
Jusu metienu rezultati : 6
Jusu metienu rezultati : 2
Jusu metienu rezultati : 6
Jusu metienu rezultati : 5
Jusu metienu rezultati : 6
Jusu metienu rezultati : 3
Jusu metienu rezultati : 3
Jusu metienu rezultati : 5
Pabeigts.
Process completed.
Its like a Dice with that random number generator it generates the dice throws and i have to stop when comes one or six but i dont know how!
- 11-20-2011, 09:20 PM #8
Re: dice game code creating help!
Use an if statement with a condition that compares the value to 1 or 6.i have to stop when comes one or six but i dont know how!
When the condition is true (the value is 1 or 6) then do what you want.
What do you mean by "stop"?
The System.exit(0) method will stop the execution of the program.
A break statement will stop the execution of a loop by exiting from the loop
- 11-22-2011, 01:13 AM #9
Member
- Join Date
- Nov 2011
- Posts
- 7
- Rep Power
- 0
Re: dice game code creating help!
So i know i am silly but i cant get it! So i have to write code who simulates dice rolling and rolling have to stop when it rolls 1 or 6 and count all result!Java Code:import java.util.Random; //genere nejausi izveletus skaitljus public final class Kaulins23 { public static final void main(String... aArgs){ log("Jusu metieni:"); int START = 1; int END = 6; Random random = new Random(); for (int idx = 1; idx <= 100; ++idx){ showRandomInteger(START, END, random); if (idx == 6, 1) // and if it is six or one it has to stop rolling the dice System.out.println(""); else System.out.println(""); System.out.println("Rezultats ir" +sum+= idx ); // so here i need to count all the numbers } log("Pabeigts."); } private static void showRandomInteger(int aStart, int aEnd, Random aRandom){ if ( aStart > aEnd ) { throw new IllegalArgumentException("Nevar sasniegt beigas."); } long range = (long)aEnd - (long)aStart + 1; long fraction = (long)(range * aRandom.nextDouble()); int randomNumber = (int)(fraction + aStart); log("Jusu metiena rezultats : " + randomNumber); } private static void log(String aMessage){ System.out.println(aMessage); } }
Thanks all
Last edited by Norm; 11-22-2011 at 01:21 AM. Reason: added code tags
- 11-22-2011, 01:24 AM #10
Re: dice game code creating help!
Can you write the steps you want the program to do in pseudo code: Simple statements in English instead of Java?
What computer programming languages do you know that you copied this statement from?if (idx == 6, 1)
Do you have a tutorial or text book you can read that defines how to create conditional expressions?
This statement is not valid java.
- 11-22-2011, 01:26 AM #11
Re: dice game code creating help!
Is that valid Java syntax? Have you seen any examples like that in a book or in an online tutorial? I bet there are many examples that show you how to make 2 or more comparisons in an if statement.Java Code:if (idx == 6, 1)
- 11-22-2011, 01:32 AM #12
Member
- Join Date
- Nov 2011
- Posts
- 7
- Rep Power
- 0
Re: dice game code creating help!
at first it has to generate random numbers from 1 to 6 (like dice).
then it has to stop when it comes 1 or 6
and at the end it have to count all the numbers what comes out.
- 11-22-2011, 01:36 AM #13
Re: dice game code creating help!
We understand what the program is. DO YOU understand what is wrong with your if statement?
- 11-22-2011, 01:36 AM #14
Re: dice game code creating help!
That is the big view, now break each of those statement up into smaller steps.
For example you need to show where the numbers are added up. It must be done as each number is generated,
not at the end after a 1 or 6.
Show where the begin and end of the loop is. for example:
begin loop
get number
test number
do something with number
end loop >> here the logic goes back to the begin loop
do something here
- 11-22-2011, 01:37 AM #15
Re: dice game code creating help!
Oh wow I just realised you are using the loop index in the if statement and not the random number. Another issue to resolve.
- 11-22-2011, 02:28 AM #16
Member
- Join Date
- Nov 2011
- Posts
- 7
- Rep Power
- 0
Re: dice game code creating help!
import java.util.Random;
class kaulins {
public static void main (String[] args) {
Random kaulinss = new Random();
int skaitlis;
for(int counter=1; counter<=20; counter++){
skaitlis = 1+kaulinss.nextInt(6);
System.out.println(skaitlis+" - metiena rezultats");
if (skaitlis == 6)
System.out.println ("");
if (skaitlis == 1)
System.out.print("");
else
System.out.println ("");
}
}
}
Like this is on right way?
- 11-22-2011, 02:33 AM #17
Re: dice game code creating help!
No. I suggest that you work on the logic first. After you have the logic, then you can write the code.
See post #14.
You need to think what the steps are your program is to do first.
Then you write code to do those steps.
- 11-22-2011, 02:34 AM #18
Similar Threads
-
Pig Dice Game Help
By pvccstudent in forum New To JavaReplies: 3Last Post: 07-10-2011, 02:21 AM -
Pig dice game
By dangyounoobs in forum New To JavaReplies: 0Last Post: 06-12-2011, 06:57 AM -
Dice game help and arrays
By SnarkKnuckle in forum New To JavaReplies: 4Last Post: 03-10-2011, 01:57 AM -
Help with a dice game.
By hero in forum AWT / SwingReplies: 14Last Post: 07-26-2009, 11:50 AM -
Help debugging a dice game
By Windoze in forum New To JavaReplies: 7Last Post: 11-22-2007, 01:01 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks