bloodymines 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/bin/bloodymines +1 -1
  2. data/lib/bloodymines.rb +43 -0
  3. metadata +5 -4
data/bin/bloodymines CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
- # bloodymines -- the executable terminal script for the bloody_mines gem
2
+ # bloodymines -- the executable terminal script for the bloodymines gem
3
3
  require File.dirname(__FILE__) + "/../lib/minefield"
4
4
  require "curses"
5
5
  include Curses
@@ -0,0 +1,43 @@
1
+ require "minefield"
2
+
3
+ class Bloodymines
4
+ attr_reader :minefield, :x_max, :y_max
5
+ def initialize(params={})
6
+ params = { :difficulty => :beginner }.merge params
7
+ @minefield = MineField.new(:difficulty => params[:difficulty])
8
+ @width = @minefield.fields.size
9
+ @height = @minefield.fields[0].size
10
+ end
11
+
12
+ def uncover(x, y)
13
+ @minefield.uncover_field(x, y)
14
+ end
15
+
16
+ def difficulty
17
+ @minefield.difficulty
18
+ end
19
+
20
+ def score
21
+ score = 0
22
+ @minefield.fields.each do |rows|
23
+ rows.each do |cell|
24
+ score += cell if cell.kind_of?(Integer)
25
+ end
26
+ end
27
+ score
28
+ end
29
+
30
+ # returns true if you triggered a mine or uncovered all save fields
31
+ def ended?
32
+ uncovered = 0
33
+ @minefield.fields.each do |rows|
34
+ rows.each do |cell|
35
+ uncovered += 1 if cell == false
36
+ return true if cell == :boom
37
+ end
38
+ end
39
+ return false if uncovered > 0
40
+ true
41
+ end
42
+
43
+ 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: 25
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 2
10
+ version: 0.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - !binary |
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2010-08-17 00:00:00 +02:00
20
+ date: 2010-08-18 00:00:00 +02:00
21
21
  default_executable:
22
22
  dependencies: []
23
23
 
@@ -30,6 +30,7 @@ extensions: []
30
30
  extra_rdoc_files: []
31
31
 
32
32
  files:
33
+ - lib/bloodymines.rb
33
34
  - lib/minefield.rb
34
35
  - test/test_minefield.rb
35
36
  - bin/bloodymines