星际争霸
背景
大致需求
一个实时战略游戏。可以选择不同的作战单位,进行不同的动作,比如,移动到某个地点,或者攻击某个作战单位

作战单位表格
名字 | 形容 | 移动性 | 攻击性 |
---|---|---|---|
Stalker | 能量蜘蛛 | 爬行 | 毒液攻击 |
PhotonCanon | 光子加农炮台 | 固定 | 光球攻击 |
Observer | 检查机 | 飞行 | 无 |
功能要求
位置
每个作战单位都有所在位置,用来描述在地图中的位置
选择
可以使用一个矩形,选择在矩形内所有作战单位

攻击
当攻击时,被选中的作战单位,能攻击的,攻击目标
移动
当移动时,被选中的作战单位,能移动的,移动到目标位置
基于代码
package course.lesson13.base; public class Point { private int x; private int y; public Point() { } public Point(int x, int y) { this.x = x; this.y = y; } public int getX() { return x; } public void setX(int x) { this.x = x; } public int getY() { return y; } public void setY(int y) { this.y = y; } }
package course.lesson13.base; public class Rectangle { private Point origin; private int width; private int height; public Rectangle() { } public Rectangle(Point origin, int width, int height) { this.origin = origin; this.width = width; this.height = height; } public boolean hitTest(Point target) { int minX = origin.getX(); int maxX = minX + width; int minY = origin.getY(); int maxY = minY + height; return minX <= target.getX() && target.getX() <= maxX && minY <= target.getY() && target.getY() <= maxY; } public Point getOrigin() { return origin; } public void setOrigin(Point origin) { this.origin = origin; } public int getWidth() { return width; } public void setWidth(int width) { this.width = width; } public int getHeight() { return height; } public void setHeight(int height) { this.height = height; } }