Facebook
From Mungo Gibbon, 7 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 291
  1. package javaapplication1;
  2.  
  3. import java.util.Random;
  4.  
  5. public class Statek {
  6.     public final int SPRAWNY = 1;
  7.     public final int NIESPRAWNY = 0;
  8.    
  9.     protected String mNazwa;
  10.     protected int stan;
  11.  
  12.     public Statek(String mNazwa, int stan) {
  13.         this.mNazwa = mNazwa;
  14.         this.stan = stan;
  15.     }
  16.    
  17.     public void wyswietl(){
  18.         String stany = stan == 1 ? "Sprawny" : "Niesprawny";
  19.         System.out.println("Statek " + mNazwa);
  20.         System.out.println("Stan: " + stany);
  21.     }
  22.    
  23.     public void bronsie(Statek oponent){
  24.         if(this.stan == 1){
  25.             Random r = new Random();
  26.             int wynik = r.nextInt(2);
  27.             oponent.ustawStan(0);
  28.         }
  29.     }
  30.    
  31.     public void ustawStan(int stan){
  32.         this.stan = stan;
  33.     }
  34.    
  35.     public int dajStan(){
  36.         return this.stan;
  37.     }
  38. }
  39.