gameboardRow function

Iterable<String> gameboardRow(
  1. Word word,
  2. String close(
    1. String
    ),
  3. String hit(
    1. String
    )
)

Generates a row of the gameboard with the given word. Generally use this with .join() to create a single string row:

final row = gameboardRow('WORDS').join();
assert(row == '│ W │ O │ R │ D │ S │');

The word can be any length. A empty string will create a single '│'.

Implementation

Iterable<String> gameboardRow(
  Word word,
  String Function(String) close,
  String Function(String) hit,
) sync* {
  yield '│';

  for (final letter in word.letters) {
    if (letter.status == LetterStatus.hit) {
      yield ' ${hit(letter.character)} │';
    } else if (letter.status == LetterStatus.close) {
      yield ' ${close(letter.character)} │';
    } else {
      yield ' ${letter.character} │';
    }
  }
}