NAME

Games::Sokoban::Controller - sokoban controller

SYNOPSIS

use strict;
use warnings;
use Games::Sokoban::Controller;

my $c = Games::Sokoban::Controller->new;
$c->set_data(<<'LEVEL');
#######
#@ .  #
#  $  #
#     #
#######
LEVEL

my @replaced = $c->go_down;

for (@replaced) {
  my $char = $c->get($_->[0], $_->[1]);
  if ($char eq '@') { ... } # me
  if ($char eq '+') { ... } # me on a goal
  if ($char eq '$') { ... } # box
  if ($char eq '*') { ... } # box on a goal
  if ($char eq '.') { ... } # goal
  if ($char eq ' ') { ... } # floor
}

if ($c->solved) {
  print "SOLVED!\n";
}

DESCRIPTION

This is a plain Sokoban controller. If you want to play Sokoban, you'll need some front-end.

METHODS

new

creates an object.

set_data (data, format)

set puzzle data (level). See Games::Sokoban for available formats.

level_id

returns an unique id of the puzzle.

reset

(re-)initializes the puzzle.

size, width, height

return width and/or height of the puzzle.

get (x, y)

returns a character of the (0-based) coordinate.

go_left, go_right, go_up, go_down

move the player (and a box if applicable), and return an array of coordinates where you need to update because of the move.

direction

usually returns the direction of the player (left, right, up, down). You may want to use this if you create a graphical front-end.

solved

returns true if everything is placed correctly.

SEE ALSO

Games::Sokoban

AUTHOR

Kenichi Ishigaki, <ishigaki@cpan.org>

COPYRIGHT AND LICENSE

Copyright (C) 2011 by Kenichi Ishigaki.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.