Project

RubyGrid

0.0
No commit activity in last 3 years
No release in over 3 years
A simple gem for grids in Ruby
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

 Project Readme

RubyGrid

Gem VersionBuild StatusCoverage StatusCode Climate

Description

Grid Class for Games or whatever else you can think of. By Randy Carnahan, released to the Public Domain. Lua Version: http://github.com/syntruth/Lua-Grid

Installation

gem install RubyGrid

Caveats

  • The Grid object is data agnostic. It doesn't care what kind of data you store in a cell. This is meant to be, for abstraction's sake. You could even store functions.
  • The class defines -no- display methods. Either sub-class the Grid class to add your own, or define functions that call the #get_* methods.
  • Grid coordinates are always x,y number pairs. X is the vertical, starting at the top left, and Y is the horizontal, also starting at the top left. Hence, the top-left cell is always 0,0. One cell to the right is 0,1. One cell down is 1,0.
  • Some Grid constants (OUTSIDE, NOT_VALID, NIL_VALUE) are not numbers, but strings, just in case number data is to be stored in a cell.

Example Usage

require 'grid'
g = RubyGrid.create(8, 8, ' ')
c = [[4, 4, 'O'], [4, 5, 'X'], [5, 4, 'X'], [5, 5, 'O']]
g.populate(c)
g.traverse(0, 0, RubyGrid::BOTTOM_RIGHT) do |x, y, value|
  puts "#{x}, #{y}: #{value}"
end
g.resize(4, 4)
g.get_cell(3, 3)