Class: Mementus::Library::StoryGraph

Inherits:
Graph
  • Object
show all
Defined in:
lib/mementus/library/story_graph.rb

Overview

Demo of an interactive fiction story with passages represented as nodes and choices represented as edges.

Class Method Summary collapse

Methods inherited from Graph

#directed?, #each_edge, #each_node, #edge, #edges, #edges_count, #has_edge?, #has_node?, #incoming, #incoming_edges, #initialize, #n, #node, #nodes, #nodes_count, #outgoing, #outgoing_edges

Constructor Details

This class inherits a constructor from Mementus::Graph

Class Method Details

.instanceObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/mementus/library/story_graph.rb', line 6

def self.instance
  self.new do
    create_node do |node|
      node.id = "start"
      node.label = :passage
      node.props[:text] = "The start of a story."
    end

    create_node do |node|
      node.id = "happy-ending"
      node.label = :passage
      node.props[:text] = "A happy ending."
    end

    create_node do |node|
      node.id = "tragic-ending"
      node.label = :passage
      node.props[:text] = "A tragic ending."
    end

    create_edge do |edge|
      edge.id = "happy-choice"
      edge.label = :choice
      edge.from = "start"
      edge.to = "happy-ending"
      edge.props[:text] = "Choose wisely."
      edge.props[:happiness] = 1
    end

    create_edge do |edge|
      edge.id = "tragic-choice"
      edge.label = :choice
      edge.from = "start"
      edge.to = "tragic-ending"
      edge.props[:text] = "Choose poorly."
      edge.props[:happiness] = -1
    end
  end
end