Created
July 17, 2011 03:03
-
-
Save djanatyn/1087079 to your computer and use it in GitHub Desktop.
object oriented
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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