Module: RTG::Screen

Defined in:
lib/rtg/screen.rb

Constant Summary collapse

WIDTH =
60

Class Method Summary collapse

Class Method Details

.clean_screen(num) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/rtg/screen.rb', line 50

def clean_screen(num)
  _height, width = STDIN.winsize
  num.times do
    puts "\r" + " " * width
  end
  print "\r\e[#{num}A"
end

.main_screen(word) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/rtg/screen.rb', line 7

def main_screen(word)
  diff = word.size - word.uncolorize.size
  puts
  puts ["\t+", "-" * WIDTH, "+"].join
  puts ["\t|", " " * WIDTH, "|"].join
  puts ["\t|", word.center(WIDTH + diff), "|"].join
  puts ["\t|", " " * WIDTH, "|"].join
  puts ["\t+", "-" * WIDTH, "+"].join
  puts
end


18
19
20
21
22
23
# File 'lib/rtg/screen.rb', line 18

def print_time_bar(remain_time)
  puts
  puts ["\t+", "-" * Server::TIME_LIMIT, "+"].join
  puts ["\t", (" " * (Server::TIME_LIMIT - remain_time) + "|" * remain_time).chars.each_slice(Server::TIME_LIMIT).map { |l| l.join.colorize(:green) }, ""].join("|")
  puts ["\t+", "-" * Server::TIME_LIMIT, "+"].join
end

.result_screen(type_count, typo_count) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/rtg/screen.rb', line 37

def result_screen(type_count, typo_count)
  puts
  puts
  puts ["\t+", "-" * WIDTH, "+"].join
  puts ["\t|", " " * WIDTH, "|"].join
  puts ["\t|", "typing speed : #{type_count}/min".center(WIDTH), "|"].join
  puts ["\t|", " " * WIDTH, "|"].join
  puts ["\t+", "-" * WIDTH, "+"].join
  puts
  puts ["\tQ)uit"]
  puts
end

.wait_screenObject



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rtg/screen.rb', line 25

def wait_screen
  puts
  puts
  puts ["\t+", "-" * WIDTH, "+"].join
  puts ["\t|", " " * WIDTH, "|"].join
  puts ["\t|", "Press the `space` key to start game".center(WIDTH), "|"].join
  puts ["\t|", " " * WIDTH, "|"].join
  puts ["\t+", "-" * WIDTH, "+"].join
  puts
  puts
end