Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class TraceBox is export {
- has $!angle;
- has Str $.motif is rw = '*';
- has $!event;
- method init {
- clear_screen();
- #nocursor();
- $*OUT.out-buffer = False;
- }
- method restore() {
- cursor();
- }
- method start_at(:$x,:$y) {
- #my Callable $method_right = self.get_method_link('write_right'); #This test to put it into a variable did NOT!
- #say 'method_right: ',$method_right; #But at this step the type is GOOD, this means the sub is launched
- gotoxy($x,$y);
- my $gs = TraceBox.new.write_right;
- #say 'gs: ', $gs;
- $!event = Event.new(
- events => {
- (KEY_RIGHT) => self.get_method_link('write_right') ,
- (KEY_LEFT) => self.get_method_link('write_left'), #These DO NOT work!! Code is interpolated
- (KEY_UP) => self.get_method_link('write_up'),
- (KEY_DOWN) => self.get_method_link('write_down')
- },
- exit_key => 'q',
- resume => self.get_method_link('resume'), #THIS WORKS too!!
- write_right => $method_right #This is a test #THESE work!!
- );
- self.init();
- $!event.wait_event()
- }
- method get_method_link(Str $name) {
- my $method = self.^lookup($name);
- my $bound_method = $method_bar.assuming(self);
- return $bound_method;
- }
- method go_right(){
- move_right(1);
- }
- method go_left(){
- move_left(1);
- }
- method go_up(){
- move_up(1);
- }
- method go_down(){
- move_down(1);
- }
- method write_right(){
- print $!motif;
- }
- method write_left(){
- move_left(1);
- print $!motif;
- }
- method write_up(){
- move_up(1);
- move_left(1);
- print $!motif;
- }
- method write_down(){
- move_down(1);
- move_left(1);
- print $!motif;
- }
- method resume() {
- say 'RESTORE';
- self.restore();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement