# Create a cookie game Blockchain app with Deku-P

**URL:** <https://forum.tezosagora.org/t/create-a-cookie-game-blockchain-app-with-deku-p/4778>\
**Category:** Research and Development\
**Created:** [October 11, 2022, 3:51pm UTC](https://forum.tezosagora.org/t/create-a-cookie-game-blockchain-app-with-deku-p/4778 "2022-10-11T15:51:04Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marigold](https://forum.tezosagora.org/user_avatar/forum.tezosagora.org/marigold/32/1009_2.png) [@Marigold](https://forum.tezosagora.org/u/Marigold)\
**Post date:** [October 11, 2022, 3:51pm UTC](https://forum.tezosagora.org/t/create-a-cookie-game-blockchain-app-with-deku-p/4778/1 "2022-10-11T15:51:04Z")

</div>

By [Gauthier Sebille](https://www.marigold.dev/team#dapps)

In our [previous blogpost](https://www.marigold.dev/post/30-min-to-create-your-first-blockchain-app-with-typescript-deku), we introduced the ground of a blockchain app with Typescript & Deku.

For the next 30 minutes you will create the state machine for your own [cookie-clicker game](https://orteil.dashnet.org/cookieclicker/)!

Each player will have a **cookieBaker** record type, which stores every counters:

- number of cookies
- number of cursors
- number of grandmas

There are three possible actions:

- **mint a cookie** =\> simply add one cookie in the current amount of cookies
- **buy a cursor** =\> if enough cookies to buy one, add one cursor to the current amount of cursors. Every second, one cursor will mint one cookie for the user
- **buy a grandma** =\> if enough cookies to buy one, add one grandma to the current amount of grandmas. Every second, one grandma will mint three cookies for the user.

‍  
The passive cookie minting from Cursors and Grandmas will be implemented in the third and last part of this tutorial, in which we will create a frontend application interacting with Deku-P HTTP APIs to perform actions on our state machine.

## Define our actions

We will use a reducer pattern to dispatch the several actions. In this tutorial, we will only implement three of them:

- Increment amount of cookies
- Increment amount of Cursors
- Increment amount of Grandmas

Let’s create an **enum** holding all the possible actions:

```auto
export enum actions {
    cookie = "cookie",
    cursor = "cursor",
    grandma = "grandma"
}

```

## Define our state

The **state** , which will be saved using the **set(“myState”, nextValue);** (operation explained in the following section), will look like:

```auto
export type cookieBaker = {
    cookies: number,
    cursors: number,
    grandmas: number
}

```

## Create a basic **saveState** function

The **saveState** function is just a syntactic sugar to avoid duplicated code lines, because we will save the state after each action.

Moreover, in this function, we will add some **console.log** to ensure everything is going well:

```auto
const saveState = (source: transaction, cookieBaker: cookieBaker) => {
    const cookieBakerJSON = JSON.stringify(cookieBaker);
    set(source, cookieBakerJSON);
    console.log("Successfully saved cookieBaker: " + cookieBakerJSON);
}

```

If you want to learn more about this tutorial, please read our blogpost on Marigold website 👉 [Create a cookie game Blockchain app with Deku-P](https://www.marigold.dev/post/create-a-cookie-game-blockchain-app-with-dekup)  
‍
