📄 origmazegraphics.java
字号:
// also draws zero, one or two golds inside the robot...
public boolean drawRobotCircle(int x, int y, int dir, int golds, int robotnumber)
{
Graphics g = this.parent_frame.getGraphics();
if ((robotnumber % 2) == 0)
g.setColor(Color.green);
else g.setColor(Color.green);
int tl_x, tl_y;
tl_x = x + this.anchor_x;
tl_y = y + this.anchor_y;
tl_x = tl_x + ((int)(this.wall_thickness * this.magnification * 2));
tl_y = tl_y + ((int)(this.wall_thickness * this.magnification * 2));
int diam = this.cellsize - (4 * this.wall_thickness);
diam = ((int)(diam * this.magnification));
int radius = (int)((float)diam / 2.0);
g.fillOval(tl_x, tl_y, diam, diam);
if (golds >= 1) {
this.drawGoldPos(tl_x-anchor_x,tl_y-anchor_y);
} //endif
if (golds == 2) {
this.drawGoldPos(tl_x-anchor_x+radius-
((int)(this.wall_thickness * this.magnification)),
tl_y-anchor_y);
} //endif
g.setColor(Color.black);
if (dir == 0) {
g.drawLine(tl_x + radius, tl_y, tl_x + radius, tl_y + radius);
}
if (dir == 1) {
g.drawLine(tl_x, tl_y + radius, tl_x + radius, tl_y + radius);
}
if (dir == 2) {
g.drawLine(tl_x + radius, tl_y + radius,
tl_x + radius, tl_y + radius + radius);
}
if (dir == 3) {
g.drawLine(tl_x + radius, tl_y + radius,
tl_x + radius + radius, tl_y + radius);
}
g.dispose();
return(true);
} // drawCircle() //
public boolean drawRobotLine(int x, int y, int dir, int golds, int robotnumber)
{
Graphics g = this.parent_frame.getGraphics();
if ((robotnumber % 2) == 0)
g.setColor(Color.green);
else g.setColor(Color.green);
int tl_x, tl_y;
tl_x = x + this.anchor_x;
tl_y = y + this.anchor_y;
tl_x = tl_x + ((int)(this.wall_thickness * this.magnification * 2));
tl_y = tl_y + ((int)(this.wall_thickness * this.magnification * 2));
int diam = this.cellsize - (4 * this.wall_thickness);
diam = ((int)(diam * this.magnification));
int radius = (int)((float)diam / 2.0);
/* g.fillOval(tl_x, tl_y, diam, diam); */
/*
if (golds >= 1) {
this.drawGoldPos(tl_x-anchor_x,tl_y-anchor_y);
} //endif
if (golds == 2) {
this.drawGoldPos(tl_x-anchor_x+radius-
((int)(this.wall_thickness * this.magnification)),
tl_y-anchor_y);
} //endif
*/
g.setColor(Color.black);
if (dir == 0) {
g.drawLine(tl_x + radius, tl_y, tl_x + radius, tl_y + radius);
}
if (dir == 1) {
g.drawLine(tl_x, tl_y + radius, tl_x + radius, tl_y + radius);
}
if (dir == 2) {
g.drawLine(tl_x + radius, tl_y + radius,
tl_x + radius, tl_y + radius + radius);
}
if (dir == 3) {
g.drawLine(tl_x + radius, tl_y + radius,
tl_x + radius + radius, tl_y + radius);
}
g.dispose();
return(true);
} // drawRobotLine() //
public boolean eraseRobotCircle(int x, int y)
{
Graphics g = this.parent_frame.getGraphics();
g.setColor(Color.white);
int tl_x, tl_y;
tl_x = xCell2Pixel(x) + this.anchor_x;
tl_y = yCell2Pixel(y) + this.anchor_y;
tl_x = tl_x + ((int)(this.wall_thickness * this.magnification * 2));
tl_y = tl_y + ((int)(this.wall_thickness * this.magnification * 2));
int diam = this.cellsize - (4 * this.wall_thickness);
diam = ((int)(diam * this.magnification));
int radius = (int)((float)diam / 2.0);
g.fillOval(tl_x, tl_y, diam, diam);
g.dispose();
return true;
}
public boolean drawRect(int x, int y, int width,
int height,
int thickness)
{
Graphics g = this.parent_frame.getGraphics();
g.setColor(Color.red);
for (int i=0; i<thickness; i++) {
g.drawRect(this.anchor_x+x+i,
this.anchor_y+y+i,
width - (i*2), height - (i*2));
} // end for //
g.dispose();
return(true);
}
//this takes tl pixel corner of one cell and draws the 1-cell gold
public boolean drawPortPos(int x, int y)
{
Graphics g = this.parent_frame.getGraphics();
g.setColor(Color.blue);
int tl_x, tl_y;
tl_x = x + this.anchor_x+ (int)(this.wall_thickness * this.magnification) - 2;
tl_y = y + this.anchor_y + (int)(this.wall_thickness * this.magnification) - 2;
g.drawRect(tl_x, tl_y, (int)(this.wall_thickness * 2*this.magnification)+4,
(int)(this.wall_thickness * 2*this.magnification)+4);
g.dispose();
return(true);
} // drawGold() //
//this takes tl pixel corner of one cell and draws the 1-cell gold
public boolean drawGoldPos(int x, int y)
{
Graphics g = this.parent_frame.getGraphics();
g.setColor(Color.orange);
int tl_x, tl_y;
tl_x = x + this.anchor_x+ (int)(this.wall_thickness * this.magnification);
tl_y = y + this.anchor_y + (int)(this.wall_thickness * this.magnification);
g.fillRect(tl_x, tl_y, (int)(this.wall_thickness * 2*this.magnification),
(int)(this.wall_thickness * 2*this.magnification));
g.dispose();
return(true);
} // drawGold() //
public boolean erasePortPos(int x, int y)
{
Graphics g = this.parent_frame.getGraphics();
g.setColor(Color.white);
int tl_x, tl_y;
tl_x = xCell2Pixel(x) + this.anchor_x+ (int)(this.wall_thickness * this.magnification) - 2;
tl_y = yCell2Pixel(y) + this.anchor_y + (int)(this.wall_thickness * this.magnification) - 2;
g.fillRect(tl_x, tl_y, (int)(this.wall_thickness * 2*this.magnification)+4,
(int)(this.wall_thickness * 2*this.magnification)+4);
g.dispose();
return(true);
} // erasePortPos() //
public boolean eraseGoldPos(int x, int y)
{
Graphics g = this.parent_frame.getGraphics();
g.setColor(Color.white);
int tl_x, tl_y;
tl_x = xCell2Pixel(x) + this.anchor_x+ (int)(this.wall_thickness * this.magnification);
tl_y = yCell2Pixel(y) + this.anchor_y + (int)(this.wall_thickness * this.magnification);
g.fillRect(tl_x, tl_y, (int)(this.wall_thickness * 2*this.magnification),
(int)(this.wall_thickness * 2*this.magnification));
g.dispose();
return(true);
} // drawGold() //
//takes the tl corner of two cells and draws a 2-cell covering gold
public boolean drawGoldPos(int x1, int y1, int x2, int y2)
{
Graphics g = this.parent_frame.getGraphics();
g.setColor(Color.orange);
int tl_x, tl_y;
if (x1 == x2) { // vertical pair of cells //
tl_x = x1 + (int)(this.cellsize * this.magnification * 0.5);
tl_x = tl_x - (int)(this.wall_thickness * this.magnification);
tl_x = tl_x + this.anchor_x;
tl_y = Math.max(y1,y2) - (int)(this.wall_thickness * this.magnification);
tl_y = tl_y + this.anchor_y;
} else if (y1 == y2) { // horizontal pair of cells //
tl_y = y1 + (int)(this.cellsize * this.magnification*0.5);
tl_y = tl_y - (int)(this.wall_thickness * this.magnification);
tl_y = tl_y + this.anchor_y;
tl_x = Math.max(x1,x2) - (int)(this.wall_thickness * this.magnification);
tl_x = tl_x + this.anchor_x;
} else {
g.dispose();
return(false);
} //endelse#2
g.fillRect(tl_x, tl_y, (int)(this.wall_thickness * 2*this.magnification),
(int)(this.wall_thickness * 2*this.magnification));
g.dispose();
return(true);
} // drawGoldPos() //
//takes the tl corner of two cells and draws a 2-cell covering gold
public boolean eraseGoldPos(int x1, int y1, int x2, int y2)
{
Graphics g = this.parent_frame.getGraphics();
g.setColor(Color.white);
int tl_x, tl_y;
if (x1 == x2) { // vertical pair of cells //
tl_x = x1 + (int)(this.cellsize * this.magnification * 0.5);
tl_x = tl_x - (int)(this.wall_thickness * this.magnification);
tl_x = tl_x + this.anchor_x;
tl_y = Math.max(y1,y2) - (int)(this.wall_thickness * this.magnification);
tl_y = tl_y + this.anchor_y;
} else if (y1 == y2) { // horizontal pair of cells //
tl_y = y1 + (int)(this.cellsize * this.magnification*0.5);
tl_y = tl_y - (int)(this.wall_thickness * this.magnification);
tl_y = tl_y + this.anchor_y;
tl_x = Math.max(x1,x2) - (int)(this.wall_thickness * this.magnification);
tl_x = tl_x + this.anchor_x;
} else {
g.dispose();
return(false);
} //endelse#2
g.fillRect(tl_x, tl_y, (int)(this.wall_thickness * 2*this.magnification),
(int)(this.wall_thickness * 2*this.magnification));
g.dispose();
return(true);
} // drawGoldPos() //
// this draws a line and does thickness symmetrically //
public boolean drawHorizontalLine(int x1, int x2,
int y, int thickness)
{
Graphics g = this.parent_frame.getGraphics();
g.setColor(Color.red);
int start_y = y - (int)((float)(thickness)/2.0);
for (int i=0; i<thickness; i++) {
g.drawLine(this.anchor_x+x1,
this.anchor_y+start_y+i,
this.anchor_x+x2,
this.anchor_y+start_y+i);
} // end for() //
g.dispose();
return(true);
} // drawHorizontalLine() //
// this draws a line and does thickness symmetrically //
public boolean drawVerticalLine(int x, int y1,
int y2, int thickness)
{
Graphics g = this.parent_frame.getGraphics();
g.setColor(Color.red);
int start_x = x - (int)((float)(thickness)/2.0);
for (int i=0; i<thickness; i++) {
g.drawLine(this.anchor_x+start_x+i,
this.anchor_y+y1,
this.anchor_x+start_x+i,
this.anchor_y+y2);
} // end for() //
g.dispose();
return(true);
} // drawVerticalLine() //
// this draws a line and does thickness symmetrically //
public boolean eraseHorizontalLine(int x1, int x2,
int y, int thickness)
{
Graphics g = this.parent_frame.getGraphics();
g.setColor(Color.white);
int start_y = y - (int)((float)(thickness)/2.0);
for (int i=0; i<thickness; i++) {
g.drawLine(this.anchor_x+x1,
this.anchor_y+start_y+i,
this.anchor_x+x2,
this.anchor_y+start_y+i);
} // end for() //
g.dispose();
return(true);
} // drawHorizontalLine() //
// this draws a line and does thickness symmetrically //
public boolean eraseVerticalLine(int x, int y1,
int y2, int thickness)
{
Graphics g = this.parent_frame.getGraphics();
g.setColor(Color.white);
int start_x = x - (int)((float)(thickness)/2.0);
for (int i=0; i<thickness; i++) {
g.drawLine(this.anchor_x+start_x+i,
this.anchor_y+y1,
this.anchor_x+start_x+i,
this.anchor_y+y2);
} // end for() //
g.dispose();
return(true);
} // drawVerticalLine() //
// this takes the entire maze off the screen by drawing a filled white rect
public boolean wipeMaze()
{
Graphics g = this.parent_frame.getGraphics();
g.setColor(Color.white);
g.fillRect(this.anchor_x-
(int)(this.magnification *
this.wall_thickness),
this.anchor_y-
(int)(this.magnification *
this.wall_thickness),
(this.width * this.cellsize)+
(2 * (int)(this.magnification *
this.wall_thickness)),
(this.height * this.cellsize)+
(2 * (int)(this.magnification *
this.wall_thickness)));
g.dispose();
return(true);
} // wipeMaze()
public void refresh ()
{
this.wipeMaze();
this.drawBorder();
this.drawGrid();
this.drawWalls();
this.drawRobots();
this.drawPorts();
this.drawGolds();
} // refresh() //
public void update ()
{ this.refresh();
} // update() //
// this refresh refreshes only this particular cell! //
// x,y are in terms of the cell numbers //
public void refreshCells (Vector cells)
{
int[] cell;
for (int i=0; i < cells.size() ; i++)
{
cell = (int [])(cells.elementAt(i));
this.redoMazeCell(cell[0], cell[1]);
} // end for
}
} // end MazeGraphics //
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -