Got an iPhone or iPad? We have a brand new Pastebin App for both devices, and it's totally free! Click here to download the new Pastebin App for iOS.
Guest

Gin

By: a guest on Oct 8th, 2009  |  syntax: Java  |  size: 5.90 KB  |  hits: 229  |  expires: Never
download  |  raw  |  embed  |  report abuse
Copied
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import java.awt.Color;
  4. import java.io.*;
  5.  
  6. public  
  7.         class hipno
  8.         extends Frame{
  9.         public int x;
  10.         public int y;
  11.         int szer;
  12.         int wys;
  13.         long szybkosc=51;
  14.         boolean ostatnia=false;
  15.         int plansza=1;
  16.         int pr=1;
  17.         boolean odb=true;
  18.         int czas=0;
  19.         int bufor;
  20.        
  21.        
  22.    
  23.     //drugi okrag//
  24.         int promien2=100;
  25.         int aa=(int)(Math.random()*szer-promien2-20);
  26.         int bb=(int)(Math.random()*wys-promien2-20);
  27.         boolean qq=true;
  28.         boolean ee=true;
  29.         int ll=(int)(Math.random()*250);
  30.         int uu=(int)(Math.random()*250);
  31.         int bbb=(int)(Math.random()*250);
  32.     //drugi
  33.    
  34.    
  35.        
  36.         public static void main(String[]args){
  37.        
  38.                        
  39.        
  40.        
  41.         new hipno();
  42.        
  43.         }
  44.         public hipno(){
  45.                
  46.  
  47.                
  48.    
  49.    
  50.    
  51.    addMouseListener(
  52.             new MouseAdapter(){
  53.                 public void mouseClicked(MouseEvent jj){
  54.                     hipno.this.x=jj.getX();
  55.                     hipno.this.y=jj.getY();
  56.                     if(plansza==8){
  57.                                                 //szer/2,wys/2+10,110,30
  58.                                                 if(x>szer/2 && x<(szer/2)+110 && y >wys/2+10 && y<wys/2+40 ){
  59.                                                         szybkosc=51;
  60.                                                         plansza=1;
  61.                                                         promien2=100;
  62.                                                         czas=0;
  63.                                                         hipno.this.repaint();
  64.                                                 }
  65.                                         }
  66.                    
  67.                    
  68.                    
  69.               if(x>aa && x<aa+promien2 && y>bb && y<bb+promien2 ){
  70.                                   plansza=plansza+1;
  71.                                   aa=(int)(Math.random()*szer/2);
  72.                       bb=(int)(Math.random()*wys/2);
  73.                                   if(szybkosc>1){
  74.                                   szybkosc=szybkosc-10;
  75.                                   if(ostatnia==true){
  76.                                          //System.out.println("Wygrales");
  77.                                   }
  78.                                  
  79.                           }
  80.                           if(szybkosc==1){
  81.                                   szybkosc=1;
  82.                                   ostatnia=true;
  83.                           }
  84.                           if(promien2>30){
  85.                                  promien2=promien2-10;
  86.                                  
  87.                           }
  88.                           if(promien2==30){
  89.                                   promien2=30;
  90.                                  
  91.                           }
  92.                           if(promien2==10){
  93.                                   promien2=10;
  94.                           }
  95.                           }
  96.                                         hipno.this.repaint();
  97.                                        
  98.                 }
  99.             }
  100.         );
  101.    
  102.                
  103.  
  104.         setSize(640,480);
  105.         setVisible(true);
  106.         setTitle("GRA: Catch v1.0");
  107.         setBackground(new Color(1,1,1));
  108.        
  109.         new Thread(){
  110.             public void run(){
  111.                  try{
  112.                      while(true){
  113.                           Dimension dimension=getSize();
  114.                           szer=(int)(dimension.getWidth());
  115.                           wys=(int)(dimension.getHeight());
  116.                           odbicia();
  117.                                                   sleep(szybkosc);
  118.                           hipno.this.repaint();
  119.                      }
  120.                  }catch(Exception ex){
  121.                      System.out.println(ex);
  122.                  }
  123.             }
  124.         }.start();
  125.        
  126.                
  127.                
  128.                 new Thread(){
  129.             public void run(){
  130.                  try{
  131.                      while(true){
  132.                          
  133.                           sleep(1000);
  134.                           czas();
  135.                      }
  136.                  }catch(Exception ex){
  137.                      System.out.println(ex);
  138.                  }
  139.             }
  140.         }.start();
  141.                
  142.                
  143.         }
  144.        
  145.        
  146.         public void czas(){
  147.                 if(plansza!=8){
  148.                                                   czas++;
  149.                                           }
  150.         }
  151.        
  152.         public void odbicia(){
  153.                                                  
  154.                                                   if(qq==true){
  155.                            aa++;
  156.                            
  157.                                                           ll=(int)(Math.random()*250);
  158.                                                             uu=(int)(Math.random()*250);
  159.                                                               bbb=(int)(Math.random()*250);
  160.                                                              
  161.                                               }
  162.                                               if(aa+promien2==szer){
  163.                                                           qq=false;
  164.                                                   }
  165.                                                   if(qq==false){
  166.                                                         aa--;  
  167.                                                   }
  168.                                            
  169.                                               if(aa==0){
  170.                                                         qq=true;
  171.                                              
  172.                                                         ll=(int)(Math.random()*250);
  173.                                                             uu=(int)(Math.random()*250);
  174.                                                               bbb=(int)(Math.random()*250);
  175.                                                        
  176.                                                   }
  177.                                                  
  178.                                                  
  179.                                
  180.                                                  
  181.                                                   if(bb+promien2<wys && ee==true){
  182.                                                           bb++;
  183.                                                   }
  184.                                                   if(bb+promien2==wys && ee==true){
  185.                                                           ee=false;
  186.                                                           ll=(int)(Math.random()*250);
  187.                                                             uu=(int)(Math.random()*250);
  188.                                                               bbb=(int)(Math.random()*250);
  189.                                                   }
  190.                                                   if(bb>0 && ee==false){
  191.                                                          bb--;
  192.                                                          
  193.                                                   }
  194.                                                   if(bb==0 && ee==false){
  195.                                                           ee=true;
  196.                                                          
  197.                                                           ll=(int)(Math.random()*250);
  198.                                                             uu=(int)(Math.random()*250);
  199.                                                               bbb=(int)(Math.random()*250);
  200.                                                   }
  201.                                                  
  202.                                                  
  203.                                                        
  204.                
  205.         }
  206.        
  207.        
  208.         public void paint(Graphics g){
  209.                                          
  210.                                                  
  211.                
  212.                 //
  213.                 if(plansza<8){   
  214.                 g.setColor(new Color(ll,uu,bbb));
  215.                                                  
  216.                 g.fillOval(aa,bb,promien2,promien2);
  217.                 g.setColor(new Color(250,250,250));
  218.                 g.drawString("Twoj aktualny czas to: "+czas + " sekundy",2,wys-10);
  219.                 g.drawString("Plansza numer " + plansza,szer/2,wys/2);
  220.                 g.drawString("v.1.0",szer-40,wys-20);
  221.                
  222.         }
  223.         if(plansza==8){
  224.                 szybkosc=10;
  225.                 g.setColor(new Color(250,250,250));
  226.                 g.drawString("Wygrales BRAWO",szer/2,wys/2);
  227.                 g.setColor(new Color(25,50,250));
  228.                 g.fillRect(szer/2,wys/2+10,110,30);
  229.                 g.setColor(new Color(250,250,250));
  230.                 g.drawString("NOWA GRA",szer/2+20,wys/2+30);
  231.                 g.drawString("v.1.0",szer-40,wys-20);
  232.                 str();
  233.                 g.drawString("Made by Maciej Lumanisha", pr,wys/2-22);
  234.                 g.drawString("Twoj czas to: "+czas + " sekundy",szer/2-10,80);
  235.                
  236. try{
  237. FileInputStream fis=new FileInputStream("wynik.txt");
  238. int sw=Integer.parseInt(br.readLine());
  239. g.drawString("Najlepszy czas w historii to : "+sw + " sekundy",szer/2-10,120);
  240. if(sw>czas){
  241. FileOutputStream fos=new FileOutputStream("wynik.txt");
  242. String wynik=Integer.toString(czas);
  243. for(int i=-0;i<wynik.length();++i){
  244. fos.write(wynik.charAt(i));
  245. }
  246. }
  247. }catch(IOException iex){
  248.         System.out.println("BLAD");
  249. }
  250.                
  251.        
  252.                
  253.                
  254.                
  255.         }
  256.         if(plansza==1){
  257.                         g.setColor(new Color(250,250,250));
  258.                         g.drawString("Catch me",aa+23,bb+48);
  259.                        
  260.                 }
  261.        
  262.        
  263.            
  264.     }
  265.                 public void str( ){
  266.                                 if(pr>0 && odb==true){
  267.                         pr++;
  268.                 }
  269.                 if(pr ==0){
  270.                         pr++;
  271.                         odb=true;
  272.                 }
  273.                 if(pr+300==szer){
  274.                         odb=false;
  275.                 }
  276.                
  277.                 if(odb ==false){
  278.                         pr--;
  279.                 }
  280.                
  281.                 }
  282.        
  283.         }