bloodymines 0.1.8 → 0.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/bin/bloodymines +12 -22
  2. data/lib/bloodymines/tui.rb +15 -0
  3. metadata +3 -3
data/bin/bloodymines CHANGED
@@ -9,39 +9,29 @@ class Bloodymines
9
9
  include TUI
10
10
  end
11
11
 
12
- # main app
12
+ # parse command line options
13
13
  options = {}
14
14
  optparse = OptionParser.new do |opts|
15
15
  opts.on('-h','--help', 'display this screen') { puts opts; exit }
16
16
  opts.on('-d', '--difficulty DIFFICULTY', [:beginner, :intermediate, :expert],
17
- "Set the difficulty of the game") do |d|
18
- options[:difficulty] = d
17
+ "beginner, intermediate or expert") do |d|
18
+ options[:difficulty] = d
19
19
  end
20
20
  end
21
21
 
22
22
  begin
23
23
  optparse.parse!
24
24
  rescue OptionParser::MissingArgument, OptionParser::InvalidArgument
25
- puts "The following difficulty levels are available: beginner, intermediate, expert"
26
25
  puts optparse
27
26
  exit
28
27
  end
29
28
 
29
+ # start game as curses app
30
30
  game = Bloodymines.new(:difficulty => options[:difficulty])
31
- game.cursor_x = 0
32
- game.cursor_y = 0
33
31
 
34
32
  Curses.program do |scr|
35
33
  while true
36
- game.draw_field
37
- case getch
38
- when Key::UP : game.move(:direction => :up)
39
- when Key::DOWN : game.move(:direction => :down)
40
- when Key::LEFT : game.move(:direction => :left)
41
- when Key::RIGHT : game.move(:direction => :right)
42
- when 32 : game.uncover(game.cursor_x, game.cursor_y)
43
- when 27, ?q, ?Q : break
44
- end
34
+ game.turn
45
35
  if game.ended?
46
36
  game.draw_field
47
37
  setpos(0, 1)
@@ -51,11 +41,11 @@ Curses.program do |scr|
51
41
  end
52
42
  end
53
43
 
54
- close_screen
55
- if game.result[:finished]
56
- puts "You completed the game on #{game.difficulty.to_s.upcase}!"
57
- else
58
- puts "You did not manage to finish the game."
59
- end
60
- puts "Your final score was: #{game.result[:score]}"
44
+ close_screen
45
+ if game.result[:finished]
46
+ puts "You completed the game on #{game.difficulty.to_s.upcase}!"
47
+ else
48
+ puts "You did not manage to finish the game."
49
+ end
50
+ puts "Your final score was: #{game.result[:score]}"
61
51
  end
@@ -18,6 +18,8 @@ module TUI
18
18
  attr_accessor :cursor_x, :cursor_y
19
19
 
20
20
  def draw_field
21
+ @cursor_x = @cursor_x || 0
22
+ @cursor_y = @cursor_y || 0
21
23
  clear
22
24
  0.upto(@width - 1) do |x|
23
25
  0.upto(@height - 1) do |y|
@@ -64,4 +66,17 @@ module TUI
64
66
  @cursor_x += 1 if @cursor_x < @width - 1
65
67
  end
66
68
  end
69
+
70
+ def turn
71
+ draw_field
72
+ case getch
73
+ when Key::UP : move(:direction => :up)
74
+ when Key::DOWN : move(:direction => :down)
75
+ when Key::LEFT : move(:direction => :left)
76
+ when Key::RIGHT : move(:direction => :right)
77
+ when 32 : uncover(@cursor_x, @cursor_y)
78
+ when 27, ?q, ?Q : break
79
+ end
80
+
81
+ end
67
82
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bloodymines
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
4
+ hash: 9
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 8
10
- version: 0.1.8
9
+ - 9
10
+ version: 0.1.9
11
11
  platform: ruby
12
12
  authors:
13
13
  - !binary |