Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Entity.pm
- use v6;
- need PokeEnv::Grid;
- class PokeEnv::Entity::Entity {
- has PokeEnv::Location $.loc;
- has Int $.id;
- has $.type;
- method new($loc, $type) {
- self.bless(:$loc, :$type);
- }
- method inspect() {
- }
- method interact() {
- }
- method apply() {
- }
- }
- # vim: ft=perl6
- =================================================================================================================
- # Grid.pm
- use v6;
- need PokeEnv::Entity::Entity;
- #class PokeEnv::Entity::Entity { ... }
- class PokeEnv::Location {
- has Int $.x;
- has Int $.y;
- has $.grid;
- method new($x, $y, $grid) {
- self.bless(:$x, :$y, :$grid);
- }
- }
- class PokeEnv::BoundedGrid {
- has Int $.width;
- has Int $.height;
- has %.contents;
- method new(:$x, :$y) {
- self.bless(:width($x), :height($y));
- }
- method put($loc, $ent) {
- say %.contents;
- %.contents{$loc} = $ent;
- say %.contents;
- }
- method rem($loc) {
- %.contents.delete($loc);
- }
- method get($loc) {
- %.contents{$loc};
- }
- method dump() {
- say %.contents;
- my $out = "\t";
- for (0 .. $.width - 1) -> $c { $out ~= "$c\t"; }
- say $out;
- for (0 .. $.height - 1) -> $r {
- $out = "$r\t";
- for (0 .. $.width - 1) -> $c {
- my $loc = PokeEnv::Location.new($r, $c, self);
- if (%.contents{$loc}:exists) {
- $out ~= self.get($loc).type ~ "\t";
- }
- }
- say $out;
- }
- }
- }
- # vim: ft=perl6
Advertisement
Add Comment
Please, Sign In to add comment