-
-
Save tene/1086959 to your computer and use it in GitHub Desktop.
roguelike
This file contains hidden or 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 | |
# Use Moose for the Player class, and other slight improvements. | |
package Player; | |
use v5.10; | |
use strict; | |
use Moose; | |
has 'health' => (is => 'rw', isa => 'Int', default => 100); | |
has 'x' => (is => 'rw', isa => 'Int'); | |
has 'y' => (is => 'rw', isa => 'Int'); | |
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->position($self->y + $y, $self->x + $x); | |
} | |
sub position { | |
my ($self, $y, $x) = @_; | |
if (defined $y and defined $x) { | |
$self->y($y); $self->x($x); | |
} | |
return ($self->y, $self->x); | |
} | |
package main; | |
use v5.10; | |
use strict; | |
use Curses; | |
initscr; | |
my $p = Player->new(x=>5, y=>10); | |
while(1) { | |
addch($p->position,"@"); | |
move($p->position); | |
refresh; | |
$p->walk(getch); | |
clear; | |
} | |
endwin; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment