Blockchain CryptoZombies - Lesson 2: Zombies Attack Their Victims


Attention: You are required to finish Blockchain CryptoZombies - Lesson 1 before continuing

In lesson 2, we're going to make our app more game-like: We're going to make it multi-player, and we'll also be adding a more fun way to create zombies instead of just generating them randomly.

How will we create new zombies? By having our zombies "feed" on other lifeforms!

When a zombie feeds, it infects the host with a virus. The virus then turns the host into a new zombie that joins your army. The new zombie's DNA will be calculated from the previous zombie's DNA and the host's DNA

Again, make sure to walk through the interactive lessons all by yourself first. This is just a rewind of important knowledge :)

Here are our codes at the end of lesson 2:

FD8jH4wosO

1 Solidity code sharing site. Share Solidity code snippets with friends, or check out cool code snippets from around the web.

jpy36siu_v

1 Solidity code sharing site. Share Solidity code snippets with friends, or check out cool code snippets from around the web.

So, there 's something you will need to remember:

Addresses

The Ethereum blockchain is made up of accounts, which you can think of like bank accounts. An account has a balance of Ether (the currency used on the Ethereum blockchain), and you can send and receive Ether payments to other accounts, just like your bank account can wire transfer money to other bank accounts.
Each account has an address, which you can think of like a bank account number. It's a unique identifier that points to that account, and it looks like this:
0x0cE446255506E92DF41614C46F1d6df9Cc969183
(This address belongs to the CryptoZombies team. If you're enjoying CryptoZombies, you can send us some Ether! 😉 )
------------------------------------------------------------------------------

Mappings

In Lesson 1 we looked at structs and arraysMappings are another way of storing organized data in Solidity.
Defining a mapping looks like this:
// For a financial app, storing a uint that holds the user's account balance:
mapping (address => uint) public accountBalance;
// Or could be used to store / lookup usernames based on userId
mapping (uint => string) userIdToName;
A mapping is essentially a key-value store for storing and looking up data. In the first example, the key is an address and the value is a uint, and in the second example the key is a uint and the value a string.
                                 ------------------------------------------------------------------------------

Internal and External

In addition to public and private, Solidity has two more types of visibility for functions: internal and external.
internal is the same as private, except that it's also accessible to contracts that inherit from this contract. (Hey, that sounds like what we want here!).
external is similar to public, except that these functions can ONLY be called outside the contract — they can't be called by other functions inside that contract. We'll talk about why you might want to use external vs public later.



That 's the end of lesson 2, here 's what you 've learned so far: 
  • The basics of making a multi-player game
  • Interacting with other contracts on the Ethereum network
  • Organizing larger Solidity projects into multiple contracts
See you in the next lesson :)

No comments

Hey, buddy. What's on your mind :)

Powered by Blogger.