Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.52 KB | None | 0 0
  1.     public void resultatAvslut(int[] tärning) {
  2.  
  3.         int resultat = 0;
  4.  
  5.         boolean yatzy = false;
  6.         int yatsynummer = 0;
  7.  
  8.         for (int i = 1; i < tärning.length; i++)
  9.  
  10.             if (tärning[i] == tärning[i - 1]) {
  11.                 yatsynummer += 1;
  12.             }
  13.  
  14.         if (yatsynummer == 4){
  15.             yatzy = true;
  16.             resultat = 50;
  17.         }
  18.  
  19.         if (!yatzy) {
  20.             for (int i = 0; i < tärning.length; i++)
  21.                 resultat += tärning[i];
  22.         }
  23.         System.out.println("Resultatet för spelarens omgång är " + resultat);
  24.         System.out.println("Nästa spelares tur!");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement