PHP code example of yandod / php-warrior

1. Go to this page and download the library: Download yandod/php-warrior 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/ */

    

yandod / php-warrior example snippets



  class Player {
    public function play_turn($warrior){
      # your code goes here
    }
  }


  class Player {
    public function play_turn($warrior) {
      if ($warrior->feel()->is_enemy()) {
        $warrior->attack();
      } else {
        $warrior->walk();
      }
    }
  }

// Move in given direction (forward by default).
$warrior->walk()

// Attack the unit in given direction (forward by default).
$warrior->attack()

// Gain 10% of max health back, but do nothing more.
$warrior->rest()

// Bind unit in given direction to keep him from moving (forward by default).
$warrior->bind()

// Rescue a captive from his chains (earning 50 points) in given direction (forward by default).
$warrior->rescue()

// Returns a Space for the given direction (forward by default).
$warrior->feel()

// Returns an integer representing your health.
$warrior->health()

// Returns the number of spaces the stairs are away.
$warrior->distance()

// Returns an array of all spaces which have units in them.
$warrior->listen()

$warrior->form(function($golem) {
  if ($golem->feel()->is_enemy()) {
    $golem->attack();
  }
});
bash
composer global composer/vendor/bin:$PATH
bash
composer global 
bash
composer global remove "yandod/php-warrior"