Advertisement
Guest User

Untitled

a guest
Jun 12th, 2014
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 6 2.10 KB | None | 0 0
  1. # Entity.pm
  2.  
  3. use v6;
  4. need PokeEnv::Grid;
  5.  
  6. class PokeEnv::Entity::Entity {
  7.         has     PokeEnv::Location       $.loc;
  8.         has     Int                     $.id;
  9.         has                             $.type;
  10.  
  11.         method new($loc, $type) {
  12.                 self.bless(:$loc, :$type);
  13.         }
  14.  
  15.         method inspect() {
  16.  
  17.         }
  18.  
  19.         method interact() {
  20.  
  21.         }
  22.  
  23.         method apply() {
  24.  
  25.         }
  26. }
  27.  
  28. # vim: ft=perl6
  29.  
  30. =================================================================================================================
  31.  
  32. # Grid.pm
  33. use v6;
  34. need PokeEnv::Entity::Entity;
  35.  
  36. #class PokeEnv::Entity::Entity { ... }
  37. class PokeEnv::Location {
  38.         has     Int     $.x;
  39.         has     Int     $.y;
  40.         has             $.grid;
  41.  
  42.         method new($x, $y, $grid) {
  43.                 self.bless(:$x, :$y, :$grid);
  44.         }
  45. }
  46.  
  47. class PokeEnv::BoundedGrid {
  48.         has     Int     $.width;
  49.         has     Int     $.height;
  50.         has             %.contents;
  51.  
  52.         method new(:$x, :$y) {
  53.                 self.bless(:width($x), :height($y));
  54.         }
  55.  
  56.         method put($loc, $ent) {
  57.                 say %.contents;
  58.                 %.contents{$loc} = $ent;
  59.                 say %.contents;
  60.         }
  61.  
  62.         method rem($loc) {
  63.                 %.contents.delete($loc);
  64.         }
  65.  
  66.         method get($loc) {
  67.                 %.contents{$loc};
  68.         }
  69.  
  70.         method dump() {
  71.                 say %.contents;
  72.                 my $out = "\t";
  73.                 for (0 .. $.width - 1) -> $c { $out ~= "$c\t"; }
  74.                 say $out;
  75.  
  76.                 for (0 .. $.height - 1) -> $r {
  77.                         $out = "$r\t";
  78.                         for (0 .. $.width - 1) -> $c {
  79.                                 my $loc = PokeEnv::Location.new($r, $c, self);
  80.                                 if (%.contents{$loc}:exists) {
  81.                                         $out ~= self.get($loc).type ~ "\t";
  82.                                 }
  83.                         }
  84.                         say $out;
  85.                 }
  86.         }
  87. }
  88.  
  89. # vim: ft=perl6
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement