Created on 7th July 2023
•
The game executes the game logic completely on top of the blockchain.
No Database, NoSQL, SessionStorage, LocalStorage, or cookies are used, and game execution is completely determined by transactions.
Whenever the game is running, no matter when you reload, log out of your wallet and log in again, you will always see the status of the game managed by the smart contract.
How to play:
First, log in to your wallet. It does not matter which wallet you use, as long as it is a web wallet that is used on the Flow, you can start the game.
Register your player name in the blockchain. This player name is the only property of your Resource. At this time, Capability to deposit FLOW to your wallet is registered in a smart contract.
Create your own deck of cards in the deck editor to create an unbeatable deck of cards! There are 78 cards available from the start.
The game begins. You must defeat your opponent within 10 turns. Use your wits to inflict more damage on your opponent than you.
If you win, you will receive 0.5 FLOW on the spot. That is why we registered Capability at the same time when you registered your player name.
In addition, for every 1,000 games, users ranked 1st to 3rd will receive a total of 35 FLOW.
You can fight as a professional gamer with the same rules as people all over the world.
In COF.ninja, all logic is written on a smart contract with over 2000 lines of code.
The logic is driven by six transactions: matching_start, game_start, put_card_on_the_field, attack, defense_action, and turn_change.
GraphQL technology is used as a tool to help with transaction processing time, and to inform you in real time what your opponents are doing.This makes for a very realistic battle. During the battle, communication takes place only through GraphQL.
In this game, I used Direct Lambda Resolver, which allows AWS AppSync to use AWS Lambda as a GraphQL server, to handle transaction execution and GraphQL notifications to users all within a single javascript file.
The most challenging thing is a dealing with the memory leaks. This game is using both FCL and GraphQL. So if connections increased, memory is soon running out. Especially, iPhone’s memory allocation to the browser app is much smaller than Mac(About 1/8 size). To solve this, I had to investigate with time consuming analyzing. (Actually it was not the memory leaks. When I stopped the blur decoration of images such as lives or cards, the crashes were solved. It seems blur decoration is memory or cpu consuming in Dart language.)
And Debugging.
Debugging the game bugs was also the hardest thing. All of game logic is on the smart contract.
So the debugging was very hard.
All the logic of the game is in the transaction. Since a transaction takes a few seconds, I used GraphQL to notify the opponents of what actions they had taken during that time.
GraphQL is a WebSocket technology specialized for notifications, and is often used in social networking applications such as Twitter. Setting up a GraphQL server on a server to use this is not an easy task for a single person.
However, AWS AppSync has commands that provide all of the GraphQL functionality with very little effort. Moreover, if you register AWS Lambda as a GraphQL server, you only need to write the necessary logic such as transaction execution in its file.
AWS AppSync was an essential platform for creating this game.
The AWS Lambda file is very simple, although all the transaction execution logic is written in one file. Just zip it up and upload it and it will provide all the backend functionality for this game. Please take a look at that file.
https://github.com/temt-ceo/CODE-of-flow/blob/master/aws_lambda/src/index.js
Tracks Applied (1)