Apache ZooKeeperã®ãã¨ã§ã¯ããã¾ãããã´ã¡ã³ããµã¤ã
ãZOO KEEPERãã¨ããã²ã¼ã ã好ããªãã§ãã
KITERETSU: ZOOKEEPERアクティブ
ZOO KEEPER (ゲーム) - Wikipedia
æè¿çªç¶ã¾ãZOO KEEPERããããããªã£ã¦FLASHæ¢ãã¦ã¿ããiPhoneã¢ããªã§æ¢ãã¦ã¿ããããã®ã ãã©ã
ããããã¿ã¼ããã«ã§ä½ãããããï¼ãã¨æã£ãã®ã§ãä½ã£ã¦ã¿ãã
h, j, k, lã§ã«ã¼ã½ã«ç§»åãspaceã§é¸æãã¦ããã«h, j, k, lã§é£ã®ã¢ãã¨äº¤æã
ï¼ã¤ä¸¦ã¹ã°æ¶ãã¦æ°ãããã®ãè½ã¡ã¦ãããé£éãããæ¶ããæ°ã ãä¸ã«è¡¨ç¤ºã
åç©ã®æåã¯é©å½ï½ ãªãªã¸ãã«ã¨åãã«ãããã¨ããã¨ä¸æåã§è¡¨ç¾ã§ããªãã®ã§ã
ã¨ããããèªåã®Macã®ã¿ã¼ããã«ã§ãã試ãã¦ãªãã®ã§ä»ã®ç°å¢ã ã¨ã©ããªãã®ãå
¨ç¶ããããªããã ãã©ã
ããã£ã¨æ¸ããã½ã¼ã¹ã¯ä»¥ä¸ã
#!/usr/bin/perl use strict; use warnings; use utf8; use Encode; use Readonly; use Term::Screen; use Time::HiRes 'sleep'; Readonly my @animails => ('ã', 'ç¿', 'é°', 'è', '鯨', 'è±', '象', 'å '); my $stage = init(); REMOVE_AND_FALL: while (1) { my $result = remove($stage); last REMOVE_AND_FALL if !$result; fall($stage); } my ($x, $y) = (0, 0); my $mark = 0; my $result = 0; my $total_point = 0; my $screen = Term::Screen->new(); MAIN_LOOP: while (1) { $screen->clrscr(); # æç» for my $row (0..7) { $screen->at($row, 0); for my $col (0..7) { my $value = $stage->[$row][$col]; my $color = 30 + $value; my $bgcolor = 40; if (($x == $col) && ($y == $row)) { $color = 30 if ($color == 37); $bgcolor = 47; } print "\e[$color;$bgcolor", "m"; print encode_utf8($animails[$value]); } } $screen->at(9, 0)->normal()->puts($total_point); if ($result) { sleep(0.5); fall($stage); $result = remove($stage); $total_point += $result; next MAIN_LOOP; } my $ch = $screen->getch(); if ($mark) { # 交æ my $src = [$y, $x]; my $des = [$y, $x]; $des->[1]-- if ($ch eq 'h'); $des->[0]++ if ($ch eq 'j'); $des->[0]-- if ($ch eq 'k'); $des->[1]++ if ($ch eq 'l'); change($stage, $src, $des); $result = remove($stage); $total_point += $result; # æ¶ããªãå ´åã¯æ»ã change($stage, $src, $des) if ($result == 0); $mark = 0; } else { # ã«ã¼ã½ã«ç§»å $x-- if ($ch eq 'h'); $y++ if ($ch eq 'j'); $y-- if ($ch eq 'k'); $x++ if ($ch eq 'l'); } $x = 0 if ($x < 0); $x = 7 if ($x > 7); $y = 0 if ($y < 0); $y = 7 if ($y > 7); # ç¾å¨å°ããã¼ã¯ $mark = !$mark if ($ch eq ' '); # çµäº last MAIN_LOOP if ($ch eq 'q'); } $screen->normal(); # ã©ã³ãã ã§8*8ã®æ°å¤ãçæ sub init { return [ map { [ map { int(rand(7)) + 1; } 1..8 ]; } 1..8 ]; } # 縦or横ã«ï¼ã¤ä»¥ä¸ä¸¦ãã§ãããã®ã0ã«å¤æ´ # return : 0ã«å¤æ´ããåæ° sub remove { my $stage = shift; my $result = 0; # æ¶å»ããæ° for my $row (0..7) { # ä¸æçã«ãã©ã°ãæ㤠for my $col (0..7) { my $value = $stage->[$row][$col]; $stage->[$row][$col] = [$value, 1]; } # 横å¤å® for my $col (0..5) { my $value = $stage->[$row][$col + 0]; my $next1 = $stage->[$row][$col + 1]; my $next2 = $stage->[$row][$col + 2]; if (($value->[0] == $next1->[0]) && ($value->[0] == $next2->[0])) { $value->[1] = 0; $next1->[1] = 0; $next2->[1] = 0; } } } for my $col (0..7) { # 縦å¤å® for my $row (0..5) { my $value = $stage->[$row + 0][$col]; my $next1 = $stage->[$row + 1][$col]; my $next2 = $stage->[$row + 2][$col]; if (($value->[0] == $next1->[0]) && ($value->[0] == $next2->[0])) { $value->[1] = 0; $next1->[1] = 0; $next2->[1] = 0; } } # ãã©ã°ãå¤å®ã«ä½¿ç¨ããæ¨ã¦ã for my $row (0..7) { my $value = $stage->[$row][$col]; if ($value->[1]) { $stage->[$row][$col] = $value->[0]; } else { $stage->[$row][$col] = 0; $result++; } } } return $result; } # 0ã®é¨åã空ç½ã¨ã¿ãªããä¸ã«è©°ãã¦ãã sub fall { my $stage = shift; # ååã調ã¹ã for my $col (0..7) { my @values = grep { # 0ã§ãªããã® $_; } map { # $colåç®ã®è¦ç´ éå $_->[$col]; } @$stage; # 空ãã¦ããåãè©°ãã while (@values < 8) { unshift(@values, int(rand(7)) + 1) } # è©°ããå¾ã®ãã®ãåæ for my $row (0..7) { $stage->[$row][$col] = $values[$row]; } } } # è¦ç´ ã®å ¥ãæ¿ã sub change { my ($stage, $src, $des) = @_; return if $des->[0] < 0; return if $des->[0] > 7; return if $des->[1] < 0; return if $des->[1] > 7; my $tmp = $stage->[$src->[0]][$src->[1]]; $stage->[$src->[0]][$src->[1]] = $stage->[$des->[0]][$des->[1]]; $stage->[$des->[0]][$des->[1]] = $tmp; }
ç¤é¢ã表ç¾ãããã¼ã¿é¨åã¯çµ¶å¯¾ã¢ã¸ã¥ã¼ã«åãã¦å¤é¨ã§æã¤ã¹ãã ã£ã orz
ãã¨ã§ãªãã¡ã¯ã¿ãªã³ã°ãããâ¦