Class: Burn::Generator::Telnet::Screen

Inherits:
Object
  • Object
show all
Includes:
Debug
Defined in:
lib/burn/generator/telnet/screen.rb

Constant Summary collapse

ESC =

equal to “033”

27.chr
CLEARSCREEN =
ESC + "[2J"
JUMPTOHOME =
ESC + "[H"
RESETALLATTR =
ESC + "[0m"
CRLF =
13.chr + 10.chr

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Debug

#log

Constructor Details

#initialize(conf) ⇒ Screen

Returns a new instance of Screen.



14
15
16
17
18
19
20
# File 'lib/burn/generator/telnet/screen.rb', line 14

def initialize(conf)
  @fg_color = 37
  @bg_color = 40
  @activated_sprite_objects = [] # activated sprite objects by #sprite method call during main_loop will be contained
  @conf = conf
  flush_screen
end

Instance Attribute Details

#activated_sprite_objectsObject

Returns the value of attribute activated_sprite_objects.



12
13
14
# File 'lib/burn/generator/telnet/screen.rb', line 12

def activated_sprite_objects
  @activated_sprite_objects
end

#bg_colorObject

Returns the value of attribute bg_color.



12
13
14
# File 'lib/burn/generator/telnet/screen.rb', line 12

def bg_color
  @bg_color
end

#displayObject

Returns the value of attribute display.



12
13
14
# File 'lib/burn/generator/telnet/screen.rb', line 12

def display
  @display
end

#fg_colorObject

Returns the value of attribute fg_color.



12
13
14
# File 'lib/burn/generator/telnet/screen.rb', line 12

def fg_color
  @fg_color
end

Instance Method Details

#flush_screenObject



34
35
36
37
38
# File 'lib/burn/generator/telnet/screen.rb', line 34

def flush_screen
  @display = Array.new
  @conf.app.height.times{ @display << Array.new(@conf.app.width){' '}.join }
  @activated_sprite_objects = []
end

#is_pressed(key, user_input) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/burn/generator/telnet/screen.rb', line 40

def is_pressed(key, user_input)
  log " ** program is waiting for:" + key.to_s
  if !user_input.nil? then
    log " **** confiremd user input:" + user_input.class.to_s, user_input.chr, user_input.to_s
    if [*'0'..'9', *'a'..'z', *'A'..'Z',10.chr,13.chr].include?(user_input.chr) && key.to_s == user_input.chr then
      log "****** is_pressed() returned true"
      return true
    end
  end
  false
end

#to_terminalObject



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/burn/generator/telnet/screen.rb', line 22

def to_terminal
  #CLEARSCREEN + escape_color(@fg_color) + escape_color(@bg_color) + @display.join("\r\n") + JUMPTOHOME + RESETALLATTR
  #JUMPTOHOME + RESETALLATTR + CLEARSCREEN + escape_color(@fg_color) + escape_color(@bg_color) + @display.join("\r\n") + ESC + "[#{@conf.app.height};2H" + RESETALLATTR
  #CLEARSCREEN + escape_color(@fg_color) + escape_color(@bg_color) + @display.join("\r\n") + ESC + "[#{@conf.app.height};2H" + RESETALLATTR
  #JUMPTOHOME + crlf + crlf + crlf + crlf + crlf + crlf + @display.join(crlf)
  #JUMPTOHOME + crlf + crlf + crlf + crlf + crlf + crlf + @display.join(crlf) + crlf
  #JUMPTOHOME + @display.join(CRLF) + CRLF

  JUMPTOHOME +  escape_color(@fg_color) + escape_color(@bg_color) + ppu_emulate + CRLF + RESETALLATTR
  #JUMPTOHOME + @display.join(CRLF) + CRLF
end