How to do it...

In this example, we notice that we can have enums, constructors, instantiating classes, and so on. Let's create a new file, name it chessboard-sample.ts, and write the following code:

enum PieceColor { White = 1, Black = 2 } enum PieceType { Pawn = 1, Bishop = 2, Knight = 3, Rook = 4, Queen = 5, King = 6 } interface Piece { type: PieceType; color: PieceColor; } class Block { isEven: boolean; row: number; col: number; piece: Piece; constructor(row: number, col: number) { this.row = row; this.col = col; this.isEven = row % 2 ? !(col % 2) : !!(col % 2); } } class Board { blocks: Array<Block> = []; placePieceOnBoard(piece: Piece, row: number, col: number) { this.blocks[(row * 8) + (col * 8)].piece = piece; } } let game = new Board(); ...

Get ASP.NET Core MVC 2.0 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.