Guest User

Untitled

a guest
Feb 21st, 2018
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.44 KB | None | 0 0
  1. package kostka;
  2.  
  3. public class Kostka {
  4.     public static void main(String[] args) {
  5.        
  6.         System.out.println("Witaj graczu, zapraszam do gry w kości");
  7.        
  8.         Player[] Table = new Player[15];
  9.        
  10.         System.out.println("Do stołu zasiada 15 graczy");
  11.        
  12.         for(int i=0; i<15; i++){
  13.             Table[i] = new Player();
  14.         }
  15.        
  16.         System.out.println("Gracze rzucają kościami");
  17.        
  18.         for(int i=0; i<15; i++){
  19.             Table[i].throw1 = Table[i].draw();
  20.             Table[i].throw2 = Table[i].draw();
  21.             Table[i].points(Table[i].throw1, Table[i].throw2); 
  22.         }
  23.        
  24.         int[] basket = new int[2];
  25.         System.out.println("Punktacja");
  26.        
  27.         for(int i = 0; i<15; i++){
  28.             Table[i].show(basket);
  29.             System.out.println("Losy gracza " + (i+1) + " to: " + basket[0] + " i " + basket[1] +
  30.                     " posiada: " + Table[i].sum + "punktów" + "średnia pkt to: ");
  31.         }
  32.     }
  33. }
  34.  
  35.  
  36.  
  37.  
  38.  
  39. --------------------------
  40.  
  41. package kostka;
  42.  
  43. import java.util.Random;
  44. import java.util.RandomAccess;
  45.  
  46. public class Player {
  47.     public int throw1, throw2, sum;
  48.    
  49.     public int draw(){
  50.         Random rand = new Random();
  51.         int randNum = rand.nextInt(6)+1;
  52.         return randNum;
  53.     }
  54.     public void points(int throw1, int throw2){
  55.         sum = throw1+throw2;
  56.         if (throw1 == 6 || throw2 == 6) sum+=5;
  57.         if (throw1 == 6 && throw2 == 6) sum+=10;
  58.         if (throw1 + throw2 == 10) sum+=3;
  59.     }
  60.    
  61.     public void show(int[] Basket) {
  62.         Basket[0] = throw1;
  63.         Basket[1] = throw2;
  64.     }
  65.  
  66.    
  67. }
Advertisement
Add Comment
Please, Sign In to add comment