Class: RubySnake::UI::Two
- Inherits:
-
Base
- Object
- Base
- RubySnake::UI::Two
show all
- Defined in:
- lib/ruby_snake/ui/two.rb
Class Method Summary
collapse
Methods inherited from Base
clear_tail, display, draw_dialog, draw_food
Class Method Details
.clear_windows ⇒ Object
37
38
39
40
41
42
|
# File 'lib/ruby_snake/ui/two.rb', line 37
def clear_windows
local_window.clear
local_window.noutrefresh
remote_window.clear
remote_window.noutrefresh
end
|
.draw_local ⇒ Object
79
80
81
82
83
84
85
|
# File 'lib/ruby_snake/ui/two.rb', line 79
def draw_local
draw_snake
draw_food
draw_score
window.noutrefresh
clear_tail
end
|
.draw_lose ⇒ Object
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/ruby_snake/ui/two.rb', line 44
def draw_lose
clear_windows
@local_window = UI.window
window.color_set 1, nil
Ncurses.nodelay window, false
x = window.getmaxx / 2
y = window.getmaxy / 2 - 10
draw_dialog y, x, "Sorry, you lose the game."
window.refresh
end
|
.draw_map ⇒ Object
114
115
116
117
118
119
|
# File 'lib/ruby_snake/ui/two.rb', line 114
def draw_map
draw_local
draw_remote
Ncurses.doupdate
sleep 0.1
end
|
.draw_remote ⇒ Object
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
# File 'lib/ruby_snake/ui/two.rb', line 93
def draw_remote
begin
receive = Game.role_class.receive
food = receive.shift
snake = receive
remote_window.color_set 1, nil
remote_display food, '$'
remote_window.mvprintw 0, 0, (50 - snake.length + 2).to_s
remote_window.color_set 2, nil
head = snake.shift
remote_display head, '@'
remote_window.noutrefresh
remote_display snake.last, ' '
rescue
nil
end
end
|
.draw_score ⇒ Object
75
76
77
|
# File 'lib/ruby_snake/ui/two.rb', line 75
def draw_score
window.mvprintw 0, 0, score.to_s
end
|
.draw_snake ⇒ Object
65
66
67
68
69
|
# File 'lib/ruby_snake/ui/two.rb', line 65
def draw_snake
window.color_set 2, nil
super
end
|
.draw_win ⇒ Object
55
56
57
58
59
60
61
62
63
|
# File 'lib/ruby_snake/ui/two.rb', line 55
def draw_win
clear_windows
@local_window = UI.window
window.color_set 4, nil
x = window.getmaxx / 2
y = window.getmaxy / 2 - 10
draw_dialog y, x, "Congratulations, you win the game."
window.refresh
end
|
.init_windows ⇒ Object
5
6
7
8
9
10
11
|
# File 'lib/ruby_snake/ui/two.rb', line 5
def init_windows
local_window.border *([0]*8)
remote_window.border *([0]*8)
local_window.noutrefresh
remote_window.noutrefresh
@snake ||= Snake.new local_window.getmaxx, local_window.getmaxy
end
|
.local_window ⇒ Object
13
14
15
16
17
18
|
# File 'lib/ruby_snake/ui/two.rb', line 13
def local_window
x = (Ncurses.stdscr.getmaxy - 30) / 2
y = (Ncurses.stdscr.getmaxx - 102) / 2
@local_window ||= Ncurses::WINDOW.new 30, 51, x, y
end
|
.remote_display(stuff, symbol) ⇒ Object
87
88
89
90
91
|
# File 'lib/ruby_snake/ui/two.rb', line 87
def remote_display stuff, symbol
x = stuff.last + 1
y = stuff.first + 1
remote_window.mvprintw x, y, symbol
end
|
.remote_window ⇒ Object
20
21
22
23
24
25
26
27
|
# File 'lib/ruby_snake/ui/two.rb', line 20
def remote_window
x = (Ncurses.stdscr.getmaxy - 30) / 2
y = Ncurses.stdscr.getmaxx / 2
@remote_window ||= Ncurses::WINDOW.new 30,
51,
x,
y
end
|
.score ⇒ Object
71
72
73
|
# File 'lib/ruby_snake/ui/two.rb', line 71
def score
50 - snake.body.length + 2
end
|
.snake ⇒ Object
29
30
31
|
# File 'lib/ruby_snake/ui/two.rb', line 29
def snake
@snake
end
|
.window ⇒ Object
33
34
35
|
# File 'lib/ruby_snake/ui/two.rb', line 33
def window
@local_window
end
|