PHP Classes


Recommend this page to a friend!
  Classes of Tomas Pavlatka  >  PHP Snake Game  >  >  Download  
Role: Documentation
Content type: text/markdown
Description: Auxiliary data
Class: PHP Snake Game
Manage and process the moves in a snake game
Author: By
Last change: Update of
Date: 10 months ago
Size: 1,031 bytes


Class file image Download


Small and simple class to play with old game called Snake. You can initiate a snake and instruct him, where to go. The system will check the path and will let you know whether snake survived or he aet himself on the way.

If everything goes well, system will return -1. If snake aet himself, system will return a number of a step when this happened.


require_once './bootstrap.php';
use \Ptx\Snake;

$snake_obj = new Snake();
$moves_2_test = [

foreach($moves_2_test as $move) {
    try {
        $result = $snake_obj->move_snake($move);

        echo $move . ': ';
        echo ($result == -1) ? 'YES' : $result;
        echo "\r\n";
    } catch(\Ptx\SnakeException $e) {
        echo $e->getMessage();

// Output

Console application

There is also a console application using the same logic. To start it, call this command

php snake.php FLERFF

System will check and will let you know.

For more information send a message to info at phpclasses dot org.