Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[bin/crypt] automatically 'look' new rooms

This is what most adventure games do, so it feels like a good
default behavior.

Had to change some tests, but I still think this is a net win.
  • Loading branch information...
commit 8896863e9baa0130977bad88c65106e58dd95cef 1 parent 30ed2fb
Carl Mäsak authored July 06, 2012

Showing 1 changed file with 27 additions and 16 deletions. Show diff stats Hide diff stats

  1. 43  bin/crypt
43  bin/crypt
@@ -237,7 +237,6 @@ class Adventure::PlayerWasPlaced does Event {
237 237
 }
238 238
 
239 239
 class Adventure::PlayerLooked does Event {
240  
-    has $.target;
241 240
     has $.description_of;
242 241
 }
243 242
 
@@ -287,6 +286,7 @@ class Adventure::Engine {
287 286
     has $!player_location;
288 287
     has %!exits;
289 288
     has %!exit_aliases;
  289
+    has %!seen_room;
290 290
 
291 291
     method connect(@rooms, $direction) {
292 292
         die X::Adventure::NoSuchDirection.new(:action('connect rooms'), :$direction)
@@ -313,12 +313,18 @@ class Adventure::Engine {
313 313
             unless defined $to;
314 314
 
315 315
         my @events = Adventure::PlayerWalked.new(:$to);
  316
+        unless %!seen_room{$to}++ {
  317
+            @events.push(Adventure::PlayerLooked.new(:description_of($to)));
  318
+        }
316 319
         self!apply($_) for @events;
317 320
         @events;
318 321
     }
319 322
 
320 323
     method place_player($in) {
321 324
         my @events = Adventure::PlayerWasPlaced.new(:$in);
  325
+        unless %!seen_room{$in}++ {
  326
+            @events.push(Adventure::PlayerLooked.new(:description_of($in)));
  327
+        }
322 328
         self!apply($_) for @events;
323 329
         @events;
324 330
     }
@@ -388,7 +394,7 @@ class Crypt::Game {
388 394
     }
389 395
 
390 396
     method look() {
391  
-        Adventure::PlayerLooked.new(:target<room>, :description_of<clearing>);
  397
+        Adventure::PlayerLooked.new(:description_of<clearing>);
392 398
     }
393 399
 }
394 400
 
@@ -607,7 +613,6 @@ multi MAIN('test') {
607 613
 
608 614
         is $game.look(),
609 615
             Adventure::PlayerLooked.new(
610  
-                :target('room'),
611 616
                 :description_of<clearing>,
612 617
             ),
613 618
             'looking at the room';
@@ -646,9 +651,14 @@ multi MAIN('test') {
646 651
         my $game = Crypt::Game.new();
647 652
 
648 653
         is $game.walk('east'),
649  
-            Adventure::PlayerWalked.new(
650  
-                :to<hill>,
651  
-            ),
  654
+            [
  655
+                Adventure::PlayerWalked.new(
  656
+                    :to<hill>,
  657
+                ),
  658
+                Adventure::PlayerLooked.new(
  659
+                    :description_of<hill>,
  660
+                ),
  661
+            ],
652 662
             'walking (+)';
653 663
     }
654 664
 
@@ -687,12 +697,8 @@ multi MAIN('test') {
687 697
                 :$direction,
688 698
             ),
689 699
             'connecting two rooms vertically';
690  
-        is $engine.place_player('first_floor'),
691  
-            Adventure::PlayerWasPlaced.new(
692  
-                :in<first_floor>,
693  
-            ),
694  
-            'placing the player';
695  
-        is $engine.walk('up'),
  700
+        $engine.place_player('first_floor');
  701
+        is $engine.walk('up')[0],
696 702
             Adventure::PlayerWalked.new(
697 703
                 :to<second_floor>,
698 704
             ),
@@ -716,15 +722,20 @@ multi MAIN('test') {
716 722
                 :alias<in>,
717 723
             ),
718 724
             'aliasing "southwest" as "in"';
719  
-        is $engine.place_player('outside'),
  725
+        is $engine.place_player('outside')[0],
720 726
             Adventure::PlayerWasPlaced.new(
721 727
                 :in<outside>,
722 728
             ),
723 729
             'placing the player';
724 730
         is $engine.walk('in'),
725  
-            Adventure::PlayerWalked.new(
726  
-                :to<inside>,
727  
-            ),
  731
+            [
  732
+                Adventure::PlayerWalked.new(
  733
+                    :to<inside>,
  734
+                ),
  735
+                Adventure::PlayerLooked.new(
  736
+                    :description_of<inside>,
  737
+                ),
  738
+            ],
728 739
             'going inside now means going southwest';
729 740
     }
730 741
 

0 notes on commit 8896863

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