好文档 - 专业文书写作范文服务资料分享网站

飞机大战java源代码

天下 分享 时间: 加入收藏 我要投稿 点赞

package ;

import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import java.awt.Image; import java.awt.Rectangle;

import java.awt.event.KeyEvent; import java.io.IOException;

import javax.imageio.ImageIO;

public class Plane {

Image feijiImage = null; int x = 300; int y = 700; int lifeCount=5; public Plane() { try {

feijiImage = ImageIO.read(Plane.class.getClassLoader() .getResourceAsStream(\ } catch (IOException e) { e.printStackTrace(); } }

public void draw(Graphics g) { // 画飞机图片

g.drawImage(feijiImage, x, y, null); // 飞机移动

this.move(); // 血条

if(lifeCount>0){

g.setColor(Color.WHITE); g.fillRect(20, 80, 100, 10); g.setColor(Color.red);

g.fillRect(20, 80, (100/5)*lifeCount, 10); g.setColor(Color.blue);

g.setFont(new Font(\幼圆\ g.drawString(\ } }

// // // // // // // //

public void move(){

if(isUP && !isDown && !isLeft && !isRight){ 上 y=y-5;

}else if(!isUP && isDown && !isLeft && !isRight){ 下 y=y+5;

}else if(!isUP && !isDown && isLeft && !isRight){ 左 x=x-5;

}else if(!isUP && !isDown && !isLeft && isRight){ 右 x=x+5;

}else if(isUP && !isDown && isLeft && !isRight){ 左上 x=x-5; y=y-5;

}else if(!isUP && isDown && isLeft && !isRight){ 左下 x=x-5; y=y+5;

}else if(isUP && !isDown && !isLeft && isRight){ 右上 x=x+5; y=y-5;

}else if(!isUP && isDown && !isLeft && isRight){ 右下 x=x+5; y=y+5; } }

boolean isUP = false; boolean isDown = false; boolean isLeft = false; boolean isRight = false;

// 摁下

public void keyPressed(KeyEvent e) {

int keyCode = e.getKeyCode();

if (keyCode == KeyEvent.VK_RIGHT || keyCode == KeyEvent.VK_D) { isRight=true;

} else if (keyCode == KeyEvent.VK_LEFT || keyCode == KeyEvent.VK_A) { isLeft=true;

} else if (keyCode == KeyEvent.VK_UP || keyCode == KeyEvent.VK_W) { isUP=true;

} else if (keyCode == KeyEvent.VK_DOWN || keyCode == KeyEvent.VK_S) { isDown=true; } }

// 放开

public void keyReleased(KeyEvent e) { int keyCode = e.getKeyCode();

if (keyCode == KeyEvent.VK_RIGHT || keyCode == KeyEvent.VK_D) { isRight=false;

} else if (keyCode == KeyEvent.VK_LEFT || keyCode == KeyEvent.VK_A) { isLeft=false;

} else if (keyCode == KeyEvent.VK_UP || keyCode == KeyEvent.VK_W) { isUP=false;

} else if (keyCode == KeyEvent.VK_DOWN || keyCode == KeyEvent.VK_S) { isDown=false; } }

public Rectangle getRectangle(){ return new Rectangle(x,y,feijiImage.getWidth(null),feijiImage.getHeight(null)); } }

package ;

public class PlaneStatus {

public static int roleNum = 1;

public static int playStatus = 0;// 0 游戏开始前 1 第一关 -1 游戏结束 }

package ;

import java.awt.Graphics;

import java.awt.Image; import java.awt.Rectangle;

import java.awt.event.KeyEvent; import java.io.IOException;

import javax.imageio.ImageIO;

public class Power {

Image PowerImage = null; int x = 20; int y = 0;

public Power() {

this.x=(int)(Math.random()*540)+20; try {

PowerImage = ImageIO.read(Gift.class.getClassLoader() .getResourceAsStream(\ } catch (IOException e) { e.printStackTrace(); } }

public void draw(Graphics g) { // 画血瓶图片

g.drawImage(PowerImage, x, y, null); // 血瓶移动 y++; }

public Rectangle getRectangle(){ return

Rectangle(x,y,PowerImage.getWidth(null),PowerImage.getHeight(null)); } }

package ;

import java.awt.Graphics; import java.awt.Image;

new

import java.awt.Rectangle;

import java.awt.event.KeyEvent; import java.io.IOException; import java.util.ArrayList; import java.util.List;

import javax.imageio.ImageIO;

// 第一关

public class Play01 {

static int count=0;

Image bgImage = null;

// 战机

Plane plane = new Plane(); // 战机子弹

List mzds = new ArrayList(); // 敌机

List dijis = new ArrayList(); // 敌机子弹

//List dijizidans = new ArrayList(); // 血瓶

List gifts = new ArrayList(); List powers = new ArrayList(); public Play01() { try {

bgImage = ImageIO.read(Play01.class.getClassLoader() .getResourceAsStream(\ } catch (IOException e) { e.printStackTrace(); } }

int bgY1 = 0; int bgY2 = -600; int fireTime = 0; boolean flag=false;

public void draw(Graphics g) { // 画背景图片

飞机大战java源代码

package;importjava.awt.Color;importjava.awt.Font;importjava.awt.Graphics;importjava.awt.Image;importjava.awt.Rectangle;importjava.awt.event.KeyEvent;importjava
推荐度:
点击下载文档文档为doc格式
22lxs8boqj4n7xz5eecp3x5if1klf700avp
领取福利

微信扫码领取福利

微信扫码分享