diff options
-rw-r--r-- | hanoi.lua | 17 | ||||
-rw-r--r-- | hanoi.teliva | 17 |
2 files changed, 18 insertions, 16 deletions
diff --git a/hanoi.lua b/hanoi.lua index d8730bd..7a5a938 100644 --- a/hanoi.lua +++ b/hanoi.lua @@ -31,9 +31,9 @@ end local function render_disk(window, line, col, size) col = col-size+1 for i=1,size do - window:attron(curses.color_pair(1)) + window:attron(curses.color_pair(size)) window:mvaddstr(line, col, " ") - window:attroff(curses.color_pair(1)) + window:attroff(curses.color_pair(size)) col = col+2 end end @@ -42,17 +42,17 @@ local function render_tower(window, line, col, tower_index, tower) window:attron(curses.A_BOLD) window:mvaddch(line+2, col, string.char(96+tower_index)) window:attroff(curses.A_BOLD) - window:attron(curses.color_pair(2)) + window:attron(curses.color_pair(7)) window:mvaddstr(line+1, col-6, " ") - window:attroff(curses.color_pair(2)) + window:attroff(curses.color_pair(7)) for i, n in ipairs(tower) do render_disk(window, line, col, n) line = line - 1 end for i=1,5-len(tower)+1 do - window:attron(curses.color_pair(2)) + window:attron(curses.color_pair(7)) window:mvaddstr(line, col, " ") - window:attroff(curses.color_pair(2)) + window:attroff(curses.color_pair(7)) line = line - 1 end end @@ -90,8 +90,9 @@ end local function main() local window = curses.initscr() curses.start_color() - curses.init_pair(1, 0, 2) - curses.init_pair(2, 0, 8) + for i=1,7 do + curses.init_pair(i, 0, i) + end while true do render(window) diff --git a/hanoi.teliva b/hanoi.teliva index ea3b1d6..ba1d9cc 100644 --- a/hanoi.teliva +++ b/hanoi.teliva @@ -31,9 +31,9 @@ end local function render_disk(window, line, col, size) col = col-size+1 for i=1,size do - window:attron(curses.color_pair(1)) + window:attron(curses.color_pair(size)) window:mvaddstr(line, col, " ") - window:attroff(curses.color_pair(1)) + window:attroff(curses.color_pair(size)) col = col+2 end end @@ -42,17 +42,17 @@ local function render_tower(window, line, col, tower_index, tower) window:attron(curses.A_BOLD) window:mvaddch(line+2, col, string.char(96+tower_index)) window:attroff(curses.A_BOLD) - window:attron(curses.color_pair(2)) + window:attron(curses.color_pair(7)) window:mvaddstr(line+1, col-6, " ") - window:attroff(curses.color_pair(2)) + window:attroff(curses.color_pair(7)) for i, n in ipairs(tower) do render_disk(window, line, col, n) line = line - 1 end for i=1,5-len(tower)+1 do - window:attron(curses.color_pair(2)) + window:attron(curses.color_pair(7)) window:mvaddstr(line, col, " ") - window:attroff(curses.color_pair(2)) + window:attroff(curses.color_pair(7)) line = line - 1 end end @@ -89,8 +89,9 @@ end local function main() local window = curses.stdscr() - curses.init_pair(1, 0, 2) - curses.init_pair(2, 0, 8) + for i=1,7 do + curses.init_pair(i, 0, i) + end while true do render(window) |