• 大小: 4.3MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-09-19
  • 语言: Java
  • 标签: java  eclipse  

资源简介

java语言开发的简单的大鱼吃小鱼游戏,开发工具eclipse,直接将该工程导入即可运行,StartGame_Eatfish.java是开始游戏类,游戏中的声音是直接使用的第三方插件,在bin那个文件夹下jl1.0.1.jar, 源码仅供java爱好者 参考

资源截图

代码片段和文件信息

package com.LanheIT.eatfish.start;

import java.awt.Graphics;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.util.Random;

/**
 * @param args
 * @author 蓝鹤-IT QQ:352465677
 * @version 11.09.1
 */

public class EatenFish {
    
//得到窗体的工具包
    public Toolkit tool = Toolkit.getDefaultToolkit();
    //得到被吃的小鱼的图片
    
    Random r = new Random();
    //获取向左图片
    Image smallFish_1 = tool.getImage(StartGame_Eatfish.class
.getResource(“eatenfish_right/“+r.nextInt(3)+“.gif“));
    //向右游动的初始坐标
    Image smallFish_2 = tool.getImage(StartGame_Eatfish.class
     .getResource(“eatenfish_left/“+r.nextInt(3)+“.gif“));
    
    //向右游动的初始坐标
int eaten_x = 0;
int eaten_y = 0;


//存储判断传过来的数 0表示向右游 反之向左
int m = 0; 

StartGame_Eatfish StartBg =null;
//通过构造方法传递窗体类和被吃鱼的初始坐标

public EatenFish(StartGame_Eatfish StartBgint eaten_xint eaten_yint m){
this.StartBg = StartBg;
if(this.m == m ){
this.eaten_x = eaten_x;
}else{
//向左游的初始坐标
this.eaten_x = 1000;
}

this.eaten_y = eaten_y;

}
public EatenFish(StartGame_Eatfish StartBg){
this.StartBg = StartBg;
}

//定义定时器
int time = 0;
//定义存储随机数变量如果随机数等于0画向右的鱼 等于1画向左的鱼
int oo = 0;

//画被吃的鱼
public void drawEatenfish(Graphics g){
if(time%(StartBg.getWidth()+100)==0){
oo = r.nextInt(2);
}
if(oo==0){
g.drawImage(smallFish_1 eaten_x eaten_y7060 StartBg);
fishmove_right();
}else if(oo==1){
g.drawImage(smallFish_2 eaten_x eaten_y 7060StartBg);
fishmove_left();
}
time++;
}

//画被吃的鱼的游动
    public void fishmove_right(){
      eaten_x +=3;
        if(eaten_x >= StartBg.getWidth()){
         StartBg.eatenfish_list.remove(this);
         eaten_x = 0;        
         }
    
     }
//画被吃的鱼的游动
    public void fishmove_left(){
     eaten_x -=3;
        if(eaten_x <= -50){
         StartBg.eatenfish_list.remove(this);
         eaten_x = 1000;        
         }
    
     }
    //返回被吃鱼的矩形区域
    public Rectangle getRectangle(){
     return new Rectangle(eaten_x eaten_y 6050);
    }
    
 }





 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        290  2011-09-22 20:03  eatfish\.classpath

     文件        383  2011-09-15 10:04  eatfish\.project

     文件     105363  2011-09-22 20:03  eatfish\bin\bin\jl1.0.1.jar

     文件       2978  2011-10-09 21:45  eatfish\bin\com\LanheIT\eatfish\start\EatenFish.class

     文件      99787  2011-09-21 15:53  eatfish\bin\com\LanheIT\eatfish\start\eatenfish_left\0.gif

     文件     155364  2011-09-21 15:53  eatfish\bin\com\LanheIT\eatfish\start\eatenfish_left\1.gif

     文件     136981  2011-09-21 15:53  eatfish\bin\com\LanheIT\eatfish\start\eatenfish_left\2.gif

     文件      99814  2011-09-21 15:52  eatfish\bin\com\LanheIT\eatfish\start\eatenfish_right\0.gif

     文件     156687  2011-09-21 15:52  eatfish\bin\com\LanheIT\eatfish\start\eatenfish_right\1.gif

     文件     136852  2011-09-21 15:52  eatfish\bin\com\LanheIT\eatfish\start\eatenfish_right\2.gif

     文件       1973  2011-09-22 20:03  eatfish\bin\com\LanheIT\eatfish\start\EatingShowPic.class

     文件      12128  2002-01-04 15:22  eatfish\bin\com\LanheIT\eatfish\start\eatShowPic\eatShowPic0.png

     文件       6380  2002-01-04 15:22  eatfish\bin\com\LanheIT\eatfish\start\eatShowPic\eatShowPic1.png

     文件       6657  2002-01-04 15:22  eatfish\bin\com\LanheIT\eatfish\start\eatShowPic\eatShowPic2.png

     文件       6818  2002-01-04 15:22  eatfish\bin\com\LanheIT\eatfish\start\eatShowPic\eatShowPic3.png

     文件       7417  2002-01-04 15:22  eatfish\bin\com\LanheIT\eatfish\start\eatShowPic\eatShowPic4.png

     文件       9152  2002-01-04 15:22  eatfish\bin\com\LanheIT\eatfish\start\eatShowPic\eatShowPic5.png

     文件       8228  2002-01-04 15:22  eatfish\bin\com\LanheIT\eatfish\start\eatShowPic\eatShowPic6.png

     文件      13242  2002-01-04 15:22  eatfish\bin\com\LanheIT\eatfish\start\eatShowPic\eatShowPic7.png

     文件       1532  2011-09-22 20:04  eatfish\bin\com\LanheIT\eatfish\start\GameSound$bgsoundThread.class

     文件       1521  2011-09-22 20:04  eatfish\bin\com\LanheIT\eatfish\start\GameSound$SoundThread.class

     文件       1063  2011-09-22 20:04  eatfish\bin\com\LanheIT\eatfish\start\GameSound.class

     文件       1436  2011-09-22 20:03  eatfish\bin\com\LanheIT\eatfish\start\GetImage.class

     文件      11019  2002-01-12 12:56  eatfish\bin\com\LanheIT\eatfish\start\left.png

     文件       5718  2011-09-15 10:48  eatfish\bin\com\LanheIT\eatfish\start\logo.png

     文件      80504  2011-09-15 10:52  eatfish\bin\com\LanheIT\eatfish\start\mainbg.jpg

     文件       3380  2011-10-09 21:40  eatfish\bin\com\LanheIT\eatfish\start\MyFish.class

     文件       1576  2011-10-09 21:39  eatfish\bin\com\LanheIT\eatfish\start\Qipao.class

     文件       1761  2011-09-16 11:22  eatfish\bin\com\LanheIT\eatfish\start\qipao.png

     文件      11062  2002-01-12 12:58  eatfish\bin\com\LanheIT\eatfish\start\right.png

............此处省略66个文件信息

评论

共有 条评论