• 大小: 192KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-06-10
  • 语言: Java
  • 标签: java  

资源简介

这个是塔防游戏的添加注释

资源截图

代码片段和文件信息

package ui;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import java.awt.image.BufferedImage;

import javax.swing.Jframe;

public class baseframe extends Jframe implements MouseMotionListener {

/**
 * 窗体宽
 */
private int w;

/**
 * 窗体长
 */
private int h;

private int gameLocationX;

private int gameLocationY;

private int gameW;

private int gameH;

private int squaresSize;

private int focusX;

private int focusY;

int x y;

public baseframe() {
init();
this.setBounds(100 100 w h);
this.setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE);
this.setVisible(true);
this.addMouseMotionListener(this);
}

private void init() {
w = 800;
h = 600;
gameLocationX = 50;
gameLocationY = 50;
gameW = 700;
gameH = 400;
focusX = -100;
focusY = -100;
squaresSize = 50;
}

public void paint(Graphics gr) {
BufferedImage image = new BufferedImage(w h
BufferedImage.TYPE_3BYTE_BGR);
Graphics g2 = image.getGraphics();
g2.setColor(Color.white);
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 14; j++) {
g2.drawRect(j * squaresSize + gameLocationX i * squaresSize
+ gameLocationY squaresSize squaresSize);
}
}
g2.setColor(Color.green);
g2.fillRect(focusX focusY squaresSize squaresSize);
gr.drawImage(image 0 0 this);

}

public static void main(String[] args) {
new baseframe();
}

public void mouseDragged(MouseEvent e) {
// TODO Auto-generated method stub

}

public void mouseMoved(MouseEvent e) {
int x = e.getX();
int y = e.getY();
if (x > gameLocationX && x < gameLocationX + gameW && y > gameLocationY
&& y < gameLocationY + gameH) {
focusX = (x - gameLocationX) / squaresSize * squaresSize
+ squaresSize;
focusY = (y - gameLocationY) / squaresSize * squaresSize
+ squaresSize;
} else {
focusX = -100;
focusY = -100;
}
repaint();
}

}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2012-12-06 14:20  tower\
     目录           0  2012-12-06 14:20  tower\TowerDefense1.1\
     文件         226  2012-12-06 14:20  tower\TowerDefense1.1\.classpath
     文件         371  2012-12-06 14:20  tower\TowerDefense1.1\.project
     目录           0  2012-12-06 14:20  tower\TowerDefense1.1\bin\
     目录           0  2012-12-06 14:20  tower\TowerDefense1.1\bin\ui\
     文件        2410  2012-12-06 14:20  tower\TowerDefense1.1\bin\ui\baseframe.class
     目录           0  2012-12-06 14:20  tower\TowerDefense1.1\src\
     目录           0  2012-12-06 14:20  tower\TowerDefense1.1\src\ui\
     文件        1972  2012-12-06 14:20  tower\TowerDefense1.1\src\ui\baseframe.java
     目录           0  2012-12-06 14:20  tower\TowerDefense1.2\
     文件         226  2012-12-06 14:20  tower\TowerDefense1.2\.classpath
     文件         371  2012-12-06 14:20  tower\TowerDefense1.2\.project
     目录           0  2012-12-06 14:20  tower\TowerDefense1.2\bin\
     目录           0  2012-12-06 14:20  tower\TowerDefense1.2\bin\control\
     文件         769  2012-12-06 14:20  tower\TowerDefense1.2\bin\control\baseControl.class
     目录           0  2012-12-06 14:20  tower\TowerDefense1.2\bin\data\
     文件        3575  2012-12-06 14:20  tower\TowerDefense1.2\bin\data\baseData.class
     文件         350  2012-12-06 14:20  tower\TowerDefense1.2\bin\data\Data.class
     目录           0  2012-12-06 14:20  tower\TowerDefense1.2\bin\model\
     文件         615  2012-12-06 14:20  tower\TowerDefense1.2\bin\model\Ball.class
     文件        2209  2012-12-06 14:20  tower\TowerDefense1.2\bin\model\Fighter.class
     目录           0  2012-12-06 14:20  tower\TowerDefense1.2\bin\thread\
     文件        1445  2012-12-06 14:20  tower\TowerDefense1.2\bin\thread\FighterThread.class
     目录           0  2012-12-06 14:20  tower\TowerDefense1.2\bin\ui\
     文件        3635  2012-12-06 14:20  tower\TowerDefense1.2\bin\ui\baseframe.class
     目录           0  2012-12-06 14:20  tower\TowerDefense1.2\src\
     目录           0  2012-12-06 14:20  tower\TowerDefense1.2\src\control\
     文件         394  2012-12-06 14:20  tower\TowerDefense1.2\src\control\baseControl.java
     目录           0  2012-12-06 14:20  tower\TowerDefense1.2\src\data\
     文件        5297  2012-12-06 14:20  tower\TowerDefense1.2\src\data\baseData.java
............此处省略240个文件信息

评论

共有 条评论