diff options
-rw-r--r-- | hanoi.lua | 27 | ||||
-rw-r--r-- | hanoi.teliva | 23 |
2 files changed, 16 insertions, 34 deletions
diff --git a/hanoi.lua b/hanoi.lua index 7a5a938..f216570 100644 --- a/hanoi.lua +++ b/hanoi.lua @@ -1,9 +1,7 @@ local curses = require "curses" - tower = {{6, 5, 4, 3, 2}, {}, {}} - local function len(array) local result = 0 for k in pairs(array) do @@ -12,7 +10,6 @@ local function len(array) return result end - local function pop(array) return table.remove(array) end @@ -57,7 +54,6 @@ local function render_tower(window, line, col, tower_index, tower) end end - local function render(window) window:clear() local lines, cols = window:getmaxyx() @@ -75,7 +71,6 @@ local function make_move(from, to) table.insert(tower[to], disk) end - local function update(window) window:mvaddstr(lines(window)-2, 5, "tower to remove top disk from? ") local from = string.byte(curses.getch()) - 96 @@ -87,20 +82,16 @@ local function update(window) end -local function main() - local window = curses.initscr() - curses.start_color() - for i=1,7 do - curses.init_pair(i, 0, i) - end - - while true do - render(window) - update(window) - end +window = curses.initscr() +curses.start_color() +for i=1,7 do + curses.init_pair(i, 0, i) +end - curses.endwin() +while true do + render(window) + update(window) end +curses.endwin() -main() diff --git a/hanoi.teliva b/hanoi.teliva index ba1d9cc..04b4491 100644 --- a/hanoi.teliva +++ b/hanoi.teliva @@ -1,9 +1,7 @@ local curses = require "curses" - tower = {{6, 5, 4, 3, 2}, {}, {}} - local function len(array) local result = 0 for k in pairs(array) do @@ -12,7 +10,6 @@ local function len(array) return result end - local function pop(array) return table.remove(array) end @@ -57,7 +54,6 @@ local function render_tower(window, line, col, tower_index, tower) end end - local function render(window) window:clear() local lines, cols = window:getmaxyx() @@ -75,7 +71,6 @@ local function make_move(from, to) table.insert(tower[to], disk) end - local function update(window) window:mvaddstr(lines(window)-2, 5, "tower to remove top disk from? ") local from = curses.getch() - 96 @@ -87,17 +82,13 @@ local function update(window) end -local function main() - local window = curses.stdscr() - for i=1,7 do - curses.init_pair(i, 0, i) - end - - while true do - render(window) - update(window) - end +local window = curses.stdscr() +for i=1,7 do + curses.init_pair(i, 0, i) end +while true do + render(window) + update(window) +end -main() |