Options
All
  • Public
  • Public/Protected
  • All
Menu

too-boring-to-play

Too Boring To Play™

Description

Too Boring To Play™ is a proof-of-concept of fully decentralized MMORPG game. It means that there is no single entity who could stop this game or change its mechanics or data. Once it is deployed, it cannot be changed in any way other than by taking predefined game actions.

This goal is achieved by implementing the essential game mechanics in contract-oriented Solidity language, and deploying it into Ethereum blockchain. Ethereum is a cryptocurrency with the support of complex scripting. Each player action is signed in client app and then sent to the blockchain as a transaction. Every Ethereum node in the network validates whether this transaction conforms to the game mechanics and rejects it if not. After accepting it, the transaction is practically irreversible.

Requirements

Recommended

  • Google Chrome v84
  • MetaMask extension v8.0.5
  • Node.js runtime v10.15.3
  • Visual Studio Code 1.47.3

Possibly

  • any modern browser supporting HTML5, WebGL and IndexedDB
  • any Ethereum provider implementing EIP-1193
  • Node.js runtime v10.15.3
  • any source-code editor

Design

The application is written in TypeScript with extensive use of React framework, which is responsible for almost all user interface (usually by using Material-UI components). For rendering of the tiled game map Phaser engine was used. Phaser objects communicate with the rest of the application via contexts, which are injected into it through the constructor of Phaser game. Contexts enable for example listening to the events and emitting them, notifying user about important matters, reading from local cache and writing into it or communicating with the Ethereum blockchain.

For storing data in the browser, Dexie library is used. It works as a wrapper for integrated IndexedDB and allows defining the data model, indexing it by user-defined indexes and querying it in a way similar to SQL.

For authentization and communication with Ethereum blockchain, injected Ethereum provider (according to the EIP-1193 standard) is used. The most convenient way is to install MetaMask extension into your browser, create an account, buy some ether (which is Ethereum native currency, needed to perform transactions against the blockchain) and play the game. For now the game is deployed on Ropsten testnet, so you can request some ether for free for example here. Another way when developing is to simulate the blockchain locally, for example with Ganache.

Design

Game mechanics are implemented as Solidity language contracts, then compiled by Truffle framework and deployed into Ethereum blockchain. There are also generated TypeScript wrapper classes from the compiled versions of contracts by using web3x-codegen tool, which allows to implement the communication with these contracts from the client application in a type-safe manner.

Project structure

  • build - After npm run build, this directory contains compiled version of web application, ready for deployment.
  • contracts - Contains Solidity contracts, which represents all server-side game mechanics.
  • dist - After truffle compile, this directory contains contracts compiled by Truffle, which are ready for deployment.
  • docs - After npm run docs, this directory contains app documentation, generated by Typedoc.
  • media - Contains images and schemas needed mostly for documentation.
  • migrations - Contains Truffle's migration files, which are useful for deploying new versions of contracts.
  • public - Contains static web content, which is copied into the build directory when the application is being built, including multimedia assets.
  • src - Contains all TypeScript source files, which are compiled by npm run build.
    • contexts - Contains contexts used mainly for communication between different parts of application and Ethereum blockchain.
      • api - Contains subcontexts for communication with Ethereum blockchain and game contracts, which are created as parts of ApiContext.
    • contracts - After npm run codegen, this directory contains TypeScript definitions of Solidity contracts from contracts.
    • hooks - Contains React Hooks, used mostly for getting current versions of blockchain data.
    • model - Contains mostly definitions of data types, which can be stored in Dexie database.
    • phaser - Contains all Phaser objects used in this project (game, scene, controls and map).
    • providers - Contains React Providers, which create contexts from src/contexts and propagates them to their children.
    • view - Contains visual React Components constituting whole user interface.
      • actions - Contains React Components, enabling user to perform game actions, but only if he should be allowed to.
      • pages - Contains React Components representing single application pages (the game itself is one of the pages).
      • popups - Contains React Components representing popups, which can be displayed over the current application page.
  • types - Contains type definitions for packages, which don't have type definitions out-of-the-box.

How to start

  • run npm install to download and install required dependencies
  • run truffle compile to compile Solidity contracts (Truffle framework not part of the project, must be installed separately)
  • for client application:
    • run npm run codegen to generate TypeScript code from contracts (configuration in contracts.json)
    • run npm start for immediate start or npm run build for compiling it into build directory
  • for blockchain logic:
    • (optional) run Ganache or other local blockchain if you want to develop locally
    • run truffle migrate to deploy contracts code into blockchain (deployment configuration in truffle-config.js)
  • for generating documentation:
    • run npm run docs to generate Typedoc documentation into docs directory

License

Copyright © 2020 Marek Polák

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

3rd party software

Licenses to 3rd party software are part of the software itself, list of used software can be found in package.json.

Media

All used media are of own production and are therefore covered by the same license.

Generated using TypeDoc