Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[bin/crypt] PlayerLooked includes list of things

  • Loading branch information...
commit d807669a4a8e780a964b6bdae00f01c0ed989cc4 1 parent e5c5198
Carl Mäsak authored July 16, 2012

Showing 1 changed file with 22 additions and 0 deletions. Show diff stats Hide diff stats

  1. 22  bin/crypt
22  bin/crypt
@@ -243,6 +243,7 @@ class Adventure::PlayerWasPlaced does Event {
243 243
 class Adventure::PlayerLooked does Event {
244 244
     has $.room;
245 245
     has @.exits;
  246
+    has @.things;
246 247
 }
247 248
 
248 249
 class Adventure::TwoRoomsConnected does Event {
@@ -453,6 +454,11 @@ class Adventure::Engine {
453 454
         self!apply_and_return: @events;
454 455
     }
455 456
 
  457
+    method !things_here {
  458
+        return unless $!player_location;
  459
+        return %!thing_rooms.grep({ .value eq $!player_location })>>.key;
  460
+    }
  461
+
456 462
     method walk($direction) {
457 463
         die X::Adventure::PlayerNowhere.new()
458 464
             unless defined $!player_location;
@@ -477,6 +483,7 @@ class Adventure::Engine {
477 483
             @events.push(Adventure::PlayerLooked.new(
478 484
                 :room($to),
479 485
                 :exits((%!exits{$to} // ()).keys),
  486
+                :things(self!things_here),
480 487
             ));
481 488
         }
482 489
         self!apply_and_return: @events;
@@ -489,6 +496,7 @@ class Adventure::Engine {
489 496
         my @events = Adventure::PlayerLooked.new(
490 497
             :room($!player_location),
491 498
             :exits((%!exits{$!player_location} // ()).keys),
  499
+            :things(self!things_here),
492 500
         );
493 501
         self!apply_and_return: @events;
494 502
     }
@@ -499,6 +507,7 @@ class Adventure::Engine {
499 507
             @events.push(Adventure::PlayerLooked.new(
500 508
                 :room($in),
501 509
                 :exits((%!exits{$in} // ()).keys),
  510
+                :things(self!things_here),
502 511
             ));
503 512
         }
504 513
         self!apply_and_return: @events;
@@ -1616,6 +1625,19 @@ multi MAIN('test') {
1616 1625
             'taking a thing (+) take, drop, take';
1617 1626
     }
1618 1627
 
  1628
+    {
  1629
+        my $engine = Adventure::Engine.new();
  1630
+
  1631
+        $engine.place_thing('dog', 'street');
  1632
+        $engine.place_player('street');
  1633
+        is $engine.look(),
  1634
+            Adventure::PlayerLooked.new(
  1635
+                :room<street>,
  1636
+                :things<dog>,
  1637
+            ),
  1638
+            'looking at the room, explicit thing';
  1639
+    }
  1640
+
1619 1641
     done;
1620 1642
 }
1621 1643
 

0 notes on commit d807669

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