-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfling.pl
53 lines (48 loc) · 1.19 KB
/
fling.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#delete after move FLing.pm line 88
use strict;
use warnings;
use utf8;
use Data::Dumper;
use Fling;
use Field;
use Term::ANSIScreen;
my $console = Term::ANSIScreen->new;
#print "$_:".chr($_)." " foreach (0..256);
my $field = new Field(7,8);
$field->draw_field();
my ($moves_cnt, %moves) = $field->_find_moves();
while(my $command = read_command()){
$console->Cls;
$console->Cursor(0, 0);
last if $command eq 'e';
if($command eq 's'){
my $res = $field->do_move();
unless($res){
print "SOLVED\n";
print join("\n", @{$field->{solve_moves}});
}
}
if($command=~/p:(\d+):(\d+)/){
new Fling($1, $2, $field);
}elsif($command=~/r/){
my $rest = pop $field->{removed};
$rest->restore();
}elsif($command=~/d:(\d+):(\d+)/){
$field->{pos_buff}[$2][$1]->remove() if defined $field->{pos_buff}[$2][$1];
}elsif($command=~/m:(\d+):(\d+):([u|d|l|r])/){
my $d;
$d = 'left' if $3 eq 'l';
$d = 'right' if $3 eq 'r';
$d = 'up' if $3 eq 'u';
$d = 'down' if $3 eq 'd';
my @moved = $field->{pos_buff}[$2][$1]->move($d);
}
$field->draw_field();
}
#print Dumper($field->{flings});
sub read_command {
print "Input command:";
my $c = <STDIN>;
chomp $c;
return $c;
} ## --- end sub read_command