水果忍者 java_java游戏制作之水果忍者

这是一个使用Java编写的水果忍者游戏。游戏背景、各种水果图片资源已加载,通过随机数生成水果出现的位置,并实现了基本的游戏逻辑。玩家通过监听事件进行切割操作。
摘要由CSDN通过智能技术生成

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);

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值