Skip to content

Commit 59b70c8

Browse files
committed
Init project
0 parents  commit 59b70c8

36 files changed

+2451
-0
lines changed

.eslintrc.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
module.exports = {
2+
extends: [
3+
'plugin:react/recommended',
4+
'plugin:prettier/recommended',
5+
'plugin:import/typescript',
6+
'plugin:@typescript-eslint/recommended',
7+
],
8+
parser: '@typescript-eslint/parser',
9+
parserOptions: {
10+
ecmaVersion: 2018,
11+
ecmaFeatures: { jsx: true },
12+
sourceType: 'module',
13+
},
14+
plugins: ['react-hooks', 'simple-import-sort'],
15+
ignorePatterns: ['dist/', '.next', 'node_modules/'],
16+
rules: {
17+
'@next/next/no-html-link-for-pages': 'off',
18+
'react/jsx-key': 'off',
19+
'simple-import-sort/sort': 'off',
20+
'simple-import-sort/imports': 'error',
21+
'simple-import-sort/exports': 'error',
22+
'@typescript-eslint/no-unused-vars': 'error',
23+
'no-unused-vars': 'off',
24+
'@typescript-eslint/explicit-module-boundary-types': 'off',
25+
'react/prop-types': [0],
26+
'react/react-in-jsx-scope': 'off',
27+
'prettier/prettier': ['error'],
28+
'no-console': ['warn'],
29+
curly: 'error',
30+
'no-restricted-imports': [
31+
'error',
32+
{
33+
paths: [
34+
{
35+
name: 'lodash',
36+
message: "Please use `import [package] from 'lodash/[package]'` instead.",
37+
},
38+
],
39+
patterns: ['!lodash/*'],
40+
},
41+
],
42+
},
43+
};

.gitignore

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
.idea
8+
.npmrc
9+
.vscode
10+
11+
# testing
12+
/coverage
13+
14+
# next.js
15+
/.next/
16+
/out/
17+
18+
# production
19+
/build
20+
21+
# misc
22+
.DS_Store
23+
*.pem
24+
25+
# debug
26+
npm-debug.log*
27+
yarn-debug.log*
28+
yarn-error.log*
29+
.pnpm-debug.log*
30+
31+
# local env files
32+
.env*.local
33+
34+
# vercel
35+
.vercel
36+
37+
# typescript
38+
*.tsbuildinfo
39+
next-env.d.ts

.prettierrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"semi": true,
3+
"trailingComma": "es5",
4+
"singleQuote": true,
5+
"printWidth": 120,
6+
"tabWidth": 2,
7+
"arrowParens": "avoid",
8+
"jsxBracketSameLine": false
9+
}

README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# axie-game-js-test-01
2+
3+
With typescript source code given, let implement write a pathfinding algorithm to help axie out of the maze.
4+
5+
![Sample map](images/01.png?raw=true "Axie Labyrinth")
6+
7+
Gameplay:
8+
9+
- Axie only can do move action
10+
- Have 2 kind object are key and door. Door only unlock if it same type with key
11+
- Objective is move axie to gray goal
12+
13+
Requirement:
14+
15+
- Only call move function
16+
- this.onMoveAxie(-1, 0);
17+
- this.onMoveAxie(1, 0);
18+
- this.onMoveAxie(0, -1);
19+
- this.onMoveAxie(0, 1);
20+
- Code can solve other map
21+
- DO NOT change the game logic code. Can create new file, and interact with axie at here:
22+
23+
```tsx
24+
//***************YOUR CODE HERE**************************/
25+
onSimulateTurn(){
26+
//Do you check and give the action to reach the goal
27+
const floorMap = this.mazeState.floors[this.mazeState.currentFloorIdx];
28+
if(this.mazeState.axie.mapX > 3){
29+
this.onMoveAxie(-1, 0);
30+
} else {
31+
this.onMoveAxie(1, 0);
32+
}
33+
}
34+
```
35+
36+
37+
## Resources
38+
39+
- Base project are at this repository :
40+
- [https://github.com/axieinfinity/game-js-test-01](https://github.com/axieinfinity/game-js-test-01)
41+
42+
## Submission
43+
44+
- Create your own git repository so we can see your work process.
45+
46+
## Deadline
47+
48+
This test is designed for 2 - 5 hours of coding. We know you might be busy with your current work, the maximum deadline is **7 days** after you received this test.

images/01.png

93.7 KB
Loading
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.AxieLabyrinth {
2+
display: flex;
3+
width: 100vw;
4+
height: 100vh;
5+
align-items: center;
6+
justify-content: center;
7+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import React, { FC } from 'react';
2+
3+
import { AxieMaze } from './axie-maze/AxieMazeNoSsr';
4+
import Classes from './AxieLabyrinth.module.scss';
5+
6+
const AxieLabyrinth: FC = () => {
7+
return (
8+
<div className={Classes.AxieLabyrinth}>
9+
<AxieMaze />
10+
</div>
11+
);
12+
};
13+
14+
export default AxieLabyrinth;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import "pixi-spine"
2+
3+
import { Mixer } from "./types"
4+
5+
export class Figure extends PIXI.spine.Spine {
6+
static readonly resourcePath =
7+
"https://axiecdn.axieinfinity.com/mixer-stuffs/v2/"
8+
mixer: Mixer
9+
10+
constructor(mixer: Mixer, atlasKeyMap: Map<string, string>, loader: PIXI.loaders.Loader) {
11+
const allTextures: { [key: string]: PIXI.Texture } = {}
12+
13+
atlasKeyMap.forEach((atlasName, atlasKey) => {
14+
allTextures[atlasName] = loader.resources[atlasKey].texture;
15+
})
16+
17+
const spineAtlas = new PIXI.spine.core.TextureAtlas()
18+
spineAtlas.addTextureHash(allTextures, false)
19+
20+
const spineAtlasLoader = new PIXI.spine.core.AtlasAttachmentLoader(
21+
spineAtlas
22+
)
23+
24+
const spineJsonParser = new PIXI.spine.core.SkeletonJson(spineAtlasLoader)
25+
const spineData = spineJsonParser.readSkeletonData(mixer.spine)
26+
super(spineData)
27+
28+
this.mixer = mixer
29+
this.scale.set(0.18)
30+
}
31+
}
32+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.container {
2+
/*display: flex;*/
3+
/*flex-direction: column;*/
4+
/*align-items: center;*/
5+
/*justify-content: center;*/
6+
/*height: 383px;*/
7+
/*position: relative;*/
8+
}
9+
10+
.canvas {
11+
overflow: hidden;
12+
border-radius: 4px;
13+
width: 960px;
14+
height: 640px;
15+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import * as PIXI from 'pixi.js';
2+
import React, { useEffect, useRef } from 'react';
3+
4+
import s from '../axie-figure/styles.module.css';
5+
import { AxieMazeGame } from './AxieMazeGame';
6+
7+
PIXI.settings.PRECISION_FRAGMENT = PIXI.PRECISION.HIGH;
8+
9+
export const AxieMaze = () => {
10+
const container = useRef<HTMLDivElement>(null);
11+
const gameRef = useRef<AxieMazeGame>(null);
12+
13+
useEffect(() => {
14+
if (!container) return;
15+
if (!container.current) return;
16+
const canvasContainer = container.current;
17+
if (canvasContainer.childElementCount > 0) {
18+
canvasContainer.lastChild?.remove();
19+
}
20+
21+
const { offsetWidth, offsetHeight } = canvasContainer;
22+
const game = new AxieMazeGame({
23+
transparent: false,
24+
resolution: window.devicePixelRatio,
25+
autoStart: true,
26+
width: offsetWidth,
27+
height: offsetHeight,
28+
backgroundColor: 0x70C8F7,
29+
// preserveDrawingBuffer: true
30+
});
31+
32+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
33+
// @ts-ignore
34+
gameRef.current = game;
35+
36+
const roninAddress = '';
37+
gameRef.current.initGame();
38+
canvasContainer.appendChild(game.view);
39+
40+
return () => {
41+
// gameRef.current.cleanUpKeyListeners();
42+
if (game) {
43+
game.destroy();
44+
}
45+
};
46+
}, []);
47+
48+
return (
49+
<div className={s.container}>
50+
<div ref={container} className={s.canvas}></div>
51+
</div>
52+
);
53+
};

0 commit comments

Comments
 (0)