# game-smart-contract

```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract GamePoints {
    address public owner;
    address public relayer; // Background wallet that pays the gas fees

    struct Player {
        uint256 totalPoints;
        mapping(uint256 => uint256) gamePoints; // Mapping of game ID to points
    }

    mapping(address => Player) public players;

    event GamePointsUpdated(address indexed player, uint256 gameId, uint256 points, uint256 totalPoints);

    constructor(address _relayer) {
        owner = msg.sender;
        relayer = _relayer;
    }

    modifier onlyRelayer() {
        require(msg.sender == relayer, "Only the relayer can perform this action");
        _;
    }

    // Relayer updates game points, gameId, and total points for the user
    function updateGamePoints(
        address _player,
        uint256 _gameId,
        uint256 _points
    ) external onlyRelayer {
        players[_player].gamePoints[_gameId] = _points;
        players[_player].totalPoints += _points;

        emit GamePointsUpdated(_player, _gameId, _points, players[_player].totalPoints);
    }

    // Function to retrieve a player's points for a specific game
    function getGamePoints(address _player, uint256 _gameId) external view returns (uint256) {
        return players[_player].gamePoints[_gameId];
    }

    // Retrieve total points for a player
    function getTotalPoints(address _player) external view returns (uint256) {
        return players[_player].totalPoints;
    }

    // Allow the owner to change the relayer address
    function setRelayer(address _newRelayer) external {
        require(msg.sender == owner, "Only the owner can change the relayer");
        relayer = _newRelayer;
    }
}


```


---

# Agent Instructions: 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:

```
GET https://0xdecharge.gitbook.io/basechain/game-smart-contract.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
