diff --git a/bin/main/edu/rpi/legup/log4j2.properties b/bin/main/edu/rpi/legup/log4j2.properties index de1fa02ed..4f2556c2d 100644 --- a/bin/main/edu/rpi/legup/log4j2.properties +++ b/bin/main/edu/rpi/legup/log4j2.properties @@ -1,15 +1,15 @@ -# Logging level -# Root logger option -log4j.rootLogger=DEBUG, stdout, file -# Redirect log messages to console -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.Target=System.out -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n -# Redirect log messages to a log file, support file rolling. -log4j.appender.file=org.apache.log4j.RollingFileAppender -log4j.appender.file.File=Legup.log -log4j.appender.file.MaxFileSize=5MB -log4j.appender.file.MaxBackupIndex=10 -log4j.appender.file.layout=org.apache.log4j.PatternLayout +# Logging level +# Root logger option +log4j.rootLogger=DEBUG, stdout, file +# Redirect log messages to console +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target=System.out +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n +# Redirect log messages to a log file, support file rolling. +log4j.appender.file=org.apache.log4j.RollingFileAppender +log4j.appender.file.File=Legup.log +log4j.appender.file.MaxFileSize=5MB +log4j.appender.file.MaxBackupIndex=10 +log4j.appender.file.layout=org.apache.log4j.PatternLayout log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n \ No newline at end of file diff --git a/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleBorder.java b/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleBorder.java new file mode 100644 index 000000000..9556e5727 --- /dev/null +++ b/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleBorder.java @@ -0,0 +1,23 @@ +package edu.rpi.legup.puzzle.starbattle; + +import edu.rpi.legup.model.gameboard.PuzzleElement; + +public class StarBattleBorder extends PuzzleElement { + private StarBattleCellType type; + + public StarBattleBorder(StarBattleCellType border_type){ + super(); //just use the empty constructor since it doesn't hold a value + type = border_type; + } + + public StarBattleCellType getType(){ + return type; + } + + public StarBattleBorder copy(){ + StarBattleBorder copy = new StarBattleBorder(type); + copy.setIndex(index); + copy.setModifiable(isModifiable); + return copy; + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleBorderView.java b/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleBorderView.java new file mode 100644 index 000000000..066f06595 --- /dev/null +++ b/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleBorderView.java @@ -0,0 +1,58 @@ +package edu.rpi.legup.puzzle.starbattle; + +import edu.rpi.legup.ui.boardview.ElementView; +import java.awt.*; +import java.awt.geom.Rectangle2D; + +public class StarBattleBorderView extends ElementView { + private static final Color Border_COLOR = Color.BLACK; + private StarBattleCellType type; + + public StarBattleBorderView(StarBattleBorder border) { + super(border); + type = border.getType(); + } + + /** + * Gets the PuzzleElement associated with this view + * + * @return PuzzleElement associated with this view + */ + @Override + public StarBattleBorder getPuzzleElement() { + return (StarBattleBorder) super.getPuzzleElement(); + } + + @Override + public void draw(Graphics2D graphics2D) { + drawElement(graphics2D); + if (this.isShowCasePicker() && this.isCaseRulePickable()) { + drawCase(graphics2D); + if (this.isHover()) { + drawHover(graphics2D); + } + } + } + + @Override + public void drawElement(Graphics2D graphics2D) { + graphics2D.setColor(Color.BLACK); + + StarBattleBorder border= getPuzzleElement(); + + int xSize = size.width; + int ySize = size.height; + if(type == StarBattleCellType.HORIZ_BORDER){ //minimize ySize / height + graphics2D.setColor(Color.RED); + //dump this + //System.out.println("Horizontal -- Border, coords " + location.x + "," + location.y + "\n"); + ySize = ySize / 8; + } + else if(type == StarBattleCellType.VERT_BORDER){ //minimize xSize / width + graphics2D.setColor(Color.RED); + //System.out.println("Vertical | Border, c0ords " + location.x + "," + location.y + "\n"); + xSize = xSize / 8; + } + graphics2D.fillRect(location.x, location.y, xSize, ySize); + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleCell.java b/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleCell.java index ddae8f882..9045ccfd9 100644 --- a/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleCell.java +++ b/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleCell.java @@ -6,7 +6,7 @@ import java.awt.event.MouseEvent; public class StarBattleCell extends GridCell { - private int groupIndex; + private int groupIndex; //This is the region the cell is in private int max; /** diff --git a/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleCellType.java b/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleCellType.java index e48e46fcb..66943698f 100644 --- a/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleCellType.java +++ b/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleCellType.java @@ -4,7 +4,10 @@ public enum StarBattleCellType { STAR(-2), BLACK(-1), - UNKNOWN(0); + UNKNOWN(0), + HORIZ_BORDER(1), + VERT_BORDER(2); + public int value; diff --git a/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleElementView.java b/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleElementView.java index 66d59d364..9680f14ad 100644 --- a/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleElementView.java +++ b/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleElementView.java @@ -18,6 +18,7 @@ public StarBattleCell getPuzzleElement() { public void drawElement(Graphics2D graphics2D) { StarBattleCell cell = (StarBattleCell) puzzleElement; StarBattleCellType type = cell.getType(); + //System.out.println("point for cell is " + location.x + "," + location.y + "\n"); if (type == StarBattleCellType.STAR) { graphics2D.setColor(Color.LIGHT_GRAY); graphics2D.fillRect(location.x, location.y, size.width, size.height); @@ -42,5 +43,14 @@ public void drawElement(Graphics2D graphics2D) { graphics2D.setColor(Color.BLACK); graphics2D.drawRect(location.x, location.y, size.width, size.height); } + //else if (type == StarBattleCellType.BORDER){ //would likely define border as a cell type so as to + //not have to rewrite this whole function + /* //maybe one type for vertical and another for horizontal + graphics2D.setStrike(new BasicStrike(1)); + graphics2D.setColor(Color.BLACK); + graphics2D.drawRect(location.x, location.y, size.width, size.height); + } + */ + } } diff --git a/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleView.java b/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleView.java index 550b5495d..c4575a7e0 100644 --- a/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleView.java +++ b/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleView.java @@ -1,14 +1,19 @@ package edu.rpi.legup.puzzle.starbattle; import edu.rpi.legup.controller.BoardController; +import edu.rpi.legup.model.elements.Element; import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.ui.boardview.ElementView; import edu.rpi.legup.ui.boardview.GridBoardView; import java.awt.*; import java.io.IOException; +import java.util.ArrayList; import javax.imageio.ImageIO; public class StarBattleView extends GridBoardView { static Image STAR; + private ArrayList horizontalBorders; //board.size * board.size+1 left-right up-down + private ArrayList verticalBorders; //board.size+1 * board.size left-right up-down static { try { @@ -23,6 +28,8 @@ public class StarBattleView extends GridBoardView { public StarBattleView(StarBattleBoard board) { super(new BoardController(), new StarBattleController(), board.getDimension()); + this.horizontalBorders = new ArrayList<>(); + this.verticalBorders = new ArrayList<>(); for (PuzzleElement puzzleElement : board.getPuzzleElements()) { StarBattleCell cell = (StarBattleCell) puzzleElement; @@ -34,5 +41,103 @@ public StarBattleView(StarBattleBoard board) { new Point(loc.x * elementSize.width, loc.y * elementSize.height)); elementViews.add(elementView); } + + //Make borders by just making a list of border objects and saving their locations as they come + //then just draw all of them one at a time + + //initialize horizontal borders, the ones that are between two cells along the y-axis, and look like -- not | + for(int i = 0; i < board.getWidth(); i++){ + for(int j = 0; j < board.getHeight() + 1; j++){ //+1 to account for sides of board + StarBattleBorderView temp = new StarBattleBorderView(new StarBattleBorder(StarBattleCellType.HORIZ_BORDER)); + temp.setSize(elementSize); + if(j == 0){ //set borders at the ends of the board + //set on top of cell + temp.setLocation(endCell(board.getCell(i,0), 8, elementSize)); + horizontalBorders.add(temp); + } + else if(j == board.getHeight()){ + temp.setLocation(endCell(board.getCell(i,board.getHeight()-1), 2, elementSize)); + horizontalBorders.add(temp); + } + else if(board.getCell(i, j-1).getGroupIndex() != board.getCell(i, j).getGroupIndex()){ //general case + //adds border when two adjacent cells aren't from the same region + temp.setLocation(endCell(board.getCell(i,j), 8, elementSize)); + horizontalBorders.add(temp); + } + //no else statement. If none of these ifs are met, then just don't add it to the list + } + } + //initialize vertical borders, the ones that are between two cells along the x-axis, and look like | not -- + //largely the same code as horizontal border adder but i and j are flipped and general case checks cells adjacent + //along i (x) instead of j (y) + for(int j = 0; j < board.getHeight(); j++){ //initialize j (y) first since we're checking the opposite axis + for(int i = 0; i < board.getHeight() + 1; i++){ //+1 to account for sides of board + StarBattleBorderView temp = new StarBattleBorderView(new StarBattleBorder(StarBattleCellType.VERT_BORDER)); + temp.setSize(elementSize); + if(i == 0){ //set borders at the ends of the board + temp.setLocation(endCell(board.getCell(0,j), 4, elementSize)); + verticalBorders.add(temp); + } + else if(i == board.getWidth()){ + temp.setLocation(endCell(board.getCell(board.getWidth() - 1,j), 6, elementSize)); + verticalBorders.add(temp); + } + else if(board.getCell(i-1, j).getGroupIndex() != board.getCell(i, j).getGroupIndex()){ //general case + //adds border when two adjacent cells aren't from the same region + temp.setLocation(endCell(board.getCell(i,j), 4, elementSize)); + verticalBorders.add(temp); + } + } + } + } + + //Direction means which side of the cell in question should have a border on it + //Numpad rules. 2 is down, 4 is left, 6 is right, 8 is up (based on visuals not coordinates, since y is from up to down) + public Point endCell(StarBattleCell one, int direction, Dimension elementSize){ + Point temp = new Point( + one.getLocation().x * elementSize.width, + one.getLocation().y * elementSize.height + );//dump this + //System.out.println("point is " + temp.x + "," + temp.y + "\n"); + if(direction == 2){ + temp.y += elementSize.height * 15/16; //multiply so it doesn't go off screen + } + if(direction == 4){ + temp.x -= elementSize.width / 16; //divide so it doesn't go off screen + } + if(direction == 6){ + temp.x += elementSize.width * 15/16; //multiply so it doesn't go off screen + }if(direction == 8){ + temp.y -= elementSize.height / 16; //multiply so it doesn't go off screen + } + //System.out.println("point is now " + temp.x + "," + temp.y + "\n"); + return temp; + } + /* shelved for redundancy + //finds average point location between two cells + public Point betweenCells(StarBattleCell one, StarBattleCell two, Dimension elementSize){ + //dump this + System.out.println("point between is " + Math.max(one.getLocation().x,two.getLocation().x) + "," + Math.max(one.getLocation().y,two.getLocation().y) + "\n"); + if(one.getLocation().x < two.getLocation().x){ + return endCell(one, 6, elementSize); + } + else if(one.getLocation().y < two.getLocation().y){ + return endCell(one, 6, elementSize); + } + } */ + + @Override + public void drawBoard(Graphics2D graphics2D){ + super.drawBoard(graphics2D); + + for(StarBattleBorderView border: horizontalBorders){ + //draw a horizontal line + border.draw(graphics2D); + } + + for(StarBattleBorderView border: verticalBorders){ + //draw a vertical line + border.draw(graphics2D); + } } }