Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.28 KB | None | 0 0
  1. public class Tarok {
  2.     public static void main(String[] args) {
  3.    
  4.         int a=0, b=0, c=0, d=0;
  5.        
  6.         //Preberemo vhodne podatke
  7.         System.out.println("Maksimalno stevilo partij: ");
  8.         int steviloPartij=BranjePodatkov.preberiInt();
  9.         System.out.println("Zgornja meja stevila tock: ");
  10.         int zgornjaMeja=BranjePodatkov.preberiInt();
  11.         //System.out.println("Verjetnost zmage v posamezni partiji: ");
  12.         //double verjetnostZmage=BranjePodatkov.preberiInt();
  13.         double verjetnostZmage=0.7;
  14.        
  15.         //Glava tabele:
  16.         System.out.println();
  17.         System.out.print("     "+"A");
  18.         System.out.print("     "+"B");
  19.         System.out.print("     "+"C");
  20.         System.out.println("     "+"D");
  21.         System.out.println("============================");
  22.         System.out.print("     "+"0");
  23.         System.out.print("     "+"0");
  24.         System.out.print("     "+"0");
  25.         System.out.print("     "+"0");
  26.         System.out.println();
  27.        
  28.          for (int i=0; i<steviloPartij; i++) {
  29.          
  30.         //Tri=0, Dve=1, Ena=2, soloTri=3, soloDve=4, soloEna=5
  31.         int tipIgre = (int)(Math.random()*6);
  32.        
  33.         //Naključno določimo razliko, večkratniki števila 5 od 0 do 35, zato število 8    
  34.         int razlika = (int) ((Math.random()*8))*5;
  35.        
  36.         //tukaj ugotovimo, če smo zmagali ali izgubili glede na dano verjetnostZmage. Če smo zmagali nastavimo zmaga na 1, drugače na 0.
  37.         double novaVerjetnost=Math.random();
  38.                 int zmaga=0;
  39.                 if (novaVerjetnost<verjetnostZmage) {
  40.                         zmaga=1;
  41.                 }
  42.                
  43.         //naključno izberemo prvega igralca       
  44.         int prviIgralec = (int) (Math.random()*4);
  45.            
  46.         //naključno izberemo drugega igralca, ki mora ustrezati pravilom igre tarok (igri se lahko pridruži le pri tri, dve in ena).
  47.         int drugiIgralec=44444;
  48.             if ((tipIgre == 0) || (tipIgre == 1) || (tipIgre == 2)) {
  49.             drugiIgralec = (int) (Math.random()*4);
  50.             }
  51.            
  52.         //estetsko izpišemo podatke
  53.             System.out.println(" ");
  54.             if (tipIgre == 0) {
  55.                 System.out.print("tri");
  56.             }
  57.             if (tipIgre == 1) {
  58.                 System.out.print("dve");
  59.             }
  60.             if (tipIgre == 2) {
  61.                 System.out.print("ena");
  62.             }
  63.             if (tipIgre == 3) {
  64.                 System.out.print("solo tri");
  65.             }
  66.             if (tipIgre == 4) {
  67.                 System.out.print("solo dve");
  68.             }
  69.             if (tipIgre == 5) {
  70.                 System.out.print("solo ena");
  71.             }
  72.             System.out.print(",");
  73.             System.out.print(" ");
  74.             if (prviIgralec == 0) {   //naključno izbran prviIgralec poimenujemo s črko, saj naloga tako zahteva.
  75.             System.out.print("A");
  76.             }
  77.             if (prviIgralec == 1) {
  78.             System.out.print("B");
  79.             }
  80.             if (prviIgralec == 2) {
  81.             System.out.print("C");
  82.             }
  83.             if (prviIgralec == 3) {
  84.             System.out.print("D");
  85.             }
  86.             if (drugiIgralec == 0) {
  87.             System.out.print("A");
  88.             }
  89.             if (drugiIgralec == 1) {
  90.             System.out.print("B");
  91.             }
  92.             if (drugiIgralec == 2) {
  93.             System.out.print("C");
  94.             }
  95.             if (drugiIgralec == 3) {
  96.             System.out.print("D");
  97.             }
  98.             System.out.print(",");
  99.             System.out.print(" ");
  100.             if (zmaga == 1) {
  101.                         System.out.print("+");      //če zmagamo, se nam točke prištejejo zato predznak +
  102.             } else {
  103.                         System.out.print("-");      //če izgubimo, se nam točke zmanjšajo zato predznak -
  104.             }
  105.             System.out.print(razlika);
  106.            
  107.             //potrebujemo tipIgre in ga pomnožimo z 10, nato pa še prištejemo 10, da se rezultat sklada s podano tabelo,
  108.             //če ne zmagamo so skupne točke negativne.
  109.             int tockeZaIgro = tipIgre*10 +10;
  110.             int skupneTocke = tockeZaIgro + razlika;
  111.             if (zmaga==0) {
  112.             skupneTocke=skupneTocke*(-1);
  113.             }
  114.            
  115.             //podelimo točke, in preverimo da drugi igralec vstopa samo v igre katere sme - 0, 1 in 2
  116.             if (prviIgralec == 0) {
  117.             a = a + skupneTocke;
  118.             }
  119.             if (prviIgralec == 1) {
  120.             b = b + skupneTocke;
  121.             }
  122.             if (prviIgralec == 2) {
  123.             c = c + skupneTocke;
  124.             }
  125.             if (prviIgralec == 3) {
  126.             d = d + skupneTocke;
  127.             }
  128.             if ((tipIgre == 0) || (tipIgre == 1) || (tipIgre == 2)) {
  129.             }
  130.             if (drugiIgralec == 0) {
  131.             a = a + skupneTocke;
  132.             }
  133.             if (drugiIgralec == 1) {
  134.             b = b + skupneTocke;
  135.             }
  136.             if (drugiIgralec == 2) {
  137.             c = c + skupneTocke;
  138.             }
  139.             if (drugiIgralec == 3) {
  140.             d = d + skupneTocke;
  141.             }
  142.             System.out.println();
  143.            
  144.             System.out.println(a+", "+b+", "+c+", "+d);
  145.            
  146.         }
  147.            
  148.                    
  149.     }
  150.  
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement