PHP code example of masyasmv / otus-macro-commands

1. Go to this page and download the library: Download masyasmv/otus-macro-commands library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

masyasmv / otus-macro-commands example snippets


$move = new MacroCommand(
    new CheckFuelCommand(5),   // 1) есть ли топливо?
    new MoveCommand(1),        // 2) сдвигаемся
    new BurnFuelCommand(5)     // 3) вычитаем расход
);

$rotate = new MacroCommand(
    new RotateCommand($rotator, 30.0),     // меняет угол
    new ChangeVelocityCommand(30.0)        // и вектор скорости
);

use Masyasmv\OtusMacroCommands\Command\{MoveCommand, CheckFuelCommand, BurnFuelCommand, MacroCommand};
use Masyasmv\OtusMacroCommands\Model\Ship;

$ship = new Ship();           // реализует Positionable, VelocityAware, Rotatable, FuelTankAware
$ship->refillFuel(100);

$moveForward = new MacroCommand(
    new CheckFuelCommand(10),
    new MoveCommand(1),
    new BurnFuelCommand(10)
);

$moveForward->execute($ship);