Skip to content

Instantly share code, notes, and snippets.

@djanatyn
Created July 17, 2011 03:03
Show Gist options
  • Save djanatyn/1087079 to your computer and use it in GitHub Desktop.
Save djanatyn/1087079 to your computer and use it in GitHub Desktop.
object oriented
#!/usr/bin/perl -w
package Player;
use strict;
use Curses;
use Moose;
has 'health' => (is => 'rw', isa => 'Int', default => 100);
has 'x' => (is => 'rw', isa => 'Int', default => 5);
has 'y' => (is => 'rw', isa => 'Int', default => 5);
sub walk {
my ($self,$ch) = @_;
my %map = (
h => [0,-1],
j => [1,0],
k => [-1,0],
l => [0,1],
);
my ($y,$x) = @{$map{$ch}};
$self->y($self->y + $y); $self->x($self->x + $x);
return ($self->y ,$self->x);
}
package main;
use strict;
use Curses;
initscr;
my $player = Player->new;
while(1) {
clear;
addch($player->y, $player->x,"@");
move($player->walk(getch));
refresh;
}
endwin;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment