tic_tac_toe 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/bin/tic_tac_toe CHANGED
@@ -2,12 +2,9 @@
2
2
  require 'curses'
3
3
  require File.expand_path('../../lib/tic_tac_toe', __FILE__)
4
4
 
5
- STATUS_LINE = 10
6
5
 
7
- def write(line, column, text)
8
- Curses.setpos(line, column)
9
- Curses.addstr(text);
10
- end
6
+ STATUS_LINE = 10
7
+ STATUS_LINE_LENGTH = 23
11
8
 
12
9
  def init_screen
13
10
  Curses.noecho # do not show typed keys
@@ -20,21 +17,33 @@ def init_screen
20
17
  end
21
18
  end
22
19
 
20
+ def write(line, column, text)
21
+ Curses.setpos(line, column)
22
+ Curses.addstr(text);
23
+ end
24
+
25
+
23
26
  def display(ttt)
24
27
  write 0,0,ttt.board
25
28
  if winner = ttt.winner
26
- write(STATUS_LINE, 0, "Player #{winner} has won!!!!")
29
+ status("Player #{winner} has won!!!!")
27
30
  elsif ttt.draw?
28
- write(STATUS_LINE, 0, "It is a draw...")
31
+ status("It is a draw...")
29
32
  else
30
- write(STATUS_LINE, 0, "It is #{ttt.player}`s turn...")
33
+ status("It is #{ttt.player}`s turn...")
31
34
  end
32
35
  end
33
36
 
34
- init_screen do
35
- write(STATUS_LINE+1, 0, "q=Quit r=Reset a=AI-move")
37
+ def status(message)
38
+ # pad the status with spaces to replace old characters
39
+ message += " " * (STATUS_LINE_LENGTH - message.length)
40
+ write(STATUS_LINE, 0, message)
41
+ end
36
42
 
43
+ init_screen do
37
44
  ttt = TicTacToe.new
45
+
46
+ write(STATUS_LINE+1, 0, "q=Quit r=Reset a=AI-move")
38
47
 
39
48
  loop do
40
49
  display ttt
@@ -1,3 +1,3 @@
1
1
  class TicTacToe
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tic_tac_toe
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 1
10
- version: 0.2.1
9
+ - 2
10
+ version: 0.2.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Michael Grosser
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-12-10 00:00:00 Z
18
+ date: 2012-12-12 00:00:00 Z
19
19
  dependencies: []
20
20
 
21
21
  description: