Skip to content

Sticks & Squares game implemented using Ethereum blockchain.

License

Notifications You must be signed in to change notification settings

m3nsr3a/LittleBritten

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LittleBritten

Small game that uses Ethereum ledger to store states and ensure that players don't cheat.

Table Of Contents

  1. TL;DR
  2. Deadlines
  3. Implementation Details
  4. How-to Use
  5. ToDo Log
  • Popular pencil game from good oll' times - Sticks & Squares.
  • All logic is held by smart contracts, frontend only handles the drawing part.
  • MetaMask for user-friendliness is integrated.
Date Maximum possible mark
2359 5-th March 10.0

Lets look at the source code structure under src folder:

  • contracts - Solidity code.
  • static - Frontend code and resources lie here.
  • migrations - Contract deployment code.
  • SubDockerfile - Launches the cite docker-machine.
  • run.sh - Script that launches the server.
  • static_server.py - Simple server, that serves static.
  • truffle.js - Configuration file, for deploying using truffle framework.
  • conf.py - Configuration file for Gunicorn.
  • requirements.txt - Dependencies, for launching our python code.
  • vendor - under this folder, the external libraries and files lie. I use:
    • I use bootstrap package for some styles and minor view modifications.
    • jquery_1.12.4.js, the standard lib for working with DOM elements.
    • web3.js for connection to Ethereum network.
    • I make use of glitch.js, tiny lib, to make nice logos.
    • And finally, truffle-contract.js custom library from truffle to wrap Solidity contracts in JS.

The system works as follows:

  • Running docker-compose command will launch two docker-environments:
    • ledger - Here the ganache Ethereum test-net will be launched.
    • cite - The simple Flask server will launch, serving our web-game.
  • When the cite image, will be build, it will:
    • Pull some dependencies.
    • Compile contracts.
    • Deploy contracts to test-net, that is in separate container.
    • Launch python server on Flask, that will serve our frontend logic.

Lastly, let's add a little bit, on how it works:

  1. Contracts hold the logic.
    • Migrations contract is needed to correctly deploy code -> nothing interesting here.
    • Math - Small math library that I'm using.
    • Rules - The logic of the game.
    • TwoPlayerGame - Core logic for game. Manipulates low-level game functions.
    • The StickGame contract represents the game itself. It extend the TwoPlayerGame contract, and provides higher level function for game handling.
  2. Fronted is primitive.
    • No logic, just updates the screen.
    • Based on callbacks(solidity events), that receives from the ledger.
  3. Everything is served under Docker.
    • One image, creates the ledger using ganache-cli.
    • Other one, which is based on the first image, serves the web-page(No logic there, just for convenience).
    • Also it's duty to compile, and upload Smart-contracts.

In order to start everything, a little bit of preparations are required:

  1. Since I tried to make the game, as most user-friendly as possible, we are using MetaMask, to communicate with game. Or more precisely, we need MetaMask's web3.js instance, to easily confirm our transactions, that we send to our test net.

    So in order, for everything to work correctly, follow this steps:

    • Download Google Chrome browser.
    • Install the MetaMask browser extension.
    • The icon will show in the top-right corner of the browser(where other extensions are).
    • Click on it, and create account.
    • Click the menu that shows "Main Network" and select Localhost 8545.
  2. Install the docker thing.

    • Do curl https://get.docker.com/ | sh in the terminal, if you are under some Linux distro.(In other case, look here)
    • Install pip3 for python3 and run sudo pip3 install docker-compose.
  3. Then, at long last, let's run dis game.

    • Assuming you have git run in terminal git clone https://github.com/NumenZ/LittleBritten, or, well, just somehow get the code part of current project.
    • Now, we need to get a small information from our MetaMask account, in order for us, to launch test-net correctly:
      • Press on ellipsis(3 dots), under the foxes head. Menu1
      • Find the export Address and Private key to some file.Menu2
      • Save this parameters as environmental variables -> in your terminal(replace caps):
        • export TEST_ADDRESS="ADDRESS".
        • export TEST_PRIVATE_KEY="0xPRIVATE_KEY".
    • Finally, run docker-compose up --build.
  4. As a last step, open your Google Chrome browser at 'http://127.0.0.1:8080', and enjoy the game.

It must look something like this. Menu1

In case, you don't know the rules, check them here.

  • 2 points - Write simple working example, with simple web-server and fronted.

  • 2 points - Implement the game, with nice GUIs and Smart-Contracts backing up the logic.

  • 3 points - Connect front-end with the back-end logic.

  • 2 points - Make all configuration as simple as possible, using Docker, MetaMask, file-serving, etc.

  • 1 point - Write this ReadMe.md with all explanations.

About

Sticks & Squares game implemented using Ethereum blockchain.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published