[V0.0.6] - SteemCasino - Mines are now here!

in #utopian-io7 years ago (edited)

black-horizontal.png

Hi, and welcome to a new update of SteemCasino!

Please be sure to check out our Official Discord.

You can see our github here.

And the pull request here.

New Features

  • We have changed our hashing algorithm from Whirlpool to SHA-256.

  • We have added a new game, Mines!

How did we implement Mines?

We have a .js script that connects the browser with a .php script that calculates everything.

The javascripts checks if you click a button through the onClick attribute from html.

If you press the start new game button, you're gonna activate the newGame function from the javascript that first will show us a message that it's working.

$("#messages-box").css('background-color', 'yellow');
$("#messages").text("Working...");
$("#closeMessage").text("X");

And then it will request a .json from /src/mines.php, the script that calculates everything.

$.getJSON( "../src/mines.php?action=newGame&game=" + game+"&bet=" + bet, function( data ) {
                ...
});

Then the php script will check if everything is good, if the action is valid, if your session is valid, if the game id is 0, meaning no game is running and if the bet is valid, >=0.001 SBD.

if(!isset($_GET['action']) || $_GET['action'] == "") {
    $arr = array('status' => 'error', 'error' => 500, 'message' => 'Action is not set.');
    echo json_encode($arr);
} else if ($_GET['action'] == "newGame") {
    if(!isset($_GET['game'])) {
        $arr = array('status' => 'error', 'error' => 501, 'message' => 'Game is not set.');
        echo json_encode($arr);
    } else if (!IsLoggedOnUser()) {
        $arr = array('status' => 'error', 'error' => 502, 'message' => 'Session is invalid. Please reload.');
        echo json_encode($arr);
    } else if($_GET['game'] != 0) {
        $arr = array('status' => 'error', 'error' => 503, 'message' => 'A game is already running. Please cash out to start another game.');
        echo json_encode($arr);
    } else if(!isset($_GET['bet'])) {
        $arr = array('status' => 'error', 'error' => 504, 'message' => 'Bet is not set.');
        echo json_encode($arr);
    } else if($_GET['bet'] < 0.001) {
        $arr = array('status' => 'error', 'error' => 505, 'message' => 'Bet is too small.');
        echo json_encode($arr);
    }
}

If everything is alright it will generate a secret using this function.

function generateSecretMines($mode = 1, $length = 92) {
    $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $charactersLength = strlen($characters);
    
    if($mode == 1) {
        $mine1 = mt_rand(1, 25);
        $mine2 = mt_rand(1, 25);
        $mine3 = mt_rand(1, 25);
        
        if($mine1 == $mine2 || $mine2 == $mine3 || $mine1 == $mine3) {
            return generateSecretMines($mode, $length);
        }       
        
        $randomString = $mine1."-".$mine2."-".$mine3."-";
    }
    
    for ($i = 0; $i < $length; $i++) {
        $randomString .= $characters[rand(0, $charactersLength - 1)];
    }

    return $randomString;
}

A secret looks something like: 1-19-20-random_92_letters. The first three numbers are the blocks where are placed mines, if you click one of that you will automatically lose.

If everything is alright, it will hash the secret and send back to the javascript the game id and the hash.

$arr = array('status' => 'success', 'message' => 'Game has been successfully created.', 'game' => $game, 'hash' => $hash, 'reward' => $_GET['bet']);
echo json_encode($arr);

The javascript will create a table and a message informing you that the game has been created. The design will be changed.

The table consists of 25 blocks, and under 3 are mines.

image.png

If you click one of them and it's not a bomb, you will be informed how much is your reward now and the block turns green. Every correct block increases the reward by 13%.

image.png

If you click on a bomb, you will lose all the reward and all the bombs are displayed. The secret of that game is also revealed. You can check our fairness by rehashing the secret using an online SHA-256 hasher.

image.png



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Thank you for the contribution. It has been approved.

You can contact us on Discord.
[utopian-moderator]

Hey @andreistalker I am @utopian-io. I have just upvoted you!

Achievements

  • Seems like you contribute quite often. AMAZING!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x

Coin Marketplace

STEEM 0.22
TRX 0.27
JST 0.042
BTC 104536.45
ETH 3874.03
SBD 3.32