day1 

Yesterday, we approximated the game state using String. Let’s see how we can improve this.

modeling the game 

On screen there should be a 10x20 grid. I only want the current piece to be rendered in different color. We’ll deal with the next piece window later. The different kinds of pieces can be represented using case objects:

sealed trait PieceKind
case object IKind extends PieceKind
case object JKind extends PieceKind
case object LKind extends PieceKind
case object OKind extends PieceKind
case object SKind extends PieceKind
case object TKind extends PieceKind
case object ZKind extends PieceKind

Individual blocks can be represented using a case class:

case class Block(pos: (Int, Int), kind: PieceKind)

Both the current piece and the grid can be presented using Seq[Block].

case class GameView(blocks: Seq[Block], gridSize: (Int, Int), current: Seq[Block])

Now we can change the AbstractUI to return an instance of GameView.

  def view: GameView =
    GameView(
      Seq(Block((5, 5), TKind), Block((6, 5), TKind), Block((7, 5), TKind), Block((6, 6), TKind), Block((0, 0), TKind)),
      (10, 20),
      Seq(Block((5, 5), TKind), Block((6, 5), TKind), Block((7, 5), TKind), Block((6, 6), TKind)))