This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'hateoas' | |
| class Maze | |
| include Hateoas::MediaType | |
| media_type "application/vnd.amundsen.maze+xml" | |
| serialization :xml | |
| element :maze, | |
| :cell, | |
| :code, | |
| :error, | |
| :collection, | |
| :item, | |
| :link, | |
| :message, | |
| :title, | |
| :debug | |
| attribute :href, | |
| :rel, | |
| :side, | |
| :total, | |
| :version | |
| relation :collection, | |
| :current, | |
| :east, | |
| :exit, | |
| :maze, | |
| :north, | |
| :south, | |
| :start, | |
| :west | |
| action :north, | |
| :south, | |
| :east, | |
| :west, | |
| :exit | |
| end | |
| maze = Maze.new("http://amundsen.com/examples/mazes/2d/five-by-five/") | |
| puts "Let's navigate a maze!" | |
| maze.transition("start") | |
| action = "" | |
| until action == "exit" | |
| # puts maze.data #for debugging | |
| puts "You can do these things:" | |
| puts maze.actions.join(", ") | |
| puts "What would you like to do?" | |
| action = gets.chomp | |
| maze.transition(action) | |
| end | |
| puts "Done!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment