在这里也感谢CSDN的朋友们的帮忙。
package dandan;
import java.util.*;
import javax.swing.JOptionPane;
public class dandanModel extends Observable implements Runnable
{
private int i=0; private int i2=100; private Node nodeArray;
//i是用来计数炸弹共落下去了多少次,然后用它来判断是否要落下炸弹。i2是用来控制sleep()了多少
//秒的,通过它可以改变关数。nodeArray是QQ头像的标记体。
private Node nodeFood; private Node nodeFood1; private Node nodeFood2;
private Node nodeplane1; private Node nodeplane2; private Node nodeplane3;
//nodeFood是用来表示炸弹nodeplane1是用来表示飞机
private boolean running=true;
//标记是在运行当中
public dandanModel()
{ reset(); }//构造函数
public void reset()//定义了炸弹,飞机和QQ头像的初始位置
{ nodeArray=new Node(300,200); nodeFood=new Node(15,300);
nodeFood1=new Node(300,15); nodeFood2=new Node(440,15);
nodeplane1=new Node(10,300); nodeplane2=new Node(300,10);
nodeplane3=new Node(440,10); }
public void changeDirection(int maX,int maY)
{ nodeArray=new Node(maX,maY); }//创建新的QQ头像位置
public Node getCreat()//通过这个函数来让外部调用炸弹
{ return nodeFood; }
public Node getCreat1()
{ return nodeFood1;}
public Node getCreat2()
{ return nodeFood2;}
public Node getplane1()
{ return nodeplane1; }
public Node getplane2()
{ return nodeplane2; }
public Node getplane3()
{ return nodeplane3; }
public boolean moveOn()//这个函数是用来判断是否QQ被炸,进入下一关
{ moveFood();
//通过判断坐标范围来判断QQ头像是否被子炸
boolean
b1=((nodeArray.x<=nodeFood.x&&nodeFood.x<=nodeArray.x+20)||(nodeArray.x<=nodeFood.x+10&&nodeFood.x+10<=nodeArray.x+20));
boolean b2=((nodeArray.y<=nodeFood.y&&nodeFood.y<=nodeArray.y+20)||(nodeArray.y<=nodeFood.y+10&&nodeFood.y+10<=nodeArray.y+20));
boolean b3=((nodeArray.x<=nodeFood1.x&&nodeFood1.x<=nodeArray.x+20)||(nodeArray.x<=nodeFood1.x+10&&nodeFood1.x+10<=nodeArray.x+20));
boolean b4=((nodeArray.y<=nodeFood1.y&&nodeFood1.y<=nodeArray.y+20)||(nodeArray.y<=nodeFood1.y+10&&nodeFood1.y+10<=nodeArray.y+20));
boolean b5=((nodeArray.x<=nodeFood2.x&&nodeFood2.x<=nodeArray.x+20)||(nodeArray.x<=nodeFood2.x+10&&nodeFood2.x+10<=nodeArray.x+20));
boolean b6=((nodeArray.y<=nodeFood2.y&&nodeFood2.y<=nodeArray.y+20)||(nodeArray.y<=nodeFood2.y+10&&nodeFood2.y+10<=nodeArray.y+20));
if(b1==true&&b2==true)
{ new zhadanMusic();
JOptionPane.showMessageDialog(null,"continue the game?","Game over",JOptionPane.INFORMATION_MESSAGE);
return false;}
if(b3==true&&b4==true)
{ new zhadanMusic();
JOptionPane.showMessageDialog(null,"continue the game?","Game over",JOptionPane.INFORMATION_MESSAGE);
return false;}
if(b5==true&&b6==true)
{ new zhadanMusic();
JOptionPane.showMessageDialog(null,"continue thegame?","Gameover",JOptionPane.INFORMATION_MESSAGE);
return false; }
return true;
}
//这个函数是用来改变飞机,炸弹的坐标位置
private void moveFood( )
{
if(i2==0)
{JOptionPane.showMessageDialog(null,"已经通关","恭喜",JOptionPane.INFORMATION_MESSAGE);
i2=100; }
if(i%150==0&&i>1)
{JOptionPane.showMessageDialog(null,"进入下一关?","恭喜",JOptionPane.INFORMATION_MESSAGE);
i2-=20; }
try {Thread.sleep(i2);}catch(Exception e) {}
if(i%30==0) nodeFood1.x+=40;
if(nodeFood1.x>=440) nodeFood1.x=15;
nodeplane2.x=nodeFood1.x;
nodeFood1.y+=20;
if(nodeFood1.y>=430) nodeFood1.y=15;
if(nodeFood2.x<=10) nodeFood2.x=440;
nodeFood2.x-=20; nodeplane3.x=nodeFood2.x; nodeFood2.y+=20;
if(nodeFood2.y>=440) nodeFood2.y=15;
if(i%30==0) nodeFood2.y+=40;
if(i%20==0)
{ nodeFood1.y+=40; nodeplane1.y+=20; nodeFood.y+=20;}
if(nodeFood.y>=430) nodeFood.y=10;
nodeFood.x+=10; nodeplane1.y=nodeFood.y;
if(nodeFood.x>=430) nodeFood.x=15;
++i;
}
//函数来实现与view的通信,以便即时更新数据
public void run()
{ while(running)
{ try{ Thread.sleep(100);}catch(Exception e){ break;}
if(moveOn()){ setChanged(); notifyObservers(); }
}
}
public Node getNodeArray()
{ return this.nodeArray; }
}
//返回Node类型物体的坐标位置
class Node
{ int x;int y;
Node(int x,int y)
{ this.x=x; this.y=y; }
}
11 个解决方案
#1
package dandan;
import java.awt.*;
import java.util.*;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class dandanView extends JFrame implements Observer
{ private static final long serialVersionUID = 8014891002972628653L;
public static final int nodeWidth=30;
public static final int nodeHeight=30;
//QQ头像的大小
private int canvasWidth; private int canvasHeight; //画布的大小
Image ima,img1,img2,img3; //图片
Canvas paintCanvas;//创建画布
Toolkit tk=Toolkit.getDefaultToolkit(); JLabel labelmain;
//用来获得图片的源文件,顶部标签
public dandanView()
{ this(30,40,0,0); }
//默认的构造函数
public dandanView(int maxX,int maxY)
{ this(maxX,maxY,0,0); }
//带参数的构造方法
public dandanView(int maxX,int maxY,int startY,int startX)
{ this.canvasHeight=maxX*15; this.canvasWidth=maxY*15; init(); }
//带参数的构造方法
//初始化视图
private void init()
{ this.setName("蛋蛋快跑");
this.setLocation(0,0);Container cp=this.getContentPane();
//创建顶部文字
labelmain=new JLabel("制作人:赵峰 用鼠标左标点着QQ,快跑,避过炸弹");
cp.add(labelmain,BorderLayout.NORTH);
//创建中间游戏显示区域
paintCanvas=new Canvas();
paintCanvas.setSize(canvasWidth+1,canvasHeight+1); cp.add(paintCanvas,BorderLayout.CENTER);
ima=tk.getImage("back.jpg"); img1=tk.getImage("13.gif");
img2=tk.getImage("70.gif"); img3=tk.getImage("plane.gif");
this.pack(); this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);this.setVisible(true); }
//实现Observer接口定义的update方法
public void update(Observable o,Object arg)
{ dandanModel model=(dandanModel)o;//获取被监控的模型
Graphics g=paintCanvas.getGraphics(); //获得画笔
g.drawImage(ima,0,0,canvasWidth,canvasHeight,this);//画背景
Node head = model.getNodeArray(); drawNode(g, head); //添加QQ头象
Node p1=model.getplane1();drawPlane(g,p1);// 添加飞机画片
Node p2=model.getplane2();drawPlane(g,p2);
Node p3=model.getplane3();drawPlane(g,p3);
Node n=model.getCreat(); drawFood(g,n);//添加炸弹的图片
Node n1=model.getCreat1();drawFood(g,n1);
Node n2=model.getCreat2();drawFood(g,n2); }
private void drawNode(Graphics g,Node n)//添加QQ头象
{ g.drawImage(img1,n.x,n.y,30,30,this); }
private void drawFood(Graphics g,Node n)//添加炸弹的图片
{ g.drawImage(img2,n.x,n.y,10,10,this); }
private void drawPlane(Graphics g,Node n)// 添加飞机画片
{ g.drawImage(img3,n.x,n.y,30,30,this); }
}
package dandan;
import java.awt.event.*;
public class dandanControl implements MouseMotionListener
{
private dandanModel model;//待控制的QQ头像 private dandanView view;//视图对象
private int district_maxX; private int district_maxY;//创建画布的大小
public dandanControl()//创建默认的构造方法
{ this.district_maxX=30; this.district_maxY=40;}
public dandanControl(int maxX,int maxY)//带参数的构造方法
{ this();
this.district_maxX=maxX; this.district_maxY=maxY;
//初始化程序
init(); }
private void init()
{ this.model=new dandanModel();//创建model的模型
//创建视图
this.view=new dandanView(district_maxX,district_maxY,500,200);
//为模型添加视图,当模型改变时,能够通知视图
this.model.addObserver(this.view);
//为视图添加鼠标事件
this.view.paintCanvas.addMouseMotionListener(this);
//model开始运动
(new Thread(this.model)).start();
//背景音乐
new backmusic();
}
//鼠标事件
public void mouseDragged(MouseEvent e)
{ //new deyiMusic();
int X=(int)e.getX(); int Y=(int)e.getY();
if(X<=20) X=20;
if(Y<=20) Y=20;
model.changeDirection(X,Y);
}
public void mouseMoved(MouseEvent e) {}
}
package dandan;
public class dandanMain
{
public static void main(String [] args)
{
new dandanControl(30,30);
}
}
package dandan;
import sun.audio.*; //import the sun.audio package
import java.io.*;
public class backmusic{
public backmusic(){
try{//循环播放声音
InputStream in = new FileInputStream("29.wav");
AudioStream as = new AudioStream(in);
AudioData data = as.getData();
ContinuousAudioDataStream gg= new ContinuousAudioDataStream (data);
AudioPlayer.player.start(gg);// Play audio.
}catch(FileNotFoundException e){
System.out.print("FileNotFoundException 1");
}
catch(IOException e){
System.out.print("有错误!");}
}
}
package dandan;
import sun.audio.*; //import the sun.audio package
import java.io.*;
public class zhadanMusic{
public zhadanMusic(){
try{// 播放声音一次
InputStream in = new FileInputStream("bomb_001.wav");
AudioStream as = new AudioStream(in);
AudioData data = as.getData();
ContinuousAudioDataStream gg= new ContinuousAudioDataStream (data);
AudioPlayer.player.start(gg);// Play audio.
try
{ Thread.sleep(500); }catch(Exception e){}
AudioPlayer.player.stop (gg); // 停止
}catch(FileNotFoundException e){
System.out.print("FileNotFoundException 1");
}
catch(IOException e){ System.out.print("有错误!");}
}
//public static void main(String arg[]){
//new music();
//}
}
package dandan;
import sun.audio.*; //import the sun.audio package
import java.io.*;
public class deyiMusic{
public deyiMusic(){
try{//循环播放声音
InputStream in = new FileInputStream("29.wav");
AudioStream as = new AudioStream(in);
AudioData data = as.getData();
ContinuousAudioDataStream gg= new ContinuousAudioDataStream (data);
AudioPlayer.player.start(gg);// Play audio.
}catch(FileNotFoundException e){
System.out.print("FileNotFoundException 1");
}catch(IOException e){System.out.print("有错误!");}
} }
#2
package dandan;
import java.awt.*;
import java.util.*;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class dandanView extends JFrame implements Observer
{ private static final long serialVersionUID = 8014891002972628653L;
public static final int nodeWidth=30;
public static final int nodeHeight=30;
//QQ头像的大小
private int canvasWidth; private int canvasHeight; //画布的大小
Image ima,img1,img2,img3; //图片
Canvas paintCanvas;//创建画布
Toolkit tk=Toolkit.getDefaultToolkit(); JLabel labelmain;
//用来获得图片的源文件,顶部标签
public dandanView()
{ this(30,40,0,0); }
//默认的构造函数
public dandanView(int maxX,int maxY)
{ this(maxX,maxY,0,0); }
//带参数的构造方法
public dandanView(int maxX,int maxY,int startY,int startX)
{ this.canvasHeight=maxX*15; this.canvasWidth=maxY*15; init(); }
//带参数的构造方法
//初始化视图
private void init()
{ this.setName("蛋蛋快跑");
this.setLocation(0,0);Container cp=this.getContentPane();
//创建顶部文字
labelmain=new JLabel("制作人:赵峰 用鼠标左标点着QQ,快跑,避过炸弹");
cp.add(labelmain,BorderLayout.NORTH);
//创建中间游戏显示区域
paintCanvas=new Canvas();
paintCanvas.setSize(canvasWidth+1,canvasHeight+1); cp.add(paintCanvas,BorderLayout.CENTER);
ima=tk.getImage("back.jpg"); img1=tk.getImage("13.gif");
img2=tk.getImage("70.gif"); img3=tk.getImage("plane.gif");
this.pack(); this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);this.setVisible(true); }
//实现Observer接口定义的update方法
public void update(Observable o,Object arg)
{ dandanModel model=(dandanModel)o;//获取被监控的模型
Graphics g=paintCanvas.getGraphics(); //获得画笔
g.drawImage(ima,0,0,canvasWidth,canvasHeight,this);//画背景
Node head = model.getNodeArray(); drawNode(g, head); //添加QQ头象
Node p1=model.getplane1();drawPlane(g,p1);// 添加飞机画片
Node p2=model.getplane2();drawPlane(g,p2);
Node p3=model.getplane3();drawPlane(g,p3);
Node n=model.getCreat(); drawFood(g,n);//添加炸弹的图片
Node n1=model.getCreat1();drawFood(g,n1);
Node n2=model.getCreat2();drawFood(g,n2); }
private void drawNode(Graphics g,Node n)//添加QQ头象
{ g.drawImage(img1,n.x,n.y,30,30,this); }
private void drawFood(Graphics g,Node n)//添加炸弹的图片
{ g.drawImage(img2,n.x,n.y,10,10,this); }
private void drawPlane(Graphics g,Node n)// 添加飞机画片
{ g.drawImage(img3,n.x,n.y,30,30,this); }
}
package dandan;
import java.awt.event.*;
public class dandanControl implements MouseMotionListener
{
private dandanModel model;//待控制的QQ头像 private dandanView view;//视图对象
private int district_maxX; private int district_maxY;//创建画布的大小
public dandanControl()//创建默认的构造方法
{ this.district_maxX=30; this.district_maxY=40;}
public dandanControl(int maxX,int maxY)//带参数的构造方法
{ this();
this.district_maxX=maxX; this.district_maxY=maxY;
//初始化程序
init(); }
private void init()
{ this.model=new dandanModel();//创建model的模型
//创建视图
this.view=new dandanView(district_maxX,district_maxY,500,200);
//为模型添加视图,当模型改变时,能够通知视图
this.model.addObserver(this.view);
//为视图添加鼠标事件
this.view.paintCanvas.addMouseMotionListener(this);
//model开始运动
(new Thread(this.model)).start();
//背景音乐
new backmusic();
}
//鼠标事件
public void mouseDragged(MouseEvent e)
{ //new deyiMusic();
int X=(int)e.getX(); int Y=(int)e.getY();
if(X<=20) X=20;
if(Y<=20) Y=20;
model.changeDirection(X,Y);
}
public void mouseMoved(MouseEvent e) {}
}
package dandan;
public class dandanMain
{
public static void main(String [] args)
{
new dandanControl(30,30);
}
}
#3
希望各位多多指点
#4
提点建议:
类名不妨以大写字母开头
类名不妨以大写字母开头
#5
能否共享一下那几个image和Music……
#6
可以,发到你邮箱里
#7
bhucuo a
#8
#9
顶,代码挺规范的,发帖挺规范的,提问也是种学问呵呵
LZ发一份给我吧
57969966@qq.com
LZ发一份给我吧
57969966@qq.com
#10
看着你在不断的进步,我很高兴,但是现在,不希望你因为那个小游戏就得意或者不思进取。我希望你可以探讨(研究)的深一点。因为,那样会让你长好多知识,而且能提高你的编程能力,你自己也应该清楚。今天说这个说的有点多,担心你会烦。但还是想说,说明我的想法。
不过你自己看着做吧,怎么对你自己好就怎么做。
不过你自己看着做吧,怎么对你自己好就怎么做。
#11
不错收藏了 ~@^_^@~
#1
package dandan;
import java.awt.*;
import java.util.*;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class dandanView extends JFrame implements Observer
{ private static final long serialVersionUID = 8014891002972628653L;
public static final int nodeWidth=30;
public static final int nodeHeight=30;
//QQ头像的大小
private int canvasWidth; private int canvasHeight; //画布的大小
Image ima,img1,img2,img3; //图片
Canvas paintCanvas;//创建画布
Toolkit tk=Toolkit.getDefaultToolkit(); JLabel labelmain;
//用来获得图片的源文件,顶部标签
public dandanView()
{ this(30,40,0,0); }
//默认的构造函数
public dandanView(int maxX,int maxY)
{ this(maxX,maxY,0,0); }
//带参数的构造方法
public dandanView(int maxX,int maxY,int startY,int startX)
{ this.canvasHeight=maxX*15; this.canvasWidth=maxY*15; init(); }
//带参数的构造方法
//初始化视图
private void init()
{ this.setName("蛋蛋快跑");
this.setLocation(0,0);Container cp=this.getContentPane();
//创建顶部文字
labelmain=new JLabel("制作人:赵峰 用鼠标左标点着QQ,快跑,避过炸弹");
cp.add(labelmain,BorderLayout.NORTH);
//创建中间游戏显示区域
paintCanvas=new Canvas();
paintCanvas.setSize(canvasWidth+1,canvasHeight+1); cp.add(paintCanvas,BorderLayout.CENTER);
ima=tk.getImage("back.jpg"); img1=tk.getImage("13.gif");
img2=tk.getImage("70.gif"); img3=tk.getImage("plane.gif");
this.pack(); this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);this.setVisible(true); }
//实现Observer接口定义的update方法
public void update(Observable o,Object arg)
{ dandanModel model=(dandanModel)o;//获取被监控的模型
Graphics g=paintCanvas.getGraphics(); //获得画笔
g.drawImage(ima,0,0,canvasWidth,canvasHeight,this);//画背景
Node head = model.getNodeArray(); drawNode(g, head); //添加QQ头象
Node p1=model.getplane1();drawPlane(g,p1);// 添加飞机画片
Node p2=model.getplane2();drawPlane(g,p2);
Node p3=model.getplane3();drawPlane(g,p3);
Node n=model.getCreat(); drawFood(g,n);//添加炸弹的图片
Node n1=model.getCreat1();drawFood(g,n1);
Node n2=model.getCreat2();drawFood(g,n2); }
private void drawNode(Graphics g,Node n)//添加QQ头象
{ g.drawImage(img1,n.x,n.y,30,30,this); }
private void drawFood(Graphics g,Node n)//添加炸弹的图片
{ g.drawImage(img2,n.x,n.y,10,10,this); }
private void drawPlane(Graphics g,Node n)// 添加飞机画片
{ g.drawImage(img3,n.x,n.y,30,30,this); }
}
package dandan;
import java.awt.event.*;
public class dandanControl implements MouseMotionListener
{
private dandanModel model;//待控制的QQ头像 private dandanView view;//视图对象
private int district_maxX; private int district_maxY;//创建画布的大小
public dandanControl()//创建默认的构造方法
{ this.district_maxX=30; this.district_maxY=40;}
public dandanControl(int maxX,int maxY)//带参数的构造方法
{ this();
this.district_maxX=maxX; this.district_maxY=maxY;
//初始化程序
init(); }
private void init()
{ this.model=new dandanModel();//创建model的模型
//创建视图
this.view=new dandanView(district_maxX,district_maxY,500,200);
//为模型添加视图,当模型改变时,能够通知视图
this.model.addObserver(this.view);
//为视图添加鼠标事件
this.view.paintCanvas.addMouseMotionListener(this);
//model开始运动
(new Thread(this.model)).start();
//背景音乐
new backmusic();
}
//鼠标事件
public void mouseDragged(MouseEvent e)
{ //new deyiMusic();
int X=(int)e.getX(); int Y=(int)e.getY();
if(X<=20) X=20;
if(Y<=20) Y=20;
model.changeDirection(X,Y);
}
public void mouseMoved(MouseEvent e) {}
}
package dandan;
public class dandanMain
{
public static void main(String [] args)
{
new dandanControl(30,30);
}
}
package dandan;
import sun.audio.*; //import the sun.audio package
import java.io.*;
public class backmusic{
public backmusic(){
try{//循环播放声音
InputStream in = new FileInputStream("29.wav");
AudioStream as = new AudioStream(in);
AudioData data = as.getData();
ContinuousAudioDataStream gg= new ContinuousAudioDataStream (data);
AudioPlayer.player.start(gg);// Play audio.
}catch(FileNotFoundException e){
System.out.print("FileNotFoundException 1");
}
catch(IOException e){
System.out.print("有错误!");}
}
}
package dandan;
import sun.audio.*; //import the sun.audio package
import java.io.*;
public class zhadanMusic{
public zhadanMusic(){
try{// 播放声音一次
InputStream in = new FileInputStream("bomb_001.wav");
AudioStream as = new AudioStream(in);
AudioData data = as.getData();
ContinuousAudioDataStream gg= new ContinuousAudioDataStream (data);
AudioPlayer.player.start(gg);// Play audio.
try
{ Thread.sleep(500); }catch(Exception e){}
AudioPlayer.player.stop (gg); // 停止
}catch(FileNotFoundException e){
System.out.print("FileNotFoundException 1");
}
catch(IOException e){ System.out.print("有错误!");}
}
//public static void main(String arg[]){
//new music();
//}
}
package dandan;
import sun.audio.*; //import the sun.audio package
import java.io.*;
public class deyiMusic{
public deyiMusic(){
try{//循环播放声音
InputStream in = new FileInputStream("29.wav");
AudioStream as = new AudioStream(in);
AudioData data = as.getData();
ContinuousAudioDataStream gg= new ContinuousAudioDataStream (data);
AudioPlayer.player.start(gg);// Play audio.
}catch(FileNotFoundException e){
System.out.print("FileNotFoundException 1");
}catch(IOException e){System.out.print("有错误!");}
} }
#2
package dandan;
import java.awt.*;
import java.util.*;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class dandanView extends JFrame implements Observer
{ private static final long serialVersionUID = 8014891002972628653L;
public static final int nodeWidth=30;
public static final int nodeHeight=30;
//QQ头像的大小
private int canvasWidth; private int canvasHeight; //画布的大小
Image ima,img1,img2,img3; //图片
Canvas paintCanvas;//创建画布
Toolkit tk=Toolkit.getDefaultToolkit(); JLabel labelmain;
//用来获得图片的源文件,顶部标签
public dandanView()
{ this(30,40,0,0); }
//默认的构造函数
public dandanView(int maxX,int maxY)
{ this(maxX,maxY,0,0); }
//带参数的构造方法
public dandanView(int maxX,int maxY,int startY,int startX)
{ this.canvasHeight=maxX*15; this.canvasWidth=maxY*15; init(); }
//带参数的构造方法
//初始化视图
private void init()
{ this.setName("蛋蛋快跑");
this.setLocation(0,0);Container cp=this.getContentPane();
//创建顶部文字
labelmain=new JLabel("制作人:赵峰 用鼠标左标点着QQ,快跑,避过炸弹");
cp.add(labelmain,BorderLayout.NORTH);
//创建中间游戏显示区域
paintCanvas=new Canvas();
paintCanvas.setSize(canvasWidth+1,canvasHeight+1); cp.add(paintCanvas,BorderLayout.CENTER);
ima=tk.getImage("back.jpg"); img1=tk.getImage("13.gif");
img2=tk.getImage("70.gif"); img3=tk.getImage("plane.gif");
this.pack(); this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);this.setVisible(true); }
//实现Observer接口定义的update方法
public void update(Observable o,Object arg)
{ dandanModel model=(dandanModel)o;//获取被监控的模型
Graphics g=paintCanvas.getGraphics(); //获得画笔
g.drawImage(ima,0,0,canvasWidth,canvasHeight,this);//画背景
Node head = model.getNodeArray(); drawNode(g, head); //添加QQ头象
Node p1=model.getplane1();drawPlane(g,p1);// 添加飞机画片
Node p2=model.getplane2();drawPlane(g,p2);
Node p3=model.getplane3();drawPlane(g,p3);
Node n=model.getCreat(); drawFood(g,n);//添加炸弹的图片
Node n1=model.getCreat1();drawFood(g,n1);
Node n2=model.getCreat2();drawFood(g,n2); }
private void drawNode(Graphics g,Node n)//添加QQ头象
{ g.drawImage(img1,n.x,n.y,30,30,this); }
private void drawFood(Graphics g,Node n)//添加炸弹的图片
{ g.drawImage(img2,n.x,n.y,10,10,this); }
private void drawPlane(Graphics g,Node n)// 添加飞机画片
{ g.drawImage(img3,n.x,n.y,30,30,this); }
}
package dandan;
import java.awt.event.*;
public class dandanControl implements MouseMotionListener
{
private dandanModel model;//待控制的QQ头像 private dandanView view;//视图对象
private int district_maxX; private int district_maxY;//创建画布的大小
public dandanControl()//创建默认的构造方法
{ this.district_maxX=30; this.district_maxY=40;}
public dandanControl(int maxX,int maxY)//带参数的构造方法
{ this();
this.district_maxX=maxX; this.district_maxY=maxY;
//初始化程序
init(); }
private void init()
{ this.model=new dandanModel();//创建model的模型
//创建视图
this.view=new dandanView(district_maxX,district_maxY,500,200);
//为模型添加视图,当模型改变时,能够通知视图
this.model.addObserver(this.view);
//为视图添加鼠标事件
this.view.paintCanvas.addMouseMotionListener(this);
//model开始运动
(new Thread(this.model)).start();
//背景音乐
new backmusic();
}
//鼠标事件
public void mouseDragged(MouseEvent e)
{ //new deyiMusic();
int X=(int)e.getX(); int Y=(int)e.getY();
if(X<=20) X=20;
if(Y<=20) Y=20;
model.changeDirection(X,Y);
}
public void mouseMoved(MouseEvent e) {}
}
package dandan;
public class dandanMain
{
public static void main(String [] args)
{
new dandanControl(30,30);
}
}
#3
希望各位多多指点
#4
提点建议:
类名不妨以大写字母开头
类名不妨以大写字母开头
#5
能否共享一下那几个image和Music……
#6
可以,发到你邮箱里
#7
bhucuo a
#8
#9
顶,代码挺规范的,发帖挺规范的,提问也是种学问呵呵
LZ发一份给我吧
57969966@qq.com
LZ发一份给我吧
57969966@qq.com
#10
看着你在不断的进步,我很高兴,但是现在,不希望你因为那个小游戏就得意或者不思进取。我希望你可以探讨(研究)的深一点。因为,那样会让你长好多知识,而且能提高你的编程能力,你自己也应该清楚。今天说这个说的有点多,担心你会烦。但还是想说,说明我的想法。
不过你自己看着做吧,怎么对你自己好就怎么做。
不过你自己看着做吧,怎么对你自己好就怎么做。
#11
不错收藏了 ~@^_^@~