public static void main(String[] args) throws NegativeExponentException { Poly p1 = null; p1 = new Poly(2, 1); p1 = p1.add(new Poly(12, 1)); p1 = p1.add(new Poly(3, 3)); System.out.println("Poly p1: " + p1.toString() + "(degree: " + 2 + ")"); }
/** Draws the game */ @Override protected void paintComponent(Graphics g) { super.paintComponent(g); final Graphics2D g2 = (Graphics2D) g; /** Draw all the non-falling blocks on the board. Non-OUTSIDE blocks have rounded corners. */ for (int row = 0; row < board.getHeight(); row++) { for (int column = 0; column < board.getWidth(); column++) { if (board.getSquareType(row, column) != SquareType.OUTSIDE) { Shape tetrominoBlock = new RoundRectangle2D.Double( column * SQUARE_WIDTH, row * SQUARE_HEIGHT, SQUARE_WIDTH, SQUARE_HEIGHT, 5, 5); g2.setColor(SQUARE_COLOR.get(board.getSquareType(row, column))); g2.fill(tetrominoBlock); g2.draw(tetrominoBlock); } else { Shape tetrominoBlock = new Rectangle2D.Double( column * SQUARE_WIDTH, row * SQUARE_HEIGHT, SQUARE_WIDTH, SQUARE_HEIGHT); g2.setColor(SQUARE_COLOR.get(board.getSquareType(row, column))); g2.fill(tetrominoBlock); g2.draw(tetrominoBlock); } } } Poly tempPoly = board.getFalling(); if (tempPoly != null) { for (int row = 0; row < tempPoly.getSize(); row++) { for (int column = 0; column < tempPoly.getSize(); column++) { if (tempPoly.getSquareType(row, column) != SquareType.EMPTY) { Shape tetrominoBlock = new RoundRectangle2D.Double( (column + board.getFallingPosX()) * SQUARE_WIDTH, (row + board.getFallingPosY()) * SQUARE_HEIGHT, SQUARE_WIDTH, SQUARE_HEIGHT, 5, 5); g2.setColor(SQUARE_COLOR.get(tempPoly.getSquareType(row, column))); g2.fill(tetrominoBlock); g2.draw(tetrominoBlock); } } } } }