src/GameOfLife/Inputs/TemplateHandler/FieldsPlacer.php
/**
     * Places a template on a board.
     *
     * @param array $_templateFields The template that will be placed on the board
     * @param Board $_board The board on which the template will be placed
     * @param int $_posX The X-coordinate of the top left corner of the template on the board
     * @param int $_posY The Y-coordinate of the top left corner of the template on the board
     * @param Bool $_adjustDimensions Indicates whether the board shall be adjusted to match the template width and height
     *
     * @throws \Exception The exception when the template exceeds a border of the board
     */
Places a template on a board.

@throws \Exception The exception when the template exceeds a border of the board
Places a template on a board . @throws \ Exception The exception when the template exceeds a border of the board
public function placeTemplate(array $_templateFields, Board $_board, int $_posX, int $_posY, Bool $_adjustDimensions)
    {
        $templateHeight = count($_templateFields);
        $templateWidth = count($_templateFields[0]);
        if ($_adjustDimensions)
        {
            $_board->setWidth($templateWidth);
            $_board->setHeight($templateHeight);
            foreach ($_templateFields as $row)
            {
                foreach ($row as $field)
                {
                    $field->setParentBoard($_board);
                }
            }
            $_board->setFields($_templateFields);
        }
        else
        {
            $exceededBorder = $this->isTemplateOutOfBounds($_board, $templateWidth, $templateHeight, $_posX, $_posY);
            if ($exceededBorder)
            {
                throw new \Exception("The template exceeds the " . $exceededBorder . " border of the board.");
            }
            else
            {
                foreach ($_templateFields as $row)
                {
                    foreach ($row as $field)
                    {
                        $_board->setField($field->x() + $_posX, $field->y() + $_posY, $field->isAlive());
                    }
                }
            }
        }
    }
public function placeTemplate ( array $ _templateFields , Board $ _board , int $ _posX , int $ _posY , Bool $ _adjustDimensions ) { $ templateHeight = count ( $ _templateFields ) ; $ templateWidth = count ( $ _templateFields [ 0 ] ) ; if ( $ _adjustDimensions ) { $ _board -> setWidth ( $ templateWidth ) ; $ _board -> setHeight ( $ templateHeight ) ; foreach ( $ _templateFields as $ row ) { foreach ( $ row as $ field ) { $ field -> setParentBoard ( $ _board ) ; } } $ _board -> setFields ( $ _templateFields ) ; } else { $ exceededBorder = $ this -> isTemplateOutOfBounds ( $ _board , $ templateWidth , $ templateHeight , $ _posX , $ _posY ) ; if ( $ exceededBorder ) { throw new \ Exception ( " The template exceeds the  " . $ exceededBorder . "  border of the board. " ) ; } else { foreach ( $ _templateFields as $ row ) { foreach ( $ row as $ field ) { $ _board -> setField ( $ field -> x ( ) + $ _posX , $ field -> y ( ) + $ _posY , $ field -> isAlive ( ) ) ; } } } } }
Places a template on a board.
Places a template on a board .
/** @var Field $field */ /** @var Field $field */