Permalink
Browse files

cleanup

  • Loading branch information...
1 parent 9097c56 commit ae78dc64776b55f3dc11dbe54fc17b254331872e @grosser committed Jan 3, 2011
Showing with 10 additions and 21 deletions.
  1. +9 −9 bin/tic_tac_toe
  2. +0 −11 lib/tic_tac_toe.rb
  3. +1 −1 spec/tic_tac_toe_spec.rb
View
18 bin/tic_tac_toe
@@ -2,17 +2,17 @@
require 'curses'
require File.expand_path('../../lib/tic_tac_toe', __FILE__)
-STATUS = 10
+STATUS_LINE = 10
-def write(x,y,text)
- Curses.setpos(y,x)
+def write(line, column, text)
+ Curses.setpos(line, column)
Curses.addstr(text);
end
def init_screen
- Curses.noecho
+ Curses.noecho # do not show typed keys
Curses.init_screen
- Curses.stdscr.keypad(true)
+ Curses.stdscr.keypad(true) # enable arrow keys
begin
yield
ensure
@@ -23,16 +23,16 @@ end
def display(ttt)
write 0,0,ttt.board
if winner = ttt.winner
- write(0, STATUS, "Player #{winner} has won!!!!")
+ write(STATUS_LINE, 0, "Player #{winner} has won!!!!")
elsif ttt.draw?
- write(0, STATUS, "It is a draw...")
+ write(STATUS_LINE, 0, "It is a draw...")
else
- write(0, STATUS, "It is #{ttt.player}`s turn...")
+ write(STATUS_LINE, 0, "It is #{ttt.player}`s turn...")
end
end
init_screen do
- write(0, STATUS+1, "q=Quit r=Reset a=AI-move")
+ write(STATUS_LINE+1, 0, "q=Quit r=Reset a=AI-move")
ttt = TicTacToe.new
View
11 lib/tic_tac_toe.rb
@@ -1,14 +1,3 @@
-class String
- def indexes(needle)
- found = []
- current_index = -1
- while current_index = index(needle, current_index+1)
- found << current_index
- end
- found
- end
-end
-
class TicTacToe
VERSION = File.read( File.join(File.dirname(__FILE__),'..','VERSION') ).strip
View
2 spec/tic_tac_toe_spec.rb
@@ -29,7 +29,7 @@ def board_full_without_winner
end
it "should position the cursor in the first position" do
- ttt.board.indexes('[ ]').should == [board_width+1]
+ ttt.board.index('[ ]').should == board_width+1
end
end

0 comments on commit ae78dc6

Please sign in to comment.