Class: RubySnake::UI
- Inherits:
-
Object
- Object
- RubySnake::UI
- Defined in:
- lib/ruby_snake/ui.rb,
lib/ruby_snake/ui/one.rb,
lib/ruby_snake/ui/two.rb,
lib/ruby_snake/ui/base.rb
Defined Under Namespace
Class Method Summary collapse
- .draw ⇒ Object
- .draw_dialog(y, x, text) ⇒ Object
- .draw_role_menu ⇒ Object
- .draw_welcome ⇒ Object
- .init ⇒ Object
- .init_window ⇒ Object
- .window ⇒ Object
Class Method Details
.draw ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/ruby_snake/ui.rb', line 82 def draw if Game.vs? Two.draw else One.draw end end |
.draw_dialog(y, x, text) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/ruby_snake/ui.rb', line 55 def draw_dialog y, x, text text = " < #{text} > " << ' .-. / aa \ -,_) _..._| \ `-< {} .\" .__.\' | {} ( /`\ {}(`\'------\' / |\/;._______.\'\ ; \ / \'-\'-.......-\' ' window.mvaddstr y, x, text window.refresh end |
.draw_role_menu ⇒ Object
48 49 50 51 52 53 |
# File 'lib/ruby_snake/ui.rb', line 48 def Ncurses.nodelay window, false x = window.getmaxx / 2 y = window.getmaxy / 2 - 10 draw_dialog y, x, 'Create Host? (s) or Connect to a Host? (c)' end |
.draw_welcome ⇒ Object
37 38 39 40 41 42 |
# File 'lib/ruby_snake/ui.rb', line 37 def draw_welcome Ncurses.nodelay window, false x = window.getmaxx / 2 y = window.getmaxy / 2 - 10 draw_dialog y, x, 'Single Player? (s) or Two Players? (t)' end |
.init ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/ruby_snake/ui.rb', line 8 def init Ncurses.initscr Ncurses.cbreak Ncurses.noecho Ncurses.nonl Ncurses.stdscr.intrflush(false) Ncurses.stdscr.keypad(true) Ncurses.curs_set 0 Ncurses.start_color Ncurses.init_pair(1, Ncurses::COLOR_RED, Ncurses::COLOR_BLACK); Ncurses.init_pair(2, Ncurses::COLOR_CYAN, Ncurses::COLOR_BLACK); Ncurses.init_pair(3, Ncurses::COLOR_YELLOW, Ncurses::COLOR_BLACK); Ncurses.init_pair(4, Ncurses::COLOR_GREEN, Ncurses::COLOR_BLACK); init_window end |
.init_window ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ruby_snake/ui.rb', line 26 def init_window x = (Ncurses.stdscr.getmaxy - 30) / 2 y = (Ncurses.stdscr.getmaxx - 101) / 2 @window = Ncurses::WINDOW.new 30, 101, x, y unless @window Ncurses.endwin raise 'Terminal screen size is not big enough' end end |
.window ⇒ Object
44 45 46 |
# File 'lib/ruby_snake/ui.rb', line 44 def window @window end |