Skip to content
Browse files

Detect when tiles cannot be placed.

  • Loading branch information...
1 parent 53d5645 commit 403dfbcaa6a5ea589169c341b75c363c15e4143d @quietfanatic committed Dec 4, 2011
Showing with 46 additions and 3 deletions.
  1. +46 −3 game.p5
View
49 game.p5
@@ -70,6 +70,8 @@ our $tile_type;
our $turn = (0, 1)[rand(2)];
our $state = 'start';
+our $invert_tile = 1;
+our $can_put = 1;
our @origpos = (0, 0);
our @moves = ();
our $move_counter = 0;
@@ -361,6 +363,24 @@ sub draw_tile {
$tile_type = pick(1..6);
}
+sub invert_tile {
+ $tile_type = (REXT, RMOD, CHAOS, BMOD, BEXT, NEUT)[$tile_type - 1];
+}
+
+sub check_can_put {
+ $can_put = 0;
+ for my $y (0..$HEIGHT-1) {
+ for my $x (0..$WIDTH-1) {
+ if ($board[$y][$x] == 0
+ and any(@{$possibilities[$y][$x]}) == $tile_type) {
+ $can_put = 1;
+ return;
+ }
+ }
+ }
+}
+
+
sub move_tile {
given ($_[0]) {
when (UP) { return if $tile_pos[1] >= $HEIGHT-1; $tile_pos[1]++ }
@@ -377,6 +397,14 @@ sub place_tile {
propogate(@tile_pos);
return 1;
}
+ elsif (not $can_put) {
+ $board[$tile_pos[1]][$tile_pos[0]] = $tile_type;
+ render();
+ $board[$tile_pos[1]][$tile_pos[0]] = pick(@{$possibilities[$tile_pos[1]][$tile_pos[0]]});
+ microsleep(.3);
+ propogate(@tile_pos);
+ return 1;
+ }
else {
$status = "That tile is not possible for this space.";
return 0;
@@ -861,19 +889,34 @@ for (;;) {
}
elsif ($c eq "\n") {
if (place_tile()) {
- $turn = !$turn;
if (board_full()) {
+ $turn = !$turn;
@text = @text_2;
start_turn();
}
else {
$status = "";
- draw_tile();
+ if ($invert_tile) {
+ $turn = !$turn;
+ invert_tile();
+ check_can_put();
+ unless ($can_put) {
+ $status = "(It will be changed after being placed.)"
+ }
+ }
+ else {
+ draw_tile();
+ check_can_put();
+ unless ($can_put) {
+ $status = "(It will be changed after being placed.)"
+ }
+ }
+ $invert_tile = !$invert_tile;
}
}
}
else {
- unkown_binding($c);
+ unknown_binding($c);
}
}
else { given ($state) {

0 comments on commit 403dfbc

Please sign in to comment.
Something went wrong with that request. Please try again.