https://github.com/fibo/tris3d-canvas
is a placeholder to play tic tac toe in 3d
https://github.com/fibo/tris3d-canvas
Last synced: over 1 year ago
JSON representation
is a placeholder to play tic tac toe in 3d
- Host: GitHub
- URL: https://github.com/fibo/tris3d-canvas
- Owner: fibo
- License: mit
- Created: 2016-03-04T10:17:54.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2020-03-16T20:28:35.000Z (over 6 years ago)
- Last Synced: 2025-03-28T17:11:13.155Z (over 1 year ago)
- Language: JavaScript
- Homepage: https://fibo.github.io/tris3d-canvas
- Size: 1.83 MB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# tris3d-canvas
> is a canvas to play tic tac toe in 3d
[Installation](#installation) |
[API](#api) |
[License](#license)
[](http://badge.fury.io/js/tris3d-canvas)
[](https://standardjs.com)
## Installation
With [npm] do
```bash
npm install three tris3d-canvas
```
Note that [three.js](https://threejs.org/) is required as a peer dependency.
## API
See [online example][online_example] or do the following to run [example.js][example_js]
```bash
npm install
npm start
```
### `const tris3dCanvas = new Tris3dCanvas(canvasId, opts)`
> Constructor to create an instance of Tris3dCanvas.
Create a canvas with attribute `id`, inside a div container with `display: block` style
```html
```
Then create a Tris3dCanvas object
```javascript
const tris3dCanvas = new Tris3dCanvas('demo')
```
Optional parameters are accepted after `canvasId`, constructor signature
is the following:
* **@param** `{String}` **id** of canvas element
* **@param** `{Object}` **[opt]** optional parameters
* **@param** `{Array}` **[opt.playerColors]** are three colors, like 0xff0000
* **@param** `{Array}` **[opt.backgroundColor]** defaults to 0xffffff
### `tris3dCanvas.localPlayerIndex`
Can be 0, 1, 2. Defaults to 0, which means the local player moves first.
### `tris3dCanvas.on('localPlayerTurnEnds', () => {})`
> Listen to *localPlayerTurnEnds* event.
### `tris3dCanvas.on('localPlayerTurnStarts', () => {})`
> Listen to *localPlayerTurnStarts* event.
### `tris3dCanvas.on('nextPlayer', (playerIndex) => {})`
> Listen to *nextPlayer* event.
### `tris3dCanvas.on('nobodyWins', () => {})`
> Listen to *nobodyWins* event.
### `tris3dCanvas.on('setChoice', (cubeIndex) => {})`
> Listen to *setChoice* event.
### `tris3dCanvas.on('tris3d!', (winnerPlayerIndex, winningCombinations) => {})`
> Listen to *tris3d!* event.
### `tris3dCanvas.render()`
> Start rendering the 3d scene.
### `tris3dCanvas.setChoice(playerIndex, cubeIndex)`
> Set player choice.
### `tris3dCanvas.resetPlayground()`
> Reset playground without start playing a new match.
### `tris3dCanvas.startNewMatch()`
> Start a brand new match
## License
[MIT](http://g14n.info/mit-license)
[example_js]: https://github.com/fibo/tris3d-canvas/blob/master/example.js
[npm]: https://npmjs.org/
[online_example]: http://g14n.info/tris3d-canvas/example