minor chnages / renaming / path painting

- draw resolved path as showAll correctly
it was displaying all direction of same cell as solution while only one direction is ok
- Renderer renaming for class rendering cells
- draw directions as arrows
This commit is contained in:
philippe lhardy
2020-12-28 13:16:35 +01:00
parent afbe26065b
commit 0bab1d51b1
7 changed files with 58 additions and 44 deletions

View File

@@ -0,0 +1,90 @@
package org.artisanlogiciel.games.maze.gui;
import org.artisanlogiciel.games.maze.Brick;
import java.awt.*;
/**
* draw cell as an hexagon
* using a square model ( LEFT UP only).
*/
public class HexagonCellRenderer
extends MazeCellRenderer
{
public final static int SUBCELL = 4;
public HexagonCellRenderer(int mapw, int maph, int W, int H, int x, int y) {
super(mapw, maph, W, H, x, y);
}
void drawLine(Graphics g, int refx, int refy, int x, int y, int a, int b) {
g.drawLine(
(int) ((refx + x) * getWidth() / SUBCELL), (int) ((refy + y) * getHeight() / SUBCELL),
(int) ((refx + a) * getWidth() / SUBCELL),(int) ((refy + b) * getHeight() / SUBCELL));
}
@Override
public void drawBackground(Graphics g, int pX, int pY, short walls) {
UV uv= new UV(pX,pY);
int x = offsetX + (int) (uv.getX() * width / SUBCELL);
int y = offsetY + (int) (uv.getY() * height / SUBCELL);
Color savecolor = g.getColor();
int greylevel = walls << 2;
g.setColor(getGreyedColor(savecolor,greylevel));
//g.fillRect(x+1,y+1,((int)width) -1,((int)height) - 1);
g.fillRect(x,y,((int)width),((int)height));
}
class UV
{
int u;
int v;
UV(int u, int v)
{
this.u=u;
this.v=v;
}
int getX()
{
return u*4 + 2*(v%2);
}
int getY()
{
return 3*v;
}
}
@Override
public void drawWalls(Graphics g, int pX, int pY, short walls) {
drawHalfNW(g, pX, pY, walls);
}
void drawHalfNW(Graphics g, int refx, int refy, short walls)
{
UV uv= new UV(refx,refy);
int x = uv.getX();
int y = uv.getY();
// NW : (0,1) - (2,0)
if (Brick.isFlagSet( Brick.UP, walls))
drawLine(g,x, y, 0,1,2,0);
// W : (0,1) - (0,3)
if (Brick.isFlagSet( Brick.LEFT, walls))
drawLine(g,x,y,0,1,0,3);
// NE : (2,0) - (4,1)
// if (Brick.isFlagSet( Brick.NE, walls))
drawLine(g,x,y,2,0,4,1);
}
void drawHalfSW(Graphics g)
{
// SW : (0,3) - (2,4)
// SE : (2,4) - (4,3)
// E : (4,3) - (4,1)
}
}