flyweight

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 4, 2025 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package flyweight implement the Flyweight design pattern. The flyweight object Tile is used by the TileFactory to optimize the memory usage for the storing of the renderable Tile items. It encapsulates the logic to create new or return the existing Tile for the client to define and render the optimized GameMap.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run()

Types

type GameMap

type GameMap struct {
	// contains filtered or unexported fields
}

GameMap represents the map of the game that could be rendered.

func NewGameMap

func NewGameMap(width, height uint8, tiles ...*Tile) *GameMap

NewGameMap is the GameMap constructor based on the provided boundaries and the list of Tiles.

func (*GameMap) Render

func (gm *GameMap) Render()

Render implements the ability of the GameMap to be rendered.

type Renderer

type Renderer interface {
	Render()
}

Renderer is the common interface for the renderable items of the game.

type Tile

type Tile struct {
	Character rune
}

Tile is a flyweight object that represents renderable item on the map.

func (*Tile) Render

func (t *Tile) Render()

Render implements the ability of Tile to be rendered.

type TileFactory

type TileFactory struct {
	// contains filtered or unexported fields
}

TileFactory implements the flyweight factory for the Tile construction (or the reusage of the existing Tiles).

func NewTileFactory

func NewTileFactory() *TileFactory

NewTileFactory constructs TileFactory.

func (*TileFactory) GetTileType

func (tf *TileFactory) GetTileType(character rune) *Tile

GetTileType returns the existing Tile, or creates the new Tile based on the provided character symbol.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL