tic_tac_toe 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 669bcc6a62e3529623b90a6d63ea18b5a30bc2c8
4
+ data.tar.gz: 97390978eca78ae37f26674b559c91f153d875bd
5
+ SHA512:
6
+ metadata.gz: ad42b25232cf62cd0c62238c30cbb5921163c97a0416fd170d47c546abab4e957c66bdb712b1c4466eebb765ec996aabf6fe8a3229e72f8e25c7576f0c634d74
7
+ data.tar.gz: 0944cf1cac8d17226c9467a4dc7669be36ea86e851121447b0ba8e3859cff4aa08b2ec983f0dde7f3be3af72432f97d4e52d367dc8019ceb979e46a4517dd312
data/Gemfile CHANGED
@@ -1,4 +1,5 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
+ gemspec
2
3
 
3
4
  gem 'bump'
4
5
  gem 'rake'
@@ -1,17 +1,24 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ tic_tac_toe (0.2.3)
5
+ dispel
6
+
1
7
  GEM
2
- remote: http://rubygems.org/
8
+ remote: https://rubygems.org/
3
9
  specs:
4
- bump (0.3.6)
5
- diff-lcs (1.1.2)
6
- rake (0.8.7)
7
- rspec (2.3.0)
8
- rspec-core (~> 2.3.0)
9
- rspec-expectations (~> 2.3.0)
10
- rspec-mocks (~> 2.3.0)
11
- rspec-core (2.3.1)
12
- rspec-expectations (2.3.0)
13
- diff-lcs (~> 1.1.2)
14
- rspec-mocks (2.3.0)
10
+ bump (0.5.0)
11
+ diff-lcs (1.2.5)
12
+ dispel (0.0.1)
13
+ rake (10.1.0)
14
+ rspec (2.14.1)
15
+ rspec-core (~> 2.14.0)
16
+ rspec-expectations (~> 2.14.0)
17
+ rspec-mocks (~> 2.14.0)
18
+ rspec-core (2.14.7)
19
+ rspec-expectations (2.14.4)
20
+ diff-lcs (>= 1.1.3, < 2.0)
21
+ rspec-mocks (2.14.4)
15
22
 
16
23
  PLATFORMS
17
24
  ruby
@@ -20,3 +27,4 @@ DEPENDENCIES
20
27
  bump
21
28
  rake
22
29
  rspec (~> 2)
30
+ tic_tac_toe!
@@ -1,62 +1,38 @@
1
1
  #!/usr/bin/env ruby
2
- require 'curses'
3
- require File.expand_path('../../lib/tic_tac_toe', __FILE__)
2
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
4
3
 
4
+ require 'dispel'
5
+ require 'tic_tac_toe'
5
6
 
6
- STATUS_LINE = 10
7
- STATUS_LINE_LENGTH = 23
8
-
9
- def init_screen
10
- Curses.noecho # do not show typed keys
11
- Curses.init_screen
12
- Curses.stdscr.keypad(true) # enable arrow keys
13
- begin
14
- yield
15
- ensure
16
- Curses.close_screen
17
- end
7
+ def draw(ttt)
8
+ [ttt.board, status_line(ttt), "q=Quit r=Reset a=AI-move"].join("\n")
18
9
  end
19
10
 
20
- def write(line, column, text)
21
- Curses.setpos(line, column)
22
- Curses.addstr(text);
23
- end
24
-
25
-
26
- def display(ttt)
27
- write 0,0,ttt.board
11
+ def status_line(ttt)
28
12
  if winner = ttt.winner
29
- status("Player #{winner} has won!!!!")
13
+ "Player #{winner} has won!!!!"
30
14
  elsif ttt.draw?
31
- status("It is a draw...")
15
+ "It is a draw..."
32
16
  else
33
- status("It is #{ttt.player}`s turn...")
17
+ "It is #{ttt.player}`s turn..."
34
18
  end
35
19
  end
