> For the complete documentation index, see [llms.txt](https://docs.bladedao.games/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.bladedao.games/zkunity-game-engine/zkunity-guide/demo-a-roguelike-card-game/guide-for-the-frontend-code.md).

# Guide for the frontend code

As we prompted previously, the entire frontend project is located in \`src/\`, and the frontend of the rogoulike card game is located in \`src/games/roguelike\`.&#x20;

\`src/games/roguelike\` has the following structure. These file names are self-explanation.

```
.
├── card.tsx
├── controller.tsx
├── death.tsx
├── images
│   ├── cheems-monster-01.jpg
│   ├── cheems-monster-02.jpg
│   ├── cheems.jpg
│   ├── d0.png
│   ├── d1.png
│   ├── d10.png
│   ├── d11.png
│   ├── d2.png
│   ├── d3.png
│   ├── d4.png
│   ├── d5.png
│   ├── d6.png
│   ├── d7.png
│   ├── d8.png
│   ├── d9.png
│   └── gameover.png
├── js
│   ├── config.js
│   ├── game.js
│   ├── gameplay.d.ts
│   ├── gameplay_bg.js
│   ├── gameplay_bg.wasm
│   ├── gameplay_bg.wasm.d.ts
│   └── package.json
├── style.scss
└── tile.ts
```

Files in js dir were copied from the backend project.&#x20;

In the \`controller.tsx\`, we can see:

```
import init, * as gameplay from "./js";

  function initGame(l2account: number) {
    (init as any)().then(() => {
      console.log("setting instance");
      console.log(gameplay);
      gameplay.new_game();
      gameplay.challenge_next_floor();
      const stateStr = gameplay.state();
      const state = JSON.parse(stateStr);
            console.log(":state:", state);
      setState(state);
      dispatch(setMD5(ImageMD5));
      dispatch(setLoaded(true));
      //drawObjects(objects);
    });
  }

...
```

We import the exported facilities of the backend into the frontend project, naming it as \`gameplay\`, and later use this handle to call functions in wasm. Just like:

```
      gameplay.new_game();
      gameplay.challenge_next_floor();
```

in the above code snippet.

Once you get it, the thing will become clear to you. Other code is just ordinary typescript/tsx code, which is easy to study.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.bladedao.games/zkunity-game-engine/zkunity-guide/demo-a-roguelike-card-game/guide-for-the-frontend-code.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
