资源简介

Java Swing开发的《星际争霸》游戏

资源截图

代码片段和文件信息

package core;

import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;

import javax.swing.KeyStroke;
/**
 * 用户交互控制
 * @author Administrator
 */
public class Control {

private int x y dx dy width height;

private boolean dragged moveing;

private Component component;

private ControlDragListener dragLister = new ControlDragListener();

private ControlMoveListener moveLister = new ControlMoveListener();

private ControlKeyListener keyLister = new ControlKeyListener();

private DragListener dragListener;

private MoveListener moveListener;

private LeftPressListener leftPressListener;

private RightPressListener rightPressListener;

private KeyPressListener keyPressListener;


public static final int LEFT_MOUSE = 1;

public static final int RIGHT_MOUSE = 3;
  
public Control(Component mouseComponentComponent keyComponent) {

this.component = mouseComponent;
component.addMouseListener(dragLister);
component.addMouseMotionListener(moveLister);
keyComponent.addKeyListener(keyLister);
}


public void drag(Graphics g) {

if (dragged && moveing) {
g.setColor(Color.red);
width = Math.abs(dx - x);
height = Math.abs(dy - y);
g.drawRect(Math.min(x dx) Math.min(y dy) width height);
}
}
/**
 * 新增鼠标拖放回调
 * @param dragCallBack
 */
public Control addDragListener(DragListener dragCallBack){
this.dragListener = dragCallBack;
return this;
}
/**
 * 新增鼠标移动回调
 * @param moveListener
 * @return
 */
public Control addMoveListener(MoveListener moveListener){
this.moveListener = moveListener;
return this;
}

public Control addLeftPressListener(LeftPressListener selectCallBack){
this.leftPressListener = selectCallBack;
return this;
}

public Control addRightPressListener(RightPressListener selectCallBack){
this.rightPressListener = selectCallBack;
return this;
}

public Control addKeyPressListener(KeyPressListener keyPressListener){
this.keyPressListener = keyPressListener;
return this;
}

 
/**
 * 内部类,处理鼠标点击
 */
private class ControlDragListener extends MouseAdapter {

public void mousePressed(MouseEvent e) {

//如果是左键
if(e.getButton()==LEFT_MOUSE){
x = e.getX();
y = e.getY();
dragged = true;

if(leftPressListener!=null){
leftPressListener.press(x y);
}
//如果是右键
} else if(e.getButton()==RIGHT_MOUSE){

if(rightPressListener!=null){
// System.out.println(e.getX()+““+e.getY());
rightPressListener.press(e.getX() e.getY());
}
}
}


public void mouseReleased(MouseEvent e) {

//如果需要有回调
if(dragListener!=null&&dragged&&moveing){

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2016-08-26 15:23  StarCraft-Java Swing\
     目录           0  2010-08-05 14:56  StarCraft-Java Swing\Swing星际争霸\
     目录           0  2010-08-05 14:57  StarCraft-Java Swing\Swing星际争霸\source\
     文件         274  2009-02-17 19:26  StarCraft-Java Swing\Swing星际争霸\source\.classpath
     文件         379  2009-02-24 17:49  StarCraft-Java Swing\Swing星际争霸\source\.project
     目录           0  2009-03-22 15:19  StarCraft-Java Swing\Swing星际争霸\source\.settings\
     目录           0  2009-05-06 13:41  StarCraft-Java Swing\Swing星际争霸\source\bin\
     目录           0  2009-04-23 15:02  StarCraft-Java Swing\Swing星际争霸\source\bin\core\
     文件        2096  2009-05-05 13:05  StarCraft-Java Swing\Swing星际争霸\source\bin\core\Control$ControlDragListener.class
     文件        1261  2009-05-05 13:05  StarCraft-Java Swing\Swing星际争霸\source\bin\core\Control$ControlKeyListener.class
     文件        1434  2009-05-05 13:05  StarCraft-Java Swing\Swing星际争霸\source\bin\core\Control$ControlMoveListener.class
     文件         202  2009-05-05 13:05  StarCraft-Java Swing\Swing星际争霸\source\bin\core\Control$DragListener.class
     文件         208  2009-05-05 13:05  StarCraft-Java Swing\Swing星际争霸\source\bin\core\Control$KeyPressListener.class
     文件         211  2009-05-05 13:05  StarCraft-Java Swing\Swing星际争霸\source\bin\core\Control$LeftPressListener.class
     文件         200  2009-05-05 13:05  StarCraft-Java Swing\Swing星际争霸\source\bin\core\Control$MoveListener.class
     文件         213  2009-05-05 13:05  StarCraft-Java Swing\Swing星际争霸\source\bin\core\Control$RightPressListener.class
     文件        5009  2009-05-05 13:05  StarCraft-Java Swing\Swing星际争霸\source\bin\core\Control.class
     文件        5638  2009-05-05 09:46  StarCraft-Java Swing\Swing星际争霸\source\bin\core\FocusManager.class
     文件         671  2009-04-20 17:43  StarCraft-Java Swing\Swing星际争霸\source\bin\core\FullGameCore$1.class
     文件        3846  2009-04-20 17:43  StarCraft-Java Swing\Swing星际争霸\source\bin\core\FullGameCore.class
     文件        3432  2009-04-20 17:43  StarCraft-Java Swing\Swing星际争霸\source\bin\core\GameCore.class
     文件         309  2009-04-20 17:43  StarCraft-Java Swing\Swing星际争霸\source\bin\core\Grid.class
     文件        5585  2009-05-05 09:46  StarCraft-Java Swing\Swing星际争霸\source\bin\core\GridMap.class
     文件        8745  2009-05-05 13:09  StarCraft-Java Swing\Swing星际争霸\source\bin\core\GridMapRender.class
     文件        1359  2009-04-20 17:43  StarCraft-Java Swing\Swing星际争霸\source\bin\core\ImageManager.class
     文件        1051  2009-04-20 17:43  StarCraft-Java Swing\Swing星际争霸\source\bin\core\NullRepaintManager.class
     文件       10937  2009-05-05 13:03  StarCraft-Java Swing\Swing星际争霸\source\bin\core\ResourceManager$Constant.class
     文件        5986  2009-05-05 13:03  StarCraft-Java Swing\Swing星际争霸\source\bin\core\ResourceManager.class
     文件         738  2009-04-20 17:43  StarCraft-Java Swing\Swing星际争霸\source\bin\core\ScreenManager$1.class
     文件        4251  2009-04-20 17:43  StarCraft-Java Swing\Swing星际争霸\source\bin\core\ScreenManager.class
     文件        1865  2009-04-20 17:43  StarCraft-Java Swing\Swing星际争霸\source\bin\core\TileList.class
............此处省略440个文件信息

评论

共有 条评论