feat(01-02): implement Tile model class

- Implements Tile interface from types/index.ts
- Constructor with id, type, position
- emoji getter returns CONFIG.emojis[type]
- isAdjacent() checks orthogonal adjacency
- cleared property defaults to false

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-10 23:49:16 +07:00
co-authored by Claude Opus 4.6
parent 080b9f22a0
commit efcac7ad4c
+47
View File
@@ -0,0 +1,47 @@
// src/models/Tile.ts - Tile data model
/**
* Tile represents a single tile in the game grid.
* It contains position, type, and state information.
*/
import { TilePosition, Tile as TileInterface } from '../types';
import { CONFIG } from '../config';
export class Tile implements TileInterface {
/**
* Whether this tile has been cleared from the board
*/
public cleared: boolean = false;
/**
* Creates a new Tile
* @param id - Unique identifier for this tile
* @param type - Tile type (0-15 for emoji index)
* @param position - Grid position (row, col)
*/
constructor(
public readonly id: string,
public readonly type: number,
public readonly position: TilePosition
) {}
/**
* Gets the emoji for this tile's type
*/
get emoji(): string {
return CONFIG.emojis[this.type];
}
/**
* Checks if this tile is orthogonally adjacent to another tile
* @param other - The other tile to check
* @returns true if tiles are adjacent (not diagonal)
*/
isAdjacent(other: Tile): boolean {
const rowDiff = Math.abs(this.position.row - other.position.row);
const colDiff = Math.abs(this.position.col - other.position.col);
// Orthogonally adjacent means exactly one row OR one column difference, but not both
return (rowDiff === 1 && colDiff === 0) || (rowDiff === 0 && colDiff === 1);
}
}