Results 1 to 4 of 4

Thread: Yahtzee game

  1. #1
    Vinny2110 is offline Member
    Join Date
    Dec 2010
    Posts
    3
    Rep Power
    0

    Default 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. #2
    Iron Lion is offline Senior Member
    Join Date
    Nov 2010
    Posts
    210
    Rep Power
    4

    Default

    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. #3
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    4

    Default

    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. #4
    Vinny2110 is offline Member
    Join Date
    Dec 2010
    Posts
    3
    Rep Power
    0

    Default

    Thx, and now i probably have to change my big straight also like that?

Similar Threads

  1. Replies: 2
    Last Post: 08-05-2010, 04:49 AM
  2. game code for any game
    By deathnote202 in forum Java Gaming
    Replies: 4
    Last Post: 06-10-2010, 08:06 AM
  3. Help with game
    By TGH in forum New To Java
    Replies: 26
    Last Post: 01-12-2010, 02:55 PM
  4. Small yahtzee program
    By kimmelim in forum New To Java
    Replies: 20
    Last Post: 03-12-2009, 12:11 PM
  5. 2D strategy game or 2D war game
    By led1433 in forum Java 2D
    Replies: 5
    Last Post: 02-10-2009, 06:00 AM

Posting Permissions

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