X-Git-Url: https://git.hedgecode.org/?p=chesshog.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fhedgecode%2Fchess%2Fimg%2Fboard%2FBoard.java;fp=src%2Fmain%2Fjava%2Forg%2Fhedgecode%2Fchess%2Fimg%2Fboard%2FBoard.java;h=f251e137a51d1d9e6429bc2f6b0c7a29c880f899;hp=0000000000000000000000000000000000000000;hb=ccafd673bfcda89a75f428e58dc06525e1b0a368;hpb=d3bad7f328495d5746704f914fd335a2487ad2bb diff --git a/src/main/java/org/hedgecode/chess/img/board/Board.java b/src/main/java/org/hedgecode/chess/img/board/Board.java new file mode 100644 index 0000000..f251e13 --- /dev/null +++ b/src/main/java/org/hedgecode/chess/img/board/Board.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2018-2019. Developed by Hedgecode. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.hedgecode.chess.img.board; + +import java.awt.Graphics; +import java.awt.image.BufferedImage; + +import org.hedgecode.chess.position.Square; + +/** + * + * + * @author Dmitry Samoshin aka gotty + */ +public class Board { + + private SquarePair squares; + private int squareSize; + + Board(SquarePair squares) { + this.squares = squares; + int width = Math.max(squares.getDark().getWidth(), squares.getLight().getWidth()); + int height = Math.max(squares.getDark().getHeight(), squares.getLight().getHeight()); + this.squareSize = Math.max(width, height); + } + + public int squareSize() { + return squareSize; + } + + public int boardSize() { + return squareSize * Square.getSize(); + } + + public BufferedImage render() { + BufferedImage board = new BufferedImage( + squareSize * Square.getSize(), + squareSize * Square.getSize(), + BufferedImage.TYPE_INT_ARGB + ); + Graphics boardGraphics = board.getGraphics(); + for (int y = 0; y < Square.getSize(); ++y) { + for (int x = 0; x < Square.getSize(); ++x) { + boardGraphics.drawImage( + (x + y) % 2 == 0 + ? squares.getLight() + : squares.getDark(), + x * squareSize, + y * squareSize, + null + ); + } + } + return board; + } + + public static Board create(SquarePair squares) { + return new Board(squares); + } + +}