diff --git a/src/pages/tictactoe/Game.ts b/src/games/tictactoe/index.ts similarity index 86% rename from src/pages/tictactoe/Game.ts rename to src/games/tictactoe/index.ts index 21da913..67fe7e2 100644 --- a/src/pages/tictactoe/Game.ts +++ b/src/games/tictactoe/index.ts @@ -1,5 +1,5 @@ /* eslint-disable max-classes-per-file */ -import GameEngine, { Component2D, ComponentState, Scene, SoundManager } from 'GameEngine' +import { Component2D, ComponentState, SoundManager } from 'GameEngine' const globalState: { playerTurn: 'X' | 'O' @@ -17,7 +17,7 @@ const globalState: { ] } -class Item extends Component2D { +export class Item extends Component2D { public size = { width: .9, @@ -126,7 +126,7 @@ class Item extends Component2D { } } -class Line extends Component2D { +export class Line extends Component2D { public constructor(direction: number, index: number) { super() @@ -145,17 +145,3 @@ class Line extends Component2D { } } - -const ge = new GameEngine('#test', { - caseCount: 3, - background: 'blue' -}) -const scene = new Scene('TicTacToe') -scene.addComponent( - ...Array.from(new Array(2)).map((_, index) => new Line(0, index)), - ...Array.from(new Array(2)).map((_, index) => new Line(1, index)), - ...Array.from(new Array(9)).map((_, index) => new Item(index)), -) - -ge.start() -ge.setScene(scene) diff --git a/src/pages/tictactoe/index.tsx b/src/pages/tictactoe/index.tsx index 4883fde..f41dce4 100644 --- a/src/pages/tictactoe/index.tsx +++ b/src/pages/tictactoe/index.tsx @@ -1,9 +1,22 @@ import { Text, Link } from '@dzeio/components' +import GameEngine, { Scene } from 'GameEngine' import React from 'react' +import { Item, Line } from '../../games/tictactoe' export default class Snake extends React.PureComponent { public async componentDidMount() { - await import('./Game') + const ge = new GameEngine('#test', { + caseCount: 3, + background: 'blue' + }) + const scene = new Scene('TicTacToe') + scene.addComponent( + ...Array.from(new Array(2)).map((_, index) => new Line(0, index)), + ...Array.from(new Array(2)).map((_, index) => new Line(1, index)), + ...Array.from(new Array(9)).map((_, index) => new Item(index)), + ) + ge.start() + ge.setScene(scene) } public render = () => ( <>