I have to say that I don't even understand what this means:
A die will roll until the pattern 123456 has been rolled in that exact format
In particular I don't understand what "in that exact format" means.
Daniel Hoang wrote:Well i got to it finally check for the entire pattern. But im having trouble getting the program to reset and try to roll for the first number whenever a number doesnt match. Right now, if i want to get 123456 and get a 1 on a roll, itll see if the next 5 numbers match 23456 before resetting. I want it to reset if i roll a 1 and dont get a 2 after.
Then you have a bug in your code. You need to fix that bug if you want it to behave properly.
0 means you haven't got it yet, and 1 means you got it, right? (And if so, don't use ints--use booleans).
So that says "keep going as long as..." what? Describe the condition under which that loop will keep going, based on that line of code. Describe it in English, in terms of the rules of your game, not in terms of java or loops.
Aside from that, and from using ints where you should be using booleans, that code is rather painful to read. The logic is really hard to follow. Too much duplicated code, too much nesting. It would be clearer if you used methods (for less duplicated code and less nesting) and arrays (for less duplicated code).
Daniel Hoang wrote:Also i know its hard to read, im not allowed to use methods or arrays...
Hunh? . Must be some new kind of teaching by torture...
All I can say is: once you've finished this exercise, forget it ever existed.
You always want to use methods to break up logic - and, within reason: the more, the better.
Also, that has virtually nothing to do with making your code neat and easy to read.
As for arrays: there are other alternatives, which you'll probably learn about soon; but for a fixed-sized group of values, they are exactly what you should use - and don't let anyone tell you any different.
Daniel Hoang wrote:yes 0 means i havent got the number, 1 means i have. The condition i tried using for that loop is, keep rolling the die if none of the numbers in pattern have been matched.
You're contradicting yourself. Earlier you said that as soon as any one digit doesn't match, you have to start over--in other words, if the desired number is 1234, then you have to roll a 1, and the very next roll has to be a 2, and the very next roll after that has to be a 3, and then the very next roll has to be a 4.
What you're saying here, and what that do/while condition says, is keep rolling only if all the numbers are wrong. So if I got a 1 and then a 5, since the 1 matched, the "none have been matched" condition is false, so we break out of the loop.
And if you're really not allowed to use methods, you should drop the class, because the teacher is incompetent. This could be made much easier to understand with proper division of responsibility.