1. Member
Join Date
Dec 2010
Posts
3
Rep Power
0

## Yahtzee game

Hello

i'm making a simple yahtzee game for school but I don't have any idea how i should program a small and big straight.

Java Code:
```//big straight
if (waarde1 != waarde2 && waarde1 != waarde3 && waarde1 != waarde4 && waarde1 != waarde5 && waarde2 != waarde3 && waarde2 != waarde4 && waarde2 != waarde5 && waarde3 != waarde4 && waarde3 != waarde5 && waarde4 != waarde5){
resultaat = mogelijkheden.get(9);
checkScore();
}
//smal straight
if(waarde1==1&&waarde2==2&&waarde3==3&&waarde4==4&&waarde5==4 //unfinished){
resultaat = mogelijkheden.get(8);
checkScore();
}```
That is what I tried first but their are so many posibilities for a small straight, isnt their an easier way?

(sorry for my grammar, and for my names of the variables but im from belgium)

2. Senior Member
Join Date
Nov 2010
Posts
210
Rep Power
4
This is what I came up with, assuming that you've implemented your dice as an array of objects named Die[] with a method getValue() that returns its value as an int:
Java Code:
```public boolean isSmallStraight() {
boolean isRolled[] = new boolean[6];
for(int i = 1; i <= 6; i++) { // for the numbers 1-6
for(int j = 0; j < 5; j++) { //for each of the five dice
if(Die[j].getValue() == i) {
isRolled[i-1] = true;
}
}
}
return ((isRolled[0] && isRolled[1] && isRolled[2] && isRolled[3])
|| (isRolled[1] && isRolled[2] && isRolled[3] && isRolled[4])
|| (isRolled[2] && isRolled[3] && isRolled[4] && isRolled[5]));
}```

3. Iron Lion, while I understand you're just trying to help, just giving source code to prospective programmers is generally a very bad idea. If they're working on an assignment, and we just give them the answer, they learn nothing and will go into their exam without the knowledge they need.

Instead, a push in the right direction is a good idea.

4. Member
Join Date
Dec 2010
Posts
3
Rep Power
0
Thx, and now i probably have to change my big straight also like that?

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•