Facebook
From Julson, 7 Years ago, written in Java.
Embed
Download Paste or View Raw
Hits: 356
  1. public class Kaktus {
  2.         Random randomKaktus = new Random();
  3.         int wyborKaktus;
  4.         int przedzialKaktus;
  5.         Image imgKaktus;
  6.         Image imge1;
  7.         Image imge2;
  8.         Image imge3;
  9.         public Kaktus(){
  10.                 przedzialKaktus = randomKaktus.nextInt(1150)+1170;
  11.                 BufferedImage kaktus1 = null;
  12.                 BufferedImage kaktus2 = null;
  13.                 BufferedImage kaktus3 = null;  
  14.                 try {
  15.                         kaktus1 = ImageIO.read(new File(getClass().getResource("/grafika/kaktus11.bmp").toURI()));
  16.                         kaktus2 = ImageIO.read(new File(getClass().getResource("/grafika/kaktus22.bmp").toURI()));
  17.                         kaktus3 = ImageIO.read(new File(getClass().getResource("/grafika/kaktus33.bmp").toURI()));
  18.                 } catch (IOException e) {
  19.                         e.printStackTrace();
  20.                 } catch (URISyntaxException e) {
  21.                         e.printStackTrace();
  22.                 }
  23.             imge1 = kaktus1;
  24.             imge2 = kaktus2;
  25.             imge3 = kaktus3;
  26.         }
  27.        
  28.         public void losowanieKaktusa(){
  29.                 wyborKaktus = randomKaktus.nextInt(2);
  30.                
  31.                 if(wyborKaktus==0){
  32.                         imgKaktus=imge1;
  33.                 }
  34.                 if(wyborKaktus==1){
  35.                         imgKaktus=imge2;
  36.                 }
  37.                 if(wyborKaktus==2){
  38.                         imgKaktus=imge3;
  39.                 }
  40.         }
  41.  
  42. }
  43.