Advertisement
Guest User

Untitled

a guest
Mar 4th, 2021
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. class TraceBox is export {
  2. has $!angle;
  3. has Str $.motif is rw = '*';
  4. has $!event;
  5.  
  6. method init {
  7. clear_screen();
  8. #nocursor();
  9. $*OUT.out-buffer = False;
  10. }
  11. method restore() {
  12. cursor();
  13. }
  14. method start_at(:$x,:$y) {
  15. #my Callable $method_right = self.get_method_link('write_right'); #This test to put it into a variable did NOT!
  16. #say 'method_right: ',$method_right; #But at this step the type is GOOD, this means the sub is launched
  17. gotoxy($x,$y);
  18. my $gs = TraceBox.new.write_right;
  19. #say 'gs: ', $gs;
  20. $!event = Event.new(
  21. events => {
  22. (KEY_RIGHT) => self.get_method_link('write_right') ,
  23. (KEY_LEFT) => self.get_method_link('write_left'), #These DO NOT work!! Code is interpolated
  24. (KEY_UP) => self.get_method_link('write_up'),
  25. (KEY_DOWN) => self.get_method_link('write_down')
  26. },
  27. exit_key => 'q',
  28. resume => self.get_method_link('resume'), #THIS WORKS too!!
  29. write_right => $method_right #This is a test #THESE work!!
  30. );
  31. self.init();
  32. $!event.wait_event()
  33. }
  34. method get_method_link(Str $name) {
  35. my $method = self.^lookup($name);
  36. my $bound_method = $method_bar.assuming(self);
  37. return $bound_method;
  38. }
  39. method go_right(){
  40. move_right(1);
  41. }
  42. method go_left(){
  43. move_left(1);
  44. }
  45. method go_up(){
  46. move_up(1);
  47. }
  48. method go_down(){
  49. move_down(1);
  50. }
  51. method write_right(){
  52. print $!motif;
  53. }
  54. method write_left(){
  55. move_left(1);
  56. print $!motif;
  57. }
  58. method write_up(){
  59. move_up(1);
  60. move_left(1);
  61. print $!motif;
  62. }
  63. method write_down(){
  64. move_down(1);
  65. move_left(1);
  66. print $!motif;
  67. }
  68. method resume() {
  69. say 'RESTORE';
  70. self.restore();
  71. }
  72.  
  73.  
  74. }
  75.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement