packageFruitninja;importjava.awt.Dimension;importjava.awt.Graphics;importjava.awt.Image;importjava.util.Random;importjavax.swing.ImageIcon;importjavax.swing.JFrame;importjavax.swing.JPanel;public class Backpicture extendsJPanel{private int x=1,y=1;private int line = 100;private int[] ti = new int[3];private int[] pi = new int[6];private int i=0;
Random ran= newRandom();private intvalue;
ThreadPicture tp= new ThreadPicture(800);
AddListener al= new AddListener(this);
ImageIcon background= new ImageIcon(this.getClass().getResource("水果忍者.jpg"));
ImageIcon apple= new ImageIcon(this.getClass().getResource("apple.png"));
ImageIcon lemon= new ImageIcon(this.getClass().getResource("lemon.png"));
ImageIcon orange= new ImageIcon(this.getClass().getResource("orange.png"));
ImageIcon purple= new ImageIcon(this.getClass().getResource("purple.png"));
ImageIcon strawberry= new ImageIcon(this.getClass().getResource("strawberry.png"));
ImageIcon watermelon= new ImageIcon(this.getClass().getResource("watermelon.png"));
ImageIcon apple1= new ImageIcon(this.getClass().getResource("apple-1.png"));
ImageIcon lemon1= new ImageIcon(this.getClass().getResource("lemon-1.png"));
ImageIcon orange1= new ImageIcon(this.getClass().getResource("orange-1.png"));
ImageIcon purple1= new ImageIcon(this.getClass().getResource("purple-1.png"));
ImageIcon strawberry1= new ImageIcon(this.getClass().getResource("strawberry-1.png"));
ImageIcon watermelon1= new ImageIcon(this.getClass().getResource("watermelon-1.png"));public static voidmain(String[] args) {
Backpicture bp= newBackpicture();
bp.initUI();
}publicBackpicture(){
ti=tp.setTi();
}public voidinitUI(){
JFrame jf= newJFrame();
jf.setDefaultCloseOperation(3);
jf.setSize(new Dimension(1500,1000));
jf.setLocationRelativeTo(null);
jf.setTitle("Fruit ninja");
jf.add(this);this.setSize(new Dimension(500,600));
jf.addMouseListener(al);
al.setThreadPicture(tp);
ranValue();
tp.getAl(al);tp.getTi(ti);
jf.setVisible(true);
Thread t= newThread(al);
t.start();
}public voidpaint(Graphics g){super.paint(g);
g.drawImage(background.getImage(),0, 0, 1500, 1000, null);for(int i=0;i<3;i++){
al.Cut();if(ti[i]==1){
g.drawImage(apple.getImage(), ti[i]*line+ti[i]*100, tp.getY(), 150, 150, null);
}if(ti[i]==2){
g.drawImage(lemon.getImage(),ti[i]*line+ti[i]*100, tp.getY(), 150, 150, null);
}if(ti[i]==3){
g.drawImage(orange.getImage(), ti[i]*line+ti[i]*100, tp.getY(), 150, 150, null);
}if(ti[i]==4){
g.drawImage(purple.getImage(), ti[i]*line+ti[i]*100, tp.getY(), 150, 150, null);
}if(ti[i]==5){
g.drawImage(strawberry.getImage(),ti[i]*line+ti[i]*100, tp.getY(), 150, 150, null);
}if(ti[i]==6){
g.drawImage(watermelon.getImage(),ti[i]*line+ti[i]*100, tp.getY(), 150, 150, null);
}if(ti[i]==7){
System.out.println("ti[i]"+ti[i]);
g.drawImage(apple1.getImage(), (ti[i]-6)*line+(ti[i]-6)*100, tp.getY(), 150, 150, null);
}if(ti[i]==8){
System.out.println("ti[i]"+ti[i]);
g.drawImage(lemon1.getImage(), (ti[i]-6)*line+(ti[i]-6)*100, tp.getY(), 150, 150, null);
}if(ti[i]==9){
System.out.println("ti[i]"+ti[i]);
g.drawImage(orange1.getImage(), (ti[i]-6)*line+(ti[i]-6)*100, tp.getY(), 150, 150, null);
}if(ti[i]==10){
System.out.println("ti[i]"+ti[i]);
g.drawImage(purple1.getImage(), (ti[i]-6)*line+(ti[i]-6)*100, tp.getY(), 150, 150, null);
}if(ti[i]==11){
System.out.println("ti[i]"+ti[i]);
g.drawImage(strawberry1.getImage(),(ti[i]-6)*line+(ti[i]-6)*100, tp.getY(), 150, 150, null);
}if(ti[i]==12){
System.out.println("ti[i]"+ti[i]);
g.drawImage(watermelon1.getImage(), (ti[i]-6)*line+(ti[i]-6)*100, tp.getY(), 150, 150, null);
}
}//System.out.println("al.Cut()="+al.Cut());//if(al.Cut()!=0){//
//if(al.Cut()==1){//g.drawImage(apple1.getImage(), al.Cut()*line+al.Cut()*100, tp.getY(), 150, 150, null);//
//}//if(al.Cut()==2){//g.drawImage(lemon1.getImage(),al.Cut()*line+al.Cut()*100, tp.getY(), 150, 150, null);//}//if(al.Cut()==3){//g.drawImage(orange1.getImage(), al.Cut()*line+al.Cut()*100, tp.getY(), 150, 150, null);//}//if(al.Cut()==4){//g.drawImage(purple1.getImage(), al.Cut()*line+al.Cut()*100, tp.getY(), 150, 150, null);//}//if(al.Cut()==5){//g.drawImage(strawberry1.getImage(),al.Cut()*line+al.Cut()*100, tp.getY(), 150, 150, null);//}//if(al.Cut()==6){//g.drawImage(watermelon1.getImage(),al.Cut()*line+al.Cut()*100, tp.getY(), 150, 150, null);//}//}
}public voidranValue(){int pi[] = {1,2,3,4,5,6};//for(int t=3;t > 0;t--)//{//value = ran.nextInt(6)+1;//ti[t-1]=value;//}//al.getValue(ti);// //al.Cut();
while(i<3){
value= ran.nextInt(6);ti[i]=0;if(pi[value]!=0){
ti[i]=pi[value];pi[value]=0;
i++;
}
al.getValue(ti);
}
}
}