Skip to content
Browse files

nice status messages

  • Loading branch information...
1 parent e3f6d93 commit 354e9c2dd073c6147e0c574a0f3ca684353fbabb @grosser committed Dec 31, 2010
Showing with 7 additions and 1 deletion.
  1. +7 −1 bin/tic_tac_toe
View
8 bin/tic_tac_toe
@@ -2,6 +2,8 @@
require 'curses'
require File.expand_path('../../lib/tic_tac_toe', __FILE__)
+STATUS = 10
+
def write(x,y,text)
Curses.setpos(y,x)
Curses.addstr(text);
@@ -21,7 +23,9 @@ end
def display(ttt)
write 0,0,ttt.board
if winner = ttt.winner
- write(0, 15, "Player #{winner} has won!!!!")
+ write(0, STATUS, "Player #{winner} has won!!!!")
+ else
+ write(0, STATUS, "It is #{ttt.player}`s turn...")
end
end
@@ -30,6 +34,7 @@ init_screen do
loop do
display ttt
+ write(0, STATUS+1, "q=Quit r=Reset")
char = Curses.getch
case char
@@ -39,6 +44,7 @@ init_screen do
when Curses::Key::LEFT then ttt.move(-1,0)
when 10 then ttt.set # enter
when ?q then break
+ when ?r then ttt = TicTacToe.new
else
# write(0, 20, char.to_s) # debugging
end

0 comments on commit 354e9c2

Please sign in to comment.
Something went wrong with that request. Please try again.