gameboard function

Iterable<String> gameboard(
  1. Iterable<Word> words
)

Generates the game board with a given list of words. Generally use this with .join('\n') to create a human-readable board:

final board = gameboard(['WORDS']).join('\n');
final matcher = '''
  ┌───┬───┬───┬───┬───┐
  │ W │ O │ R │ D │ S │
  └───┴───┴───┴───┴───┘''';
assert(board == matcher);

The word count can be any length, but the length all words must be 5. If an empty list is given it will create an empty board like this:

┌───┬───┬───┬───┬───┐
└───┴───┴───┴───┴───┘

Implementation

Iterable<String> gameboard(Iterable<Word> words) sync* {
  yield '┌───┬───┬───┬───┬───┐';

  for (final word in words) {
    if (word.letters.length != 5) {
      throw Exception('The word must be 5 chars long.');
    }

    yield gameboardRow(word, close, hit).join();
  }

  yield '└───┴───┴───┴───┴───┘';
}