Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
March 27, 2022 12:44 pm GMT

Smart Contract that simulate Animal Crossing (nintendo game)

Smart Contracts Automatic Bell Dispenser

Bank System simulation in Animal Crossing Nintendo Game




tests

About The Project

This project is composed by smart contracts that simulate Animal Crossing banking system, Animal Crossing is a social simulation video game series developed and published by Nintendo, where the user can buy and sell things having a bank account.We created smart contracts for 2 tokens inside the game, Bell & Miles (ERC20 standards), and 1 contract to simulate all game's functionalities. We also adding a script for deploy them and tests (obviously).

link Repository, leave a follow please.

Built With

Getting Started with Hardhat

npx hardhat accountsnpx hardhat compilenpx hardhat cleannpx hardhat testnpx hardhat nodenode scripts/TomNookATM.jsnpx hardhat help

Functionalities

Bells & Miles (ERC20 standard)

Nook Miles are a type of currency in New Horizons that work similar to airline mileage programs in real life. Players earn Nook Miles from travel and participating in activities around the Deserted Island. Additionally, players can also get Nook Miles from completing tasks and stamp cards in the Nook Miles app section of the NookPhone. Since 500 Nook Miles can be redeemed for a 3,000 Bells voucher in the Nook Stop, 1 Nook Miles is worth 6 Bells.

Bells are the main currency used in the Animal Crossing series. Although most frequently used to purchase items from stores and pay off the player's mortgage, Bells may also be used in several other respects, including trading with villagers and other services.




import "@openzeppelin/contracts/utils/Context.sol";import "@openzeppelin/contracts/token/ERC20/ERC20.sol";//Bell.solcontract Bell is ERC20 {    constructor() ERC20("Bell", "BLL") {        _mint(msg.sender, 1000000 * (10**uint256(decimals())));    }}//Miles.solcontract Miles is ERC20 {    constructor() ERC20("Miles", "MLS") {        _mint(msg.sender, 100 * (10**uint256(decimals())));    }}

Pay Debts

Mortgages are the number of Bells that the player owes Tom Nook for constructing and expanding their house. There are several mortgages to pay off.



    address payable TomNook;    mapping(address => uint256) userDebt;    function payDebts(uint256 _amount) external accountExists {        if (userDebt[msg.sender] == 0) {            console.log(                "extinguished corredebts! Congratulations ! you have finished paying your home loan !  "            );        } else {            //tracking            claimInterests();            accounts[msg.sender].balances[address(bell)] -= _amount;            userDebt[msg.sender] -= _amount;            bell.transfer(TomNook, _amount);        }    }

Bell voucher Dex

The Bell voucher is a new redeemable item in New Horizons. They can be redeemed from the Nook Stop in the Resident Services Tent or Building. They cost 500 Nook Miles, and are sold for 3,000 Bells. They have no uses other than as a way to convert Nook Miles into Bells.




    function BellVaucherDex(uint256 _amount) external {        accounts[msg.sender].balances[address(miles)] -= _amount;         bell.transferFrom(TomNook, msg.sender, _amount * 6);    }

Automatic Bell Dispenser

interest is deposited into the player's savings on the first of each month 0.5% (0.05% in New Horizons). The ABD was first added in City Folk, and has appeared in all main series games since then.





    function claimInterests() public {        uint256 rate = ((block.timestamp -            accounts[msg.sender].timestampForInterests) * 100) / 1 days;        uint256 interests = (accounts[msg.sender].balances[address(bell)] *            rate) / 600_000;           bell.transferFrom(TomNook, msg.sender, interests);    }

Other Functionalities Added

  • Create Account
  • Close Account
  • Deposit
  • Withdraw
  • Get Balance for each token
  • accountExists, onlyValidTokens, OnlyMilesForVaucher Modifiers

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement".
Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Original Link: https://dev.to/matteol/smart-contract-that-simulate-animal-crossing-nintendo-game-3bh3

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To