boardgame 0.0.1

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 (39) hide show
  1. checksums.yaml +7 -0
  2. data/.DS_Store +0 -0
  3. data/Rakefile +8 -0
  4. data/coverage/.last_run.json +1 -0
  5. data/coverage/.resultset.json +1 -0
  6. data/coverage/assets/0.8.0/application.css +799 -0
  7. data/coverage/assets/0.8.0/application.js +1559 -0
  8. data/coverage/assets/0.8.0/colorbox/border.png +0 -0
  9. data/coverage/assets/0.8.0/colorbox/controls.png +0 -0
  10. data/coverage/assets/0.8.0/colorbox/loading.gif +0 -0
  11. data/coverage/assets/0.8.0/colorbox/loading_background.png +0 -0
  12. data/coverage/assets/0.8.0/favicon_green.png +0 -0
  13. data/coverage/assets/0.8.0/favicon_red.png +0 -0
  14. data/coverage/assets/0.8.0/favicon_yellow.png +0 -0
  15. data/coverage/assets/0.8.0/loading.gif +0 -0
  16. data/coverage/assets/0.8.0/magnify.png +0 -0
  17. data/coverage/assets/0.8.0/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  18. data/coverage/assets/0.8.0/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  19. data/coverage/assets/0.8.0/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  20. data/coverage/assets/0.8.0/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  21. data/coverage/assets/0.8.0/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  22. data/coverage/assets/0.8.0/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  23. data/coverage/assets/0.8.0/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  24. data/coverage/assets/0.8.0/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  25. data/coverage/assets/0.8.0/smoothness/images/ui-icons_222222_256x240.png +0 -0
  26. data/coverage/assets/0.8.0/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
  27. data/coverage/assets/0.8.0/smoothness/images/ui-icons_454545_256x240.png +0 -0
  28. data/coverage/assets/0.8.0/smoothness/images/ui-icons_888888_256x240.png +0 -0
  29. data/coverage/assets/0.8.0/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
  30. data/coverage/index.html +1470 -0
  31. data/lib/game.rb +3 -0
  32. data/lib/map.rb +74 -0
  33. data/lib/piece.rb +16 -0
  34. data/lib/tile.rb +32 -0
  35. data/readme.md +0 -0
  36. data/test/test_helper.rb +5 -0
  37. data/test/test_map.rb +64 -0
  38. data/test/test_tile.rb +16 -0
  39. metadata +83 -0
