Skip to content

yacn/RubyGrid

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)

About

Simple gem for grids in Ruby

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 84.7%
  • CSS 14.6%
  • Shell 0.7%