Last Updated | | Ratings | | Unique User Downloads | | Download Rankings |
2024-01-10 (3 days ago) | | 67% | | Total: 556 This week: 2 | | All time: 5,462 This week: 220 |
|
Description | | Author |
This class can manage and process the moves in a snake game.
It can initialize the snake game and process sequences of moves in given directions.
The class returns the result of whether the snake survived traversing the given path of directions. Innovation Award
March 2015
Number 8
Prize: One copy of VS.PHP |
The snake game is a very old game from the time of the first arcade machines.
This class can simulate the moves of the snake game to determine if the snake would survive.
Manuel Lemos |
| |
|
|
Innovation award
Nominee: 2x |
|
Example
<?php
header('content-type: text/plain; charset=utf-8');
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();
}
}
|
Details
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.
|
Applications that use this package |
|
No pages of applications that use this class were specified.
If you know an application of this package, send a message to the author to add a link here.