@@ -0,0 +1,3 @@
1
+ require_relative 'piece'
2
+ require_relative 'tile'
3
+ require_relative 'map'
@@ -0,0 +1,74 @@
1
+ #._________. A simple board / map of tiles
2
+ #| 0123 X | =============================
3
+ #| 0.... | Example 4X2 map,
4
+ #| 1..#. | with a piece
5
+ #| Y | placed in (2, 1)
6
+ #`---------'
7
+ class Map
8
+
9
+ attr_reader :tiles, :height, :width
10
+
11
+ def initialize(height, width)
12
+ @height, @width = height, width
13
+ validate_height
14
+ initialize_map_tiles
15
+ end
16
+
17
+ # Retrieves a tile for a given X/Y coord.
18
+ def [](x, y)
19
+ return @tiles[x][y] if within? x, y
20
+ end
21
+
22
+ # Sets a tile for a given X/Y coord.
23
+ def []=(x, y, tile)
24
+ validate_coords(x, y)
25
+ raise 'needs to be a tile' unless tile.is_a? Tile
26
+ @tiles[x][y] = tile.move_to(x, y, self)
27
+ end
28
+
29
+ # Determine if x and y values are within the limits of the map.
30
+ def within?(x, y)
31
+ (x >= 0) && (x < height) && (y >= 0) && (y < height)
32
+ end
33
+
34
+ def inspect
35
+ buffer = "\n"
36
+ 0.upto(max_y) do |ht|
37
+ 0.upto(max_x) do |wd|
38
+ buffer += self[wd, ht].inspect
39
+ end
40
+ buffer += "\n"
41
+ end
42
+ return buffer
43
+ end
44
+
45
+ private
46
+
47
+ def initialize_map_tiles
48
+ @tiles = {}
49
+ 0.upto(max_x) do |wd|
50
+ @tiles[wd] = {}
51
+ 0.upto(max_y) do |ht|
52
+ self[wd, ht] = Tile.new({})
53
+ end
54
+ end
55
+ end
56
+
57
+ def max_x
58
+ width - 1
59
+ end
60
+
61
+ def max_y
62
+ height - 1
63
+ end
64
+
65
+ def validate_coords(x, y)
66
+ raise "Coords out of range for #{height}x#{width} map." unless within? x, y
67
+ end
68
+
69
+ def validate_height
70
+ unless height.is_a?(Fixnum) && width.is_a?(Fixnum)
71
+ raise 'Expected height and width to be Fixnums'
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,16 @@
1
+ # A piece on the board.
2
+ class Piece
3
+ attr_accessor :tile
4
+
5
+ def move_to(new_tile)
6
+ raise 'that isnt a tile' unless new_tile.is_a? Tile
7
+ @tile.remove self if @tile
8
+ @tile = new_tile
9
+ @tile << self
10
+ self
11
+ end
12
+
13
+ def inspect
14
+ "+"
15
+ end
16
+ end
@@ -0,0 +1,32 @@
1
+ # A single tile on the map/board.
2
+ class Tile
3
+
4
+ attr_accessor :content, :x, :y, :map
5
+
6
+ def initialize(x: nil , y: nil, map: nil, content: [])
7
+ @content, @x, @y, @map = content, x, y, map
8
+ end
9
+
10
+ def move_to(x, y, map = @map)
11
+ if map.within? x, y
12
+ @x, @y, @map = x, y, map
13
+ else
14
+ raise 'invalid move'
15
+ end
16
+ self
17
+ end
18
+
19
+ def inspect
20
+ content.empty? ? "□" : content.last.inspect
21
+ end
22
+
23
+ def <<(piece)
24
+ piece.tile = self
25
+ @content << piece
26
+ end
27
+
28
+ def remove(piece)
29
+ piece.tile = nil
30
+ @content.delete piece
31
+ end
32
+ end
File without changes
@@ -0,0 +1,5 @@
1
+ require "simplecov"
2
+ SimpleCov.start
3
+ require 'minitest/autorun'
4
+ require_relative '../lib/game'
5
+ require 'pry'
@@ -0,0 +1,64 @@
1
+ require "test_helper"
2
+
3
+ class TestMap < Minitest::Test
4
+
5
+ def map
6
+ @map ||= Map.new(4, 4)
7
+ end
8
+
9
+ def test_new
10
+ assert map.tiles.is_a?(Hash),
11
+ "Expected new maps to have a tiles hash."
12
+ end
13
+
14
+ def test_within
15
+ assert map.within?(2, 2),
16
+ "Within did not identify coords within bounds"
17
+ assert map.within?(0, 0),
18
+ "Within did not identify coords within bounds"
19
+ refute map.within?(-1, 0),
20
+ "Within did not identify coords within bounds"
21
+ refute map.within?(4, 4),
22
+ "Within did not identify coords outside bounds"
23
+ refute map.within?(5, 5),
24
+ "Within did not identify coords outside bounds"
25
+ end
26
+
27
+ def test_set_tile
28
+ map[1, 2] = Tile.new()
29
+ assert map[1,2].is_a?(Tile),
30
+ "Could not set tile on map."
31
+ assert_raises RuntimeError do
32
+ map[1, 2] = "Not a tile"
33
+ end
34
+ assert_raises RuntimeError do
35
+ map[11, 4] = Tile.new
36
+ end
37
+ assert_raises RuntimeError do
38
+ map[4, 11] = Tile.new
39
+ end
40
+ end
41
+
42
+ def test_get_tile
43
+ assert map[0, 1].is_a?(Tile),
44
+ "Lookups of tiles should return Tile."
45
+ map[1, 2] = Tile.new
46
+ assert map[1,2].is_a?(Tile),
47
+ "Could not set tile on map."
48
+ assert_equal map[0,0].map, map,
49
+ "Tile did not know where that it was owned by map `map`."
50
+ end
51
+
52
+ def test_inspect
53
+ map[0, 0] = Tile.new
54
+ map[3, 3] = Tile.new
55
+ map[2, 1] << Piece.new
56
+ expectation = "\n"\
57
+ "□□□□\n"\
58
+ "□□+□\n"\
59
+ "□□□□\n"\
60
+ "□□□□\n"
61
+ assert_equal map.inspect, expectation,
62
+ "Maps dont look right in console."
63
+ end
64
+ end
@@ -0,0 +1,16 @@
1
+ require "test_helper"
2
+
3
+ class TestTile < Minitest::Test
4
+ def test_new
5
+ assert Tile.new.is_a?(Tile),
6
+ "Expected new tile to be."
7
+ end
8
+
9
+ def test_insertion
10
+ tile = Tile.new
11
+ piece = Piece.new
12
+ tile << piece
13
+ assert tile.content.first == piece,
14
+ "Did not put piece on tile."
15
+ end
16
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: boardgame
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Rick Carlino
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-09 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A simple Ruby object library for board and tile based games.
14
+ email: rick.carlino@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - .DS_Store
20
+ - Rakefile
21
+ - coverage/.last_run.json
22
+ - coverage/.resultset.json
23
+ - coverage/assets/0.8.0/application.css
24
+ - coverage/assets/0.8.0/application.js
25
+ - coverage/assets/0.8.0/colorbox/border.png
26
+ - coverage/assets/0.8.0/colorbox/controls.png
27
+ - coverage/assets/0.8.0/colorbox/loading.gif
28
+ - coverage/assets/0.8.0/colorbox/loading_background.png
29
+ - coverage/assets/0.8.0/favicon_green.png
30
+ - coverage/assets/0.8.0/favicon_red.png
31
+ - coverage/assets/0.8.0/favicon_yellow.png
32
+ - coverage/assets/0.8.0/loading.gif
33
+ - coverage/assets/0.8.0/magnify.png
34
+ - coverage/assets/0.8.0/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png
35
+ - coverage/assets/0.8.0/smoothness/images/ui-bg_flat_75_ffffff_40x100.png
36
+ - coverage/assets/0.8.0/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png
37
+ - coverage/assets/0.8.0/smoothness/images/ui-bg_glass_65_ffffff_1x400.png
38
+ - coverage/assets/0.8.0/smoothness/images/ui-bg_glass_75_dadada_1x400.png
39
+ - coverage/assets/0.8.0/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png
40
+ - coverage/assets/0.8.0/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png
41
+ - coverage/assets/0.8.0/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png
42
+ - coverage/assets/0.8.0/smoothness/images/ui-icons_222222_256x240.png
43
+ - coverage/assets/0.8.0/smoothness/images/ui-icons_2e83ff_256x240.png
44
+ - coverage/assets/0.8.0/smoothness/images/ui-icons_454545_256x240.png
45
+ - coverage/assets/0.8.0/smoothness/images/ui-icons_888888_256x240.png
46
+ - coverage/assets/0.8.0/smoothness/images/ui-icons_cd0a0a_256x240.png
47
+ - coverage/index.html
48
+ - lib/game.rb
49
+ - lib/map.rb
50
+ - lib/piece.rb
51
+ - lib/tile.rb
52
+ - readme.md
53
+ - test/test_helper.rb
54
+ - test/test_map.rb
55
+ - test/test_tile.rb
56
+ homepage: http://github.com/rickcarlino/shiny-octo-nemesis
57
+ licenses:
58
+ - MIT
59
+ metadata: {}
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project:
76
+ rubygems_version: 2.2.2
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: Generate a Rails app using debatable best practices.
80
+ test_files:
81
+ - test/test_helper.rb
82
+ - test/test_map.rb
83
+ - test/test_tile.rb