Table of Contents

Scope

This gem is the Ruby implementation of the Goose Game code-kata (for more information refer to the OBJECTIVES).

Design

The code design follows the single responsibility principle by using a dedicated class/module for any specific task. Each class exposes a minimal public API, when meaningful by using the call method, thus behaving like a plain Proc object.

Cell

The cell of the game board. They are responsible to compute the position of the player and properly display the output messages. Polymorphism is used to reduce conditional logic.

Dice

The class represents the two dice used to move players (creating a single Die class brings little benefit to the design). A factory class rolls dice with random values (within 1 to 6), constructor accepts any convertible integers, the absolute value is taken and limited to 6.

Gameboard

The board class uses a Hash for its data representation: this data structure grants quick access by key.

Gameplay

The main interface with the game core logic is enclosed within the Gameplay class: it recognizes input commands, performs actions by creating players, rolling dice and printing appropriate messages to the terminal. The whole game runs within an endless loop.

Player

The player of the game, record both current and previous position.

Installation

Runtime

This library supports from Ruby 2.4.1 on.

Dependencies

There are no runtime dependencies, but some developments ones (testing).
Just clone the repository, move to the directory and use bundler:

bundle install

Testing

The code is covered by fast, isolated unit testing.
Move to the installation path and run them by:

bundle exec rake

Gem

The library is packaged as a gem. Build and install it by:

gem build goose_game.gemspec
...
gem install --local ./goose_game.gem

Usage

CLI

The gem provides a CLI interface, once installed you will be able to start the game from the terminal:

goose_game

Help

The game starts with no prompts, type help to see the available commands:

available commands:
* add player <player_name>
* move <player_name> 4, 5
* move <player_name>
* help
* exit