| Class | Hex |
| In: |
lib/core/board.rb
|
| Parent: | Object |
Node numbers
5---------0 / # / # 4/ \1 \ / \ / \ / 3---------2
| card_type | [RW] | |
| coords | [RW] | |
| edges | [RW] | |
| has_bandit | [RW] | |
| nodes | [RW] | |
| number | [RW] |
# File lib/core/board.rb, line 68 def initialize(card, number, has_bandit=false) @card_type = card @number = number @has_bandit = has_bandit @nodes = [] @edges = [] end
# File lib/core/board.rb, line 80 def connect_hex(edgeIndex, hex2) edgeIndex2 = (edgeIndex-1)%6 if hex2 i2 = (edgeIndex + 3) % 6 @edges[edgeIndex].nodes = [] if @edges[edgeIndex] hex2.edges[i2].nodes = [] if hex2.edges[i2] edge = @edges[edgeIndex] edge = hex2.edges[i2] if hex2.edges[i2] edge = Edge.new if not edge hex2.edges[i2] = edge tempNodes = connect_to_nodes(edge, edgeIndex, i2, hex2) else edge = Edge.new tempNodes = connect_to_nodes(edge, edgeIndex, i2, nil) edge.nodes = tempNodes end @edges[edgeIndex] = edge edge.coords = @coords + [edgeIndex] tempNodes.each_with_index{|n,i| tempEdgeIndex = i==0 ? edgeIndex : edgeIndex2 n.coords = @coords + [tempEdgeIndex] n.edges.uniq! @nodes[tempEdgeIndex] = n n.hexes << self n.hexes.uniq! } end
helper for connectHex
# File lib/core/board.rb, line 111 def connect_to_nodes(edge, edgeIndex, i2, hex2 = nil) n1 = @nodes[edgeIndex] n2 = @nodes[(edgeIndex-1)%6] n1 = hex2.nodes[(i2-1)%6] if not n1 and hex2 n2 = hex2.nodes[i2] if not n2 and hex2 n1 = Node.new if not n1 n2 = Node.new if not n2 n1.edges << edge n2.edges << edge if hex2 hex2.nodes[i2] = n2 hex2.nodes[(i2-1)%6] = n1 edge.nodes = [n1, n2] end [n1,n2] end
gets the cartesian coordinatess of the rightmost point of this hex
# File lib/core/board.rb, line 134 def get_cartesian x,y = @coords [x, y+((x%2)/2.0)] end