36
20
 
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
42
-
43
- init_screen do
21
+ Dispel::Screen.open do |screen|
44
22
  ttt = TicTacToe.new
45
-
46
- write(STATUS_LINE+1, 0, "q=Quit r=Reset a=AI-move")
47
-
48
- loop do
49
- display ttt
50
-
51
- case Curses.getch
52
- when Curses::Key::UP then ttt.move(0,-1)
53
- when Curses::Key::DOWN then ttt.move(0,1)
54
- when Curses::Key::RIGHT then ttt.move(1,0)
55
- when Curses::Key::LEFT then ttt.move(-1,0)
56
- when ?a then ttt.ai_move
57
- when 10 then ttt.set # enter
58
- when ?q then break
59
- when ?r then ttt = TicTacToe.new
23
+ screen.draw draw(ttt)
24
+
25
+ Dispel::Keyboard.output do |key|
26
+ case key
27
+ when :up then ttt.move(0,-1)
28
+ when :down then ttt.move(0,1)
29
+ when :right then ttt.move(1,0)
30
+ when :left then ttt.move(-1,0)
31
+ when "a" then ttt.ai_move
32
+ when :enter then ttt.set # enter
33
+ when "q" then break
34
+ when "r" then ttt = TicTacToe.new
60
35
  end
36
+ screen.draw draw(ttt)
61
37
  end
62
- end
38
+ end
@@ -1,3 +1,3 @@
1
1
  class TicTacToe
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
@@ -11,5 +11,6 @@ Gem::Specification.new name, TicTacToe::VERSION do |s|
11
11
  s.executables = [name]
12
12
  s.files = `git ls-files`.split("\n")
13
13
  s.license = "MIT"
14
+ s.add_runtime_dependency "dispel"
14
15
  end
15
16
 
metadata CHANGED
@@ -1,32 +1,36 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: tic_tac_toe
3
- version: !ruby/object:Gem::Version
4
- hash: 19
5
- prerelease:
6
- segments:
7
- - 0
8
- - 2
9
- - 2
10
- version: 0.2.2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.3
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Michael Grosser
14
8
  autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2012-12-12 00:00:00 Z
19
- dependencies: []
20
-
11
+ date: 2013-12-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: dispel
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
21
27
  description:
22
28
  email: michael@grosser.it
23
- executables:
29
+ executables:
24
30
  - tic_tac_toe
25
31
  extensions: []
26
-
27
32
  extra_rdoc_files: []
28
-
29
- files:
33
+ files:
30
34
  - Gemfile
31
35
  - Gemfile.lock
32
36
  - Rakefile
@@ -38,37 +42,27 @@ files:
38
42
  - spec/tic_tac_toe_spec.rb
39
43
  - tic_tac_toe.gemspec
40
44
  homepage: http://github.com/grosser/tic_tac_toe
41
- licenses:
45
+ licenses:
42
46
  - MIT
47
+ metadata: {}
43
48
  post_install_message:
44
49
  rdoc_options: []
45
-
46
- require_paths:
50
+ require_paths:
47
51
  - lib
48
- required_ruby_version: !ruby/object:Gem::Requirement
49
- none: false
50
- requirements:
51
- - - ">="
52
- - !ruby/object:Gem::Version
53
- hash: 3
54
- segments:
55
- - 0
56
- version: "0"
57
- required_rubygems_version: !ruby/object:Gem::Requirement
58
- none: false
59
- requirements:
60
- - - ">="
61
- - !ruby/object:Gem::Version
62
- hash: 3
63
- segments:
64
- - 0
65
- version: "0"
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
66
62
  requirements: []
67
-
68
63
  rubyforge_project:
69
- rubygems_version: 1.8.24
64
+ rubygems_version: 2.0.14
70
65
  signing_key:
71
- specification_version: 3
66
+ specification_version: 4
72
67
  summary: Play Tic-Tac-Toe using Curses
73
68
  test_files: []
74
-