📄 pathgraphic.java
字号:
/* * Copyright 2008 TKK/ComNet * Released under GPLv3. See LICENSE.txt for details. */package gui.playfield;
import java.awt.Color;
import java.awt.Graphics2D;
import java.util.List;
import core.Coord;
import movement.Path;
/**
* Visualization of a Path
*
*/
public class PathGraphic extends PlayFieldGraphic {
private final static Color PATH_COLOR = Color.RED;
private List<Coord> coords;
public PathGraphic(Path path) {
if (path == null) {
this.coords = null;
}
else {
this.coords = path.getCoords();
assert this.coords != null && this.coords.size() > 0 :
"No coordinates in the path (" + path + ")";
}
}
/**
* Draws a line trough all path's coordinates.
* @param g2 The graphics context to draw to
*/
@Override
public void draw(Graphics2D g2) {
if (coords == null) {
return;
}
g2.setColor(PATH_COLOR);
Coord prev = coords.get(0);
for (int i=1, n=coords.size(); i < n; i++) {
Coord next = coords.get(i);
g2.drawLine(scale(prev.getX()), scale(prev.getY()),
scale(next.getX()), scale(next.getY()));
prev = next;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -