# Play To Earn Contract

## Overview

The `P2EGame` (Play-to-Earn Game) contract is designed for managing a gaming ecosystem where players can stake ERC20 tokens in a gaming escrow.&#x20;

The contract handles the staking of tokens, tracks game states, and manages token payouts based on game outcomes.

## Methods

## <mark style="color:blue;">`gameState`</mark>

Retrieves the current state of game funds in escrow.

### Parameters

| **Parameter** | **Type**  | **Description**         |
| ------------- | --------- | ----------------------- |
| `_gameId`     | `uint256` | Identifier of the game. |
| `_player`     | `address` | Address of the player.  |

### Returns

| **Return** | **Type**                   | **Description**                             |
| ---------- | -------------------------- | ------------------------------------------- |
| Tuple      | `(uint256, bool, address)` | Balance, lock status, and treasury address. |

## <mark style="color:blue;">`createGame`</mark>

### Parameters

| **Parameter** | **Type**  | **Description**                |
| ------------- | --------- | ------------------------------ |
| `_player`     | `address` | Address of the player.         |
| `_treasury`   | `address` | Treasury address for the game. |
| `_p`          | `uint256` | Player's staked amount.        |
| `_t`          | `uint256` | Treasury's staked amount.      |

### Returns

| **Return** | **Type** | **Description**                                   |
| ---------- | -------- | ------------------------------------------------- |
| `success`  | `bool`   | Returns true if the game is successfully created. |

## <mark style="color:blue;">`playerWon`</mark>

### Parameters

| **Parameter** | **Type**  | **Description**                |
| ------------- | --------- | ------------------------------ |
| `_gameId`     | `uint256` | Identifier of the game.        |
| `_player`     | `address` | Address of the winning player. |

### Returns

| **Return** | **Type** | **Description**                                   |
| ---------- | -------- | ------------------------------------------------- |
| `success`  | `bool`   | Returns true if tokens are unlocked successfully. |

## <mark style="color:blue;">`playerLost`</mark>

### Parameters

| **Parameter** | **Type**  | **Description**               |
| ------------- | --------- | ----------------------------- |
| `_gameId`     | `uint256` | Identifier of the game.       |
| `_player`     | `address` | Address of the losing player. |

### Returns

| **Return** | **Type** | **Description**                             |
| ---------- | -------- | ------------------------------------------- |
| `success`  | `bool`   | Returns true if funds are sent to treasury. |

## <mark style="color:blue;">`Withdraw`</mark>

### Parameters

| **Parameter** | **Type**  | **Description**         |
| ------------- | --------- | ----------------------- |
| `_gameId`     | `uint256` | Identifier of the game. |

### Returns

| **Return** | **Type** | **Description**                           |
| ---------- | -------- | ----------------------------------------- |
| `success`  | `bool`   | Returns true if withdrawal is successful. |
