Skip to content

Commit

Permalink
Merge pull request #1 from aran418/master
Browse files Browse the repository at this point in the history
Output Cleanup
  • Loading branch information
grosser committed Dec 12, 2012
2 parents 9ea0bc8 + cae1389 commit 0eb7889
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions bin/tic_tac_toe
Expand Up @@ -2,12 +2,9 @@
require 'curses'
require File.expand_path('../../lib/tic_tac_toe', __FILE__)

STATUS_LINE = 10

def write(line, column, text)
Curses.setpos(line, column)
Curses.addstr(text);
end
STATUS_LINE = 10
STATUS_LINE_LENGTH = 23

def init_screen
Curses.noecho # do not show typed keys
Expand All @@ -20,21 +17,33 @@ def init_screen
end
end

def write(line, column, text)
Curses.setpos(line, column)
Curses.addstr(text);
end


def display(ttt)
write 0,0,ttt.board
if winner = ttt.winner
write(STATUS_LINE, 0, "Player #{winner} has won!!!!")
status("Player #{winner} has won!!!!")
elsif ttt.draw?
write(STATUS_LINE, 0, "It is a draw...")
status("It is a draw...")
else
write(STATUS_LINE, 0, "It is #{ttt.player}`s turn...")
status("It is #{ttt.player}`s turn...")
end
end

init_screen do
write(STATUS_LINE+1, 0, "q=Quit r=Reset a=AI-move")
def status(message)
# pad the status with spaces to replace old characters
message += " " * (STATUS_LINE_LENGTH - message.length)
write(STATUS_LINE, 0, message)
end

init_screen do
ttt = TicTacToe.new

write(STATUS_LINE+1, 0, "q=Quit r=Reset a=AI-move")

loop do
display ttt
Expand Down

0 comments on commit 0eb7889

Please sign in to comment.