PHP Classes

File: README.md

Recommend this page to a friend!
  Classes of Tomas Pavlatka  >  PHP Snake Game  >  README.md  >  Download  
File: README.md
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 README.md
Date: 4 days ago
Size: 1,031 bytes
 

Contents

Class file image Download

PTX-Snake

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.

Example

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

$snake_obj = new Snake();
$moves_2_test = [
    'FLERFF', 'EEEELLLL'
];

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

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

// Output
FLERFF: YES
EEEELLLL: 7

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.