| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 435 人关注过本帖
标题:请大家帮帮忙 麻烦大家了
只看楼主 加入收藏
风影空
Rank: 1
等 级:新手上路
帖 子:73
专家分:2
注 册:2009-7-23
结帖率:75%
收藏
已结贴  问题点数:20 回复次数:1 
请大家帮帮忙 麻烦大家了
编了一个坦克 但不会发子弹  请问哪里有问题 谢谢

package com.tank;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.*;
public class MyTankGame1 extends JFrame{

    MyPanel mp=null;

    public static void main(String[] args) {
        MyTankGame1 mtk=new MyTankGame1();
    }
    public MyTankGame1()
    {
        mp=new MyPanel();
        this.addKeyListener(mp);
        this.add(mp);
        this.setSize(400,300);
        this.setTitle("坦克大战");
        this.setLocation(100, 100);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setVisible(true);
    }

}
class MyPanel extends JPanel implements KeyListener
{
    int speed=2;
    MyTank my;
    Vector<EnemyTank> et=new Vector<EnemyTank>();
    public MyPanel()
    {
        my=new MyTank(200,200,0,1);
        for(int i=0;i<3;i++)
        {
            EnemyTank eta=new EnemyTank(10+i*50, 10, 2, speed);
            et.add(eta);
        }
    }
    public void paint(Graphics g)
    {
        int i=0;
        my.setSpeed(speed);
        super.paint(g);
        g.fillRect(0, 0, 400, 300);
        this.drawTank(my.getX(), my.getY(), g, my.getDirect(),my.getType());
        for(i=0;i<et.size();i++)
        {
            this.drawTank(et.get(i).getX(), et.get(i).getY(), g, et.get(i).getDirect(), et.get(i).getType());
        }
    }
    public void drawTank(int x,int y,Graphics g,int direct,int type)
    {
        switch(type)
        {
        case 0:
            g.setColor(Color.GREEN);
            break;
        case 1:
            g.setColor(Color.GRAY);
        }
        switch(direct)
        {
        case 0:   
            g.fill3DRect(x-10,y-15, 5, 30, false);
            g.fill3DRect(x+5,y-15, 5, 30, false);
            g.fill3DRect(x-5, y-10, 10, 20,false);
            g.fillOval(x-5,y-5, 10, 10);
            g.drawLine(x, y, x, y-15);break;
        case 1:
            g.fill3DRect(x-15, y-10, 30, 5, false);
            g.fill3DRect(x-15, y+5, 30, 5, false);
            g.fill3DRect(x-10, y-5, 20, 10, false);
            g.fillOval(x-5, y-5, 10, 10);
            g.drawLine(x, y, x+15, y);break;
        case 2:
            g.fill3DRect(x-10,y-15, 5, 30, false);
            g.fill3DRect(x+5,y-15, 5, 30, false);
            g.fill3DRect(x-5, y-10, 10, 20,false);
            g.fillOval(x-5,y-5, 10, 10);
            g.drawLine(x, y, x, y+15);break;
        case 3:
            g.fill3DRect(x-15, y-10, 30, 5, false);
            g.fill3DRect(x-15, y+5, 30, 5, false);
            g.fill3DRect(x-10, y-5, 20, 10, false);
            g.fillOval(x-5, y-5, 10, 10);
            g.drawLine(x, y, x-15, y);break;
        }
    }
   
    @Override
    public void keyPressed(KeyEvent e) {
        // TODO Auto-generated method stub
        if(e.getKeyCode()==KeyEvent.VK_DOWN)
        {
            my.moveDown();
            this.repaint();
        }else if(e.getKeyCode()==KeyEvent.VK_UP)
        {
            my.moveUp();
            this.repaint();
        }else if(e.getKeyCode()==KeyEvent.VK_LEFT)
        {
            my.moveLeft();
            this.repaint();
        }else if(e.getKeyCode()==KeyEvent.VK_RIGHT)
        {
            my.moveRight();
            this.repaint();
        }
    }
    @Override
    public void keyReleased(KeyEvent e) {
        // TODO Auto-generated method stub
        
    }
    @Override
    public void keyTyped(KeyEvent e) {
        // TODO Auto-generated method stub
        
    }
}

搜索更多相关主题的帖子: 麻烦 
2010-05-03 11:25
lanyu111
该用户已被删除
收藏
得分:14 
提示: 作者被禁止或删除 内容自动屏蔽
2010-05-03 17:01
快速回复:请大家帮帮忙 麻烦大家了
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.042302 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved