multifarious 0.1.1 → 0.2.0

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.
data/Rakefile CHANGED
@@ -11,7 +11,7 @@ begin
11
11
  gem.homepage = "http://github.com/kristjan/multifarious"
12
12
  gem.authors = ["Kristján Pétursson"]
13
13
  gem.add_development_dependency "rspec"
14
- gem.version = "0.1.1"
14
+ gem.version = "0.2.0"
15
15
  end
16
16
  Jeweler::GemcutterTasks.new
17
17
  rescue LoadError
@@ -81,6 +81,7 @@ class Mosaic
81
81
  raise DuplicateTile if has_tile?(tile)
82
82
  return false unless can_place?(tile, row, col)
83
83
  @tiles << tile
84
+ tile.place!(self, row, col)
84
85
  (row...(row + tile.rows)).each do |r|
85
86
  (col...(col + tile.cols)).each do |c|
86
87
  @grid[r][c] = tile
@@ -1,4 +1,6 @@
1
1
  class Tile
2
+ attr_reader :mosaic
3
+ attr_reader :row, :col
2
4
  attr_reader :rows, :cols
3
5
 
4
6
  class Large < Tile
@@ -55,6 +57,10 @@ class Tile
55
57
  @rows * @cols
56
58
  end
57
59
 
60
+ def place!(mosaic, row, col)
61
+ @mosaic, @row, @col = mosaic, row, col
62
+ end
63
+
58
64
  def shatter
59
65
  Tile.rand_covering(area)
60
66
  end
@@ -109,6 +109,11 @@ describe Mosaic do
109
109
  @mosaic.place!(@tile, 0, 0)
110
110
  }.to raise_error(Mosaic::DuplicateTile)
111
111
  end
112
+
113
+ it "notifies the tile of its placement" do
114
+ @tile.should_receive(:place!).with(@mosaic, 1, 0)
115
+ @mosaic.place!(@tile, 1, 0)
116
+ end
112
117
  end
113
118
 
114
119
  it "knows when it contains a tile" do
@@ -2,12 +2,25 @@ require "spec_helper"
2
2
 
3
3
  describe Tile do
4
4
  describe "initializing" do
5
+ before :each do
6
+ @tile = Tile.new(1,2)
7
+ end
8
+
5
9
  it "stores the rows" do
6
- Tile.new(1,2).rows.should == 1
10
+ @tile.rows.should == 1
7
11
  end
8
12
 
9
13
  it "stores the columns" do
10
- Tile.new(1,2).cols.should == 2
14
+ @tile.cols.should == 2
15
+ end
16
+
17
+ it "has no mosaic" do
18
+ @tile.mosaic.should be_nil
19
+ end
20
+
21
+ it "has no location" do
22
+ @tile.row.should be_nil
23
+ @tile.col.should be_nil
11
24
  end
12
25
  end
13
26
 
@@ -34,6 +47,26 @@ describe Tile do
34
47
  end
35
48
  end
36
49
 
50
+ describe "placing a tile in a mosaic" do
51
+ before :each do
52
+ @mosaic = Mosaic.new(4,4)
53
+ @tile = Tile::Medium.new
54
+ @tile.place!(@mosaic, 1, 2)
55
+ end
56
+
57
+ it "links the tile to the mosaic" do
58
+ @tile.mosaic.should == @mosaic
59
+ end
60
+
61
+ it "remembers the row the tile was placed in" do
62
+ @tile.row.should == 1
63
+ end
64
+
65
+ it "remembers the column the tile was placed in" do
66
+ @tile.col.should == 2
67
+ end
68
+ end
69
+
37
70
  it "knows its area" do
38
71
  Tile.new(1,1).area.should == 1
39
72
  Tile.new(2,2).area.should == 4
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: multifarious
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 1
10
- version: 0.1.1
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Kristj\xC3\xA1n P\xC3\xA9tursson"