CrytogsReturn Game v0.3

Author: 0xAA

Development / Design / Coordination: @cosmoburn, @0xAA_Science, @deepe_eth, @steve0xp, TylerS, @beastadon, @OrHalldor, @Thisisnottap

The code is opensourced at:

For the introduction of the v0.1 version, see :

Game Logic: only 2 txs

Tx1:

  • Player0 transfers 5 Togs to the game contract and create a new Cryptogs game by calling initGame().

function initGame(uint256[] calldata _creatorTogs, uint256[] calldata _amounts):

  • player0 need to input Tog ids and amounts to transfer.
  • It will emit gameInit event, telling the frontend a game is created.

Tx2:

  • Player 1 join an eligible game and flip all the tokens randomly via chainlink VRF by calling joinPlay()

function joinPlay(uint256 _gameId, uint256[] calldata _joinTogs, uint256[] calldata _amounts)

  • player1 need to input the gameId he wants to join, and the tog ids and amounts he want to transfer.
  • It will emit gameJoin event and flipTog event.

Events

There are 3 events related to game play, and 1 event related to withdraw Togs.

Gameplay event:

  1. event gameInit(uint256 indexed GameId, address indexed Creator, uint256 indexed ExpirationBlock): This event is emitted when player 0 create a new game. It carries the information of the gameId (unique game identifier), address of player0, and how long the game will expire.
  2. event gameJoin(uint256 indexed GameId, address indexed Creator, address indexed Opponent, bytes32 RequestId): This event is emitted when player 1 join a existing game. It carries the information of the GameId, address of player0 and player 1, and the chainlink VRF RequestId.
  3. event FlipTogs(uint256 indexed GameId, address indexed Creator, address indexed Opponent, uint256[] FlippedTogs, uint256[] AmountPlayer0, uint256[] AmountPlayer1): This event is emited when chainlink VRF is executed in callback function and Togs are sent randomly back to player0 and player1. It carries the information of the gameId, addresses of player0 and player1, list of TogId in this game, list of amount of Togs sent to Player0 and Player1.

Withdraw Tog event:

  1. event WithdrawTogs (uint256 indexed GameId, address indexed Creator): this event is emitted when a game created by player0 is not joined by any player within expirationBlock, and player0 choose to withdraw his Togs. It carries the information of GameId, address of player0

Front-end Design

on Game creation:

  • Create button: a button for players to create a new Cryptogs game.
  • Cryptog list: a list of Togs owned by the player to select for the game.
  • Confirm button: confirm and start the tx.
  • Game table: a game table should be created once the tx is executed.

after Game creation:

  • Join button: a button that let another player join an existing game.
  • Cryptog list: a list of Togs owned by the player to select for the game.

on Game expiration:

  • Expiration game tab: a tab for players to view expired games.
  • Withdraw button: a button that let players withdraw their Togs from expired games.
Subscribe to 0xAA
Receive the latest updates directly to your inbox.
Verification
This entry has been permanently stored onchain and signed by its creator.