Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[bin/crypt] can't see in hall

  • Loading branch information...
commit e90ce36e75c3d845951f22490e93c5dbfb8916cb 1 parent c2cab1d
Carl Mäsak authored July 21, 2012

Showing 1 changed file with 59 additions and 10 deletions. Show diff stats Hide diff stats

  1. 69  bin/crypt
69  bin/crypt
@@ -329,6 +329,13 @@ class Adventure::GameRemarked does Event {
329 329
     has $.remark;
330 330
 }
331 331
 
  332
+class Adventure::PlayerLookedAtDarkness does Event {
  333
+}
  334
+
  335
+class Adventure::RoomMadeDark does Event {
  336
+    has $.room;
  337
+}
  338
+
332 339
 class X::Adventure is Exception {
333 340
 }
334 341
 
@@ -461,6 +468,7 @@ class Adventure::Engine {
461 468
     has %!implicit_things;
462 469
     has %!open_hooks;
463 470
     has %!put_hooks;
  471
+    has %!dark_rooms;
464 472
 
465 473
     method connect(@rooms, $direction) {
466 474
         die X::Adventure::NoSuchDirection.new(:action('connect rooms'), :$direction)
@@ -528,11 +536,18 @@ class Adventure::Engine {
528 536
 
529 537
         my @events = Adventure::PlayerWalked.new(:$to);
530 538
         unless %!seen_room{$to}++ {
531  
-            @events.push(Adventure::PlayerLooked.new(
532  
-                :room($to),
533  
-                :exits((%!exits{$to} // ()).keys),
534  
-                :things(self!explicit_things_at($to)),
535  
-            ));
  539
+            my $pitch_black = %!dark_rooms{$!player_location};
  540
+
  541
+            if $pitch_black {
  542
+                @events.push(Adventure::PlayerLookedAtDarkness.new());
  543
+            }
  544
+            else {
  545
+                @events.push(Adventure::PlayerLooked.new(
  546
+                    :room($to),
  547
+                    :exits((%!exits{$to} // ()).keys),
  548
+                    :things(self!explicit_things_at($to)),
  549
+                ));
  550
+            }
536 551
         }
537 552
         self!apply_and_return: @events;
538 553
     }
@@ -541,11 +556,15 @@ class Adventure::Engine {
541 556
         die X::Adventure::PlayerNowhere.new()
542 557
             unless defined $!player_location;
543 558
 
544  
-        my @events = Adventure::PlayerLooked.new(
545  
-            :room($!player_location),
546  
-            :exits((%!exits{$!player_location} // ()).keys),
547  
-            :things(self!explicit_things_at($!player_location)),
548  
-        );
  559
+        my $pitch_black = %!dark_rooms{$!player_location};
  560
+
  561
+        my @events = $pitch_black
  562
+            ?? Adventure::PlayerLookedAtDarkness.new()
  563
+            !! Adventure::PlayerLooked.new(
  564
+                   :room($!player_location),
  565
+                   :exits((%!exits{$!player_location} // ()).keys),
  566
+                   :things(self!explicit_things_at($!player_location)),
  567
+               );
549 568
         self!apply_and_return: @events;
550 569
     }
551 570
 
@@ -766,6 +785,11 @@ class Adventure::Engine {
766 785
         self!apply_and_return: @events;
767 786
     }
768 787
 
  788
+    method make_room_dark($room) {
  789
+        my @events = Adventure::RoomMadeDark.new(:$room);
  790
+        self!apply_and_return: @events;
  791
+    }
  792
+
769 793
     method on_try_exit($room, $direction, &hook) {
770 794
         %!try_exit_hooks{$room}{$direction} = &hook;
771 795
     }
@@ -866,6 +890,9 @@ class Adventure::Engine {
866 890
         when Adventure::ThingMadeImplicit {
867 891
             %!implicit_things{.thing} = True;
868 892
         }
  893
+        when Adventure::RoomMadeDark {
  894
+            %!dark_rooms{.room} = True;
  895
+        }
869 896
     }
870 897
 }
871 898
 
@@ -889,6 +916,9 @@ class Crypt::Game {
889 916
                 say "You try to walk past the fire, but it's too hot!";
890 917
                 False;
891 918
             });
  919
+            .make_room_dark('hall');
  920
+            .make_room_dark('cave');
  921
+            .make_room_dark('crypt');
892 922
 
893 923
             # Things in clearing
894 924
             .place_thing('car', 'clearing');
@@ -2043,6 +2073,8 @@ multi MAIN('test') {
2043 2073
     sub game_from_chamber {
2044 2074
         my $game = Crypt::Game.new();
2045 2075
 
  2076
+        $game.open('car');
  2077
+        $game.take('flashlight');
2046 2078
         $game.walk('east');
2047 2079
         $game.take('leaves');
2048 2080
         $game.examine('bushes');
@@ -2081,6 +2113,23 @@ multi MAIN('test') {
2081 2113
             'reading the sign';
2082 2114
     }
2083 2115
 
  2116
+    sub game_from_hall {
  2117
+        my $game = game_from_chamber();
  2118
+
  2119
+        $game.put_thing_in('leaves', 'basket'),
  2120
+        $game.walk('south');
  2121
+        return $game;
  2122
+    }
  2123
+
  2124
+    {
  2125
+        my $game = game_from_hall();
  2126
+
  2127
+        is $game.look(),
  2128
+            Adventure::PlayerLookedAtDarkness.new(
  2129
+            ),
  2130
+            'looking without the flashlight';
  2131
+    }
  2132
+
2084 2133
     done;
2085 2134
 }
2086 2135
 

0 notes on commit e90ce36

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