Last active
October 16, 2021 18:17
-
-
Save JimLynchCodes/1f458c439447f1fd154f89f05d44ca1a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: GPL-3.0 | |
pragma solidity >=0.7.0 <0.9.0; | |
import "@openzeppelin/contracts/access/Ownable.sol"; | |
// Created by Jimbo - use at your own risk! 😜 | |
/** | |
* A game where there are some face down cards (boardWidth * boardHeight) | |
* | |
* Users pay 1 matic token to guess a card. | |
* | |
* There is 1 of each face card hidden in the pile. | |
* | |
* The first user to find each face card gets paid according to this schedule: | |
* | |
* ace -> acePayoutMultiplier | |
* king -> kingPayoutMultiplier | |
* queen -> queenPayoutMultiplier | |
* jack -> wins the progressive jackpot | |
* | |
* A percentage of each user's bet (jackpotRakePercentage) is added to the pot for every wrong guess. | |
* | |
* ----- | |
* | |
* (Ideas for future versions) | |
* | |
* - Over time, reveal face cards one by one to slightly change the odds in the players' favor and make things more interesting. | |
* | |
* - when all four face cards have been found, clear out contract variables and start a new game! | |
* | |
**/ | |
contract ProguessiveJackpot is Ownable { | |
// 1 matic token on polygon | |
uint cost = 1 ether; | |
uint boardWidth = 10; | |
uint boardHeight = 10; | |
// percentage of each user bet that gets added to the progressive jackpot | |
uint256 jackpotRakePercentage = 33; | |
uint acePayoutMultiplier = 25; | |
uint kingPayoutMultiplier = 15; | |
uint queenPayoutMultiplier = 10; | |
mapping(uint => string) internal currentBoard; | |
mapping(address => uint256[]) internal userGuesses; | |
uint256 totalGuesses; | |
address[] uniqueUsers; | |
uint[] revealedCards; | |
string[] revealedCardValues; | |
bool aceHasBeenFound; | |
bool kingHasBeenFound; | |
bool queenHasBeenFound; | |
bool jackHasBeenFound; | |
uint jackpotSize; | |
event AceFound(address guesser, uint256 numGuessed); | |
event KingFound(address guesser, uint256 numGuessed); | |
event QueenFound(address guesser, uint256 numGuessed); | |
event JackFound(address guesser, uint256 numGuessed); | |
event JackpotSizeIncrease(address contributor, uint amountContributed, uint256 newJackpotSize); | |
function createNewBoard() external { | |
// Set empty squares | |
for (uint256 i = 1; i <= boardWidth * boardHeight; i++) { | |
currentBoard[i] = "empty"; | |
} | |
// TODO - Get random values for face cards | |
uint256 aceNumber = 1; | |
uint256 kingNumber = 2; | |
uint256 queenNumber = 3; | |
uint256 jackNumber = 4; | |
// Set Face Cards on the current board | |
currentBoard[aceNumber] = "ace"; | |
currentBoard[kingNumber] = "king"; | |
currentBoard[queenNumber] = "queen"; | |
currentBoard[jackNumber] = "jack"; | |
} | |
function submitGuess(uint numGuessed) public payable returns (string memory) { | |
require(msg.value >= cost, "Please send the correct cost to guess: 1 matic"); | |
totalGuesses++; | |
if (userGuesses[msg.sender] == []) { | |
uniqueUsers.push(msg.sender); | |
} | |
userGuesses[msg.sender].push(numGuessed); | |
string memory valueOfCardGuessed = currentBoard[numGuessed]; | |
if (!aceHasBeenFound && keccak256(bytes(valueOfCardGuessed)) == keccak256('ace')) { | |
aceHasBeenFound = true; | |
payable(msg.sender).transfer( msg.value * (acePayoutMultiplier + 1) ); // adds 1 to give the user's bet back | |
emit AceFound(msg.sender, numGuessed); | |
return 'ace'; | |
} | |
else if (!kingHasBeenFound && keccak256(bytes(valueOfCardGuessed)) == keccak256('king')) { | |
kingHasBeenFound = true; | |
payable(msg.sender).transfer( msg.value * (kingPayoutMultiplier + 1) ); | |
emit KingFound(msg.sender, numGuessed); | |
return 'king'; | |
} | |
else if (!queenHasBeenFound && keccak256(bytes(valueOfCardGuessed)) == keccak256('queen')) { | |
queenHasBeenFound = true; | |
payable(msg.sender).transfer( msg.value * (queenPayoutMultiplier + 1) ); | |
emit QueenFound(msg.sender, numGuessed); | |
return 'queen'; | |
} | |
else if (!jackHasBeenFound && keccak256(bytes(valueOfCardGuessed)) == keccak256('jack')) { | |
jackHasBeenFound = true; | |
payable(msg.sender).transfer( jackpotSize ); | |
emit JackFound(msg.sender, numGuessed); | |
return 'jack'; | |
} | |
else if (keccak256(bytes(valueOfCardGuessed)) == keccak256('nft')) { | |
// transfer an nft to the user :) | |
} | |
jackpotSize += msg.value * jackpotRakePercentage / 100; | |
emit JackpotSizeIncrease(msg.sender, numGuessed, jackpotSize); | |
// TODO - if all cards have been found, create a new game | |
return valueOfCardGuessed; | |
} | |
function fundContract() public payable returns (string memory) { | |
return "funded!"; | |
} | |
function contractBalance() public view returns (uint256) { | |
return address(this).balance; | |
} | |
function withdraw() public payable onlyOwner { | |
(bool success, ) = payable(msg.sender).call{value: address(this).balance}(""); | |
require(success); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment