Guest User

Untitled

a guest
Feb 20th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. module Tetris
  2. module Field
  3. WIDTH = 12
  4. HEIGHT = 12
  5.  
  6. class << self
  7. def highline
  8. @highline ||= HighLine.new
  9. end
  10.  
  11. def color(*args)
  12. highline.color(*args)
  13. end
  14.  
  15. def clear_screen
  16. write "\e[2J"
  17. end
  18.  
  19. def reset_cursor
  20. write "\e[2H"
  21. end
  22.  
  23. def hide_cursor
  24. write "\e[?25l"
  25. end
  26.  
  27. def move_cursor(x, y)
  28. write "\e[#{y};#{x}H"
  29. end
  30.  
  31. # Gibt die übergebenen Argumente über $stdout.write aus.
  32. # $stdout wird im nachinein geflusht.
  33. def write(*args)
  34. $stdout.write(*args)
  35. $stdout.flush
  36. end
  37.  
  38. def draw_border
  39. reset_cursor
  40.  
  41. output = []
  42. output << [::Unicode::U2551, ' ' * WIDTH, ::Unicode::U2551]
  43. output << [::Unicode::U2551, ' ' * WIDTH, ::Unicode::U2551]
  44. output << [::Unicode::U2551, ' ' * WIDTH, ::Unicode::U2551]
  45. output << [::Unicode::U2551, ' ' * WIDTH, ::Unicode::U2551]
  46. output << [::Unicode::U2551, ' ' * WIDTH, ::Unicode::U2551]
  47. output << [::Unicode::U2551, ' ' * WIDTH, ::Unicode::U2551]
  48. output << [::Unicode::U2551, ' ' * WIDTH, ::Unicode::U2551]
  49. output << [::Unicode::U2551, ' ' * WIDTH, ::Unicode::U2551]
  50. output << [::Unicode::U255A, ::Unicode::U2550 * WIDTH, ::Unicode::U255D]
  51.  
  52. puts output.map { |x| x.join('') }
  53. end
  54.  
  55. def draw_fixed_stones
  56. # NOOP
  57. end
  58.  
  59. def draw_at(chars, options = {})
  60. move_cursor(options[:x] || 0, options[:y] || 0)
  61. write(chars)
  62. end
  63.  
  64. end
  65. end
  66. end
Add Comment
Please, Sign In to add comment