1.7.11 ā¢ Published 1 month ago
soku-game-snake v1.7.11
soku-game-snake
š The example of using @soku-games/core
to implement game Double Snake
.
Usage(Quick Start)
You should install dependency @soku-games/core
at first.
And then
// assume that using Solid-JS in `src/App.tsx`
// all the api to use
import {
NewController,
NewGame,
NewGenerator,
NewRenderer,
NewValidator,
} from '@soku-games/core';
// must do
import 'soku-game-snake';
function SnakeDemo(): JSX.Element {
const [view, setView] = createSignal('');
const game = NewGame('snake');
const renderer = NewRenderer('snake');
const controller = NewController('snake');
const validator = NewValidator('snake');
const generator = NewGenerator('snake');
let control: (strStep: string) => void;
onMount(() => {
renderer.bindGame(game, {
print: setView,
});
control = controller.bindRenderer(renderer) as unknown as (
strStep: string,
) => void;
validator.bindGame(game);
game.prepare(generator.generate(13, 14, 20)).start();
});
const abstractView = () => view();
const objectiveView = () =>
abstractView()
.replace(/0/g, 'šæļø')
.replace(/1/g, 'š§±ļø')
.replace(/A/g, 'š±')
.replace(/B/g, 'š¶');
let inputRef: HTMLInputElement;
function handleSubmit(e: KeyboardEvent) {
if (e.key === 'Enter') {
const str = inputRef.value;
control(str);
inputRef.value = '';
}
}
return (
<>
<div style={{ display: 'flex', gap: '20px', 'font-size': '25px' }}>
<pre>{objectiveView()}</pre>
<pre>{abstractView()}</pre>
</div>
<input
style={{ 'font-size': '25px', 'padding-inline': '10px' }}
ref={(el) => (inputRef = el)}
type="text"
onKeyDown={handleSubmit}
/>
</>
);
}
Now look at website, try to play.
1.7.11
1 month ago
1.7.10
6 months ago
1.7.9
6 months ago
1.2.0
6 months ago
1.7.3
6 months ago
1.7.2
6 months ago
1.7.1
6 months ago
1.5.3
6 months ago
1.7.0
6 months ago
1.6.1
6 months ago
1.5.2
6 months ago
1.4.3
6 months ago
1.6.0
6 months ago
1.4.2
6 months ago
1.5.0
6 months ago
1.4.1
6 months ago
1.2.3
6 months ago
1.4.0
6 months ago
1.3.1
6 months ago
1.2.2
6 months ago
1.3.0
6 months ago
1.2.1
6 months ago
1.7.8
6 months ago
1.7.7
6 months ago
1.7.6
6 months ago
1.7.5
6 months ago
1.7.4
6 months ago
0.2.2
8 months ago
0.2.1
9 months ago
0.2.0
9 months ago
0.1.3
9 months ago
0.1.2
9 months ago
0.1.1
10 months ago
0.0.3
10 months ago
0.0.2
10 months ago
0.0.1
10 months ago