Skip to content

hota1024/lifegame-core-quickstart-with-typescript

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🚀 lifegame-core quick start with TypeScript

https://github.com/hota1024/lifegame-core

1. Install ts-node

yarn global add ts-node
# or
npm i -g ts-node

2. Install lifegame-core

yarn add lifegame-core
# or
npm i lifegame-core

3. Create game.ts

import { LifeGame, ArrayWorld, BasicEnvironment, Cell, ConsoleWorldRenderer, CellState } from 'lifegame-core'

const game = new LifeGame(new ArrayWorld(20, 20, Cell), new BasicEnvironment()) // Create 20 x 20 world.
const renderer = new ConsoleWorldRenderer() // Create console world renderer.

// Random generate.
game.setEach(() => {
  return Math.random() > 0.5 ? CellState.Dead : CellState.Living
})

// Tick function.
const tick = () => {
  console.clear() // Clear console.
  renderer.draw(game.world) // Draw.
  game.forward() // Forward.

  setTimeout(tick, 500)
}

// Start
tick()

4. Run

$ ts-node game.ts
□■□□□□□■□□□□■■□□□□■□
□■□□□□□■□□□□□■□□□■■□
□■□□□□■□□□□□■□□■□□□□
□□■■■□□□□□□■■■■■□□□□
□■■■■□□□□■■■■□□■□□□□
■□□■□□□□□□□□□■■■□□□□
□□■□□□□□□□■□■■□■□□□□
■■□□□□□□□□■□□■■□□□□□
□□□□□□□□□□■■□■■□□□□■
□□□□□□□□□□■■□□□□□□□■
□□□□□■■■□□□□■■□□□□□■
□□□□□□□□□■□□□■■□□■■■
□□□□□■□□□■□□□■■□■□□■
□□■□□■■■□□■□■■■□■■□■
□□□■■□□□□■■■■■□□□■□■
□□□■■□□□□■■□□■□□□□□□
□□□□□□□□□■■□□■■□□□■□
□□□□□□□□■□□□□□□□□□□□
□□□□□□□□□□□□■□□□□■■□
□□□□□□□□□□■■□□□□□■□□

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published