// GOROK Smart Contract - Web3 Gaming Platform pragma solidity ^0.8.19; import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; import "@openzeppelin/contracts/security/ReentrancyGuard.sol"; contract GorokToken is ERC20, Ownable { uint256 public constant MAX_SUPPLY = 1000000000 * 10**18; // 1B tokens uint256 public constant INITIAL_SUPPLY = 500000000 * 10**18; // 500M initial mapping(address => bool) public gameContracts; mapping(address => uint256) public playerRewards; event GameReward(address indexed player, uint256 amount); event GameContractAdded(address indexed gameContract); constructor() ERC20("GOROK", "GRK") { _mint(msg.sender, INITIAL_SUPPLY); } function addGameContract(address _gameContract) external onlyOwner { gameContracts[_gameContract] = true; emit GameContractAdded(_gameContract); } function rewardPlayer(address _player, uint256 _amount) external { require(gameContracts[msg.sender], "Only game contracts can reward"); require(totalSupply() + _amount <= MAX_SUPPLY, "Exceeds max supply"); _mint(_player, _amount); playerRewards[_player] += _amount; emit GameReward(_player, _amount); } } contract GorokNFT is ERC721, Ownable, ReentrancyGuard { uint256 private _tokenIdCounter; uint256 public constant MAX_NFTS = 10000; struct GameAsset { string name; uint256 rarity; // 1-5 (common to legendary) uint256 power; uint256 gameId; bool isActive; } mapping(uint256 => GameAsset) public gameAssets; mapping(address => uint256[]) public playerAssets; event AssetMinted(address indexed player, uint256 tokenId, string name); event AssetUpgraded(uint256 tokenId, uint256 newPower); constructor() ERC721("GOROK Game Assets", "GGA") {} function mintAsset( address _to, string memory _name, uint256 _rarity, uint256 _power, uint256 _gameId ) external onlyOwner returns (uint256) { require(_tokenIdCounter < MAX_NFTS, "Max NFTs minted"); uint256 tokenId = _tokenIdCounter++; _safeMint(_to, tokenId); gameAssets[tokenId] = GameAsset({ name: _name, rarity: _rarity, power: _power, gameId: _gameId, isActive: true }); playerAssets[_to].push(tokenId); emit AssetMinted(_to, tokenId, _name); return tokenId; } function upgradeAsset(uint256 _tokenId, uint256 _powerIncrease) external { require(ownerOf(_tokenId) == msg.sender, "Not asset owner"); require(gameAssets[_tokenId].isActive, "Asset not active"); gameAssets[_tokenId].power += _powerIncrease; emit AssetUpgraded(_tokenId, gameAssets[_tokenId].power); } function getPlayerAssets(address _player) external view returns (uint256[] memory) { return playerAssets[_player]; } } contract GorokGameEngine is Ownable, ReentrancyGuard { GorokToken public gorokToken; GorokNFT public gorokNFT; struct Game { string name; uint256 entryFee; uint256 rewardPool; uint256 maxPlayers; uint256 currentPlayers; bool isActive; } mapping(uint256 => Game) public games; mapping(uint256 => mapping(address => bool)) public gameParticipants; mapping(address => uint256) public playerScores; uint256 public gameCounter; event GameCreated(uint256 gameId, string name, uint256 entryFee); event PlayerJoined(uint256 gameId, address player); event GameCompleted(uint256 gameId, address winner, uint256 reward); constructor(address _tokenAddress, address _nftAddress) { gorokToken = GorokToken(_tokenAddress); gorokNFT = GorokNFT(_nftAddress); } function createGame( string memory _name, uint256 _entryFee, uint256 _maxPlayers ) external onlyOwner returns (uint256) { uint256 gameId = gameCounter++; games[gameId] = Game({ name: _name, entryFee: _entryFee, rewardPool: 0, maxPlayers: _maxPlayers, currentPlayers: 0, isActive: true }); emit GameCreated(gameId, _name, _entryFee); return gameId; } function joinGame(uint256 _gameId) external payable nonReentrant { Game storage game = games[_gameId]; require(game.isActive, "Game not active"); require(game.currentPlayers < game.maxPlayers, "Game full"); require(!gameParticipants[_gameId][msg.sender], "Already joined"); require(msg.value >= game.entryFee, "Insufficient entry fee"); gameParticipants[_gameId][msg.sender] = true; game.currentPlayers++; game.rewardPool += msg.value; emit PlayerJoined(_gameId, msg.sender); } function completeGame(uint256 _gameId, address _winner) external onlyOwner { Game storage game = games[_gameId]; require(game.isActive, "Game not active"); require(gameParticipants[_gameId][_winner], "Winner not participant"); uint256 reward = game.rewardPool; game.isActive = false; // Transfer reward to winner payable(_winner).transfer(reward); // Mint reward tokens gorokToken.rewardPlayer(_winner, reward * 10); // 10x token reward emit GameCompleted(_gameId, _winner, reward); } }
Revolutionizing the gaming industry through blockchain technology, NFTs, and decentralized governance.
Experience the future of Web3 gaming with GOROK