You don't have access to this class

Keep learning! Join and start boosting your career

Aprovecha el precio especial y haz tu profesi贸n a prueba de IA

Antes: $249

Currency
$209
Suscr铆bete

Termina en:

0 D铆as
10 Hrs
54 Min
5 Seg

Desarrollando un juego simple

4/15
Resources

How to design a project using smart contracts?

When you embark on a project based on blockchain technology, planning is key. In this class we will address how to properly choose projects that involve smart contracts. It is often easy to get lost in the sea of innovative ideas, but it is crucial to discern which ones really benefit from being developed in a decentralized environment.

How do we evaluate whether an idea is suitable for a smart contract?

  • Simplicity of the solution: If an idea requires edifice development with multiple lines of code and seems like it will become convoluted in its complexity, it is probably not the best choice for a smart contract. These should be simple, straightforward and clear.

  • Storage costs: Any data stored in a smart contract has a cost associated with it. Therefore, storage should be limited to critical data, avoiding data that inflates costs. For example, irrelevant details such as the user's favorite ice cream flavor are not needed in the blockchain.

  • Sensitive information: It is not only important to safeguard users' privacy, but also to avoid exposing critical data for the project itself. If privacy is a deciding factor, a smart contract might not be the best choice as ultimately the information could be accessible through commands and scripts.

What is the proposed project?

The project consists of developing a tic-tac-toe style game using smart contracts. This exercise not only allows to exercise development, but also retains the opportunity to think about how blockchain can be leveraged in games.

Key points of the project:

  • Simultaneous multi-game: Contracts should allow multiple games at once. Each game will be associated with specific addresses representing players. Only these addresses will be able to make moves in that game.

  • Structure and collections: We will use structs and dynamic arrays to manage the games. Each game will be represented by a struct that will store the players, the winner, and the moves.

How do we implement the project in code?

The following is a basic outline of the code that makes up the contract:

// SPDX-License-Identifier: MITpragma solidity ^0.8.0;
contract TicTacToe { struct Partida { address player1; address player2; address winner; uint8[4][4] plays; // Array of plays }    
 Partida[] public partidas; // Dynamic array of games    
 function createGame(address _player1, address _player2) public returns (uint) { // Logic to create a new game }    
 function play(uint _idGame, uint8 _x, uint8 _y) public { // Logic to make a move in the game }    
 constructor() { // Constructor in case it is needed in the future } }}

Important considerations:

  • Game Structure: The structure encompasses the address of the players, the eventual winner, and an array representing the game board.

  • Key functions: There will be two main functions: createParty to start a game and play to make moves.

  • Essential validations: Within play, we must perform checks such as verifying that the player is authorized to move or that the square is not already occupied.

What is expected of the student?

The goal is that you not only understand how the skeleton of the contract is laid out, but also that you dare to implement and complete the missing parts of the code on your own. A challenge has been set to stimulate autonomous learning and problem solving. You are therefore encouraged to try to finalize the code based on this basic structure.

This guide gives you the foundation to dive into the development of smart contracts applied in practical projects such as games. Go ahead and explore how you can expand your skills in blockchain technology!

Contributions 1

Questions 0

Sort by:

Want to see more contributions, questions and answers from the community?

Como que Tic Tac Toe? toda mi vida lo he conocido como "Michi", "Tres en l铆nea" o "Tres en raya", estaba perdido poque no entendia de que trataba el juego pense que era piedra papel o tijera