mirror of
https://github.com/gwenhael-le-moine/c-urs_-toil-s.git
synced 2024-12-26 09:58:48 +01:00
working on a ncurses Ruby version, not finished
This commit is contained in:
parent
84133b8ec4
commit
046fbf63fe
1 changed files with 91 additions and 33 deletions
74
star.rb
74
star.rb
|
@ -1,3 +1,5 @@
|
||||||
|
require 'ncursesw'
|
||||||
|
|
||||||
LEVEL_HEIGHT = 9
|
LEVEL_HEIGHT = 9
|
||||||
LEVEL_WIDTH = 16
|
LEVEL_WIDTH = 16
|
||||||
|
|
||||||
|
@ -115,17 +117,73 @@ class Star
|
||||||
end
|
end
|
||||||
return s
|
return s
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def nc_display( )
|
||||||
|
LEVEL_HEIGHT.times do
|
||||||
|
|y|
|
||||||
|
LEVEL_WIDTH.times do
|
||||||
|
|x|
|
||||||
|
Ncurses.stdscr.mvprintw( y+1, x*2, @elements[ get_cell( x, y ) ][ :text ] )
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
Ncurses.initscr
|
||||||
|
begin
|
||||||
|
# if (Ncurses.has_colors?)
|
||||||
|
# bg = Ncurses::COLOR_BLACK
|
||||||
|
# Ncurses.start_color
|
||||||
|
# if (Ncurses.respond_to?("use_default_colors"))
|
||||||
|
# if (Ncurses.use_default_colors == Ncurses::OK)
|
||||||
|
# bg = -1
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
# Ncurses.init_pair(1, Ncurses::COLOR_BLUE, bg);
|
||||||
|
# Ncurses.init_pair(2, Ncurses::COLOR_CYAN, bg);
|
||||||
|
# end
|
||||||
|
Ncurses.nl()
|
||||||
|
Ncurses.noecho()
|
||||||
|
Ncurses.curs_set(0)
|
||||||
|
Ncurses.stdscr.nodelay(true)
|
||||||
|
|
||||||
st = Star.new
|
st = Star.new
|
||||||
puts st.to_s
|
|
||||||
|
|
||||||
moves = [ :down, :right, :down, :left, :up, :right, :up, :left, :down, :right, :down, :left, :right, :up, :left, :up, :right, :up, :down, :left, :up, :right, :down, :up, :left, ]
|
begin
|
||||||
|
case(Ncurses.getch())
|
||||||
moves.each do
|
when 'q'[0], 'Q'[0]
|
||||||
|direction|
|
Ncurses.curs_set(1)
|
||||||
st.move( direction )
|
Ncurses.endwin()
|
||||||
puts st.is_it_over? ? "YES \o/" : "not yet"
|
exit
|
||||||
|
when 'h'
|
||||||
|
st.move( :left )
|
||||||
|
st.nc_display( )
|
||||||
|
when 'j'[0]
|
||||||
|
st.move( :down )
|
||||||
|
st.nc_display( )
|
||||||
|
when 'k'[0]
|
||||||
|
st.move( :up )
|
||||||
|
st.nc_display( )
|
||||||
|
when 'l'[0]
|
||||||
|
st.move( :right )
|
||||||
|
st.nc_display( )
|
||||||
end
|
end
|
||||||
|
|
||||||
puts st.to_s
|
st.nc_display( )
|
||||||
|
Ncurses.refresh
|
||||||
|
end while true
|
||||||
|
ensure
|
||||||
|
Ncurses.curs_set(1)
|
||||||
|
Ncurses.endwin()
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
# moves = [ :down, :right, :down, :left, :up, :right, :up, :left, :down, :right, :down, :left, :right, :up, :left, :up, :right, :up, :down, :left, :up, :right, :down, :up, :left, ]
|
||||||
|
|
||||||
|
# moves.each do
|
||||||
|
# |direction|
|
||||||
|
# st.move( direction )
|
||||||
|
# puts st.is_it_over? ? "YES \o/" : "not yet"
|
||||||
|
# end
|
||||||
|
|
||||||
|
#puts st.to_s
|
||||||
|
|
Loading…
Reference in a new